@uyghurcommunity/spell 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/LICENSE +21 -0
- package/README.md +87 -2
- package/package.json +41 -4
- package/src/confusions.js +234 -0
- package/src/data/roots.js +124 -0
- package/src/distance.js +147 -0
- package/src/index.d.ts +181 -0
- package/src/index.js +67 -0
- package/src/lexicon.js +406 -0
- package/src/lexiconLoader.js +78 -0
- package/src/morphology.js +386 -0
- package/src/normalize.js +204 -0
- package/src/suggest.js +278 -0
- package/src/tokenize.js +127 -0
- package/src/userDictionary.js +219 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
First release, extracted from the correction engine in [uyghur-ocr](https://github.com/WarisWorks/uyghur-ocr) (`src/correction/`).
|
|
6
|
+
|
|
7
|
+
- `createSpellChecker()`: independent checkers with `check`, `suggest`, `isKnown` and `learn`.
|
|
8
|
+
- Morphology-aware recognition: case, possessive, plural and derivational suffixes, vowel harmony, verb endings and particles.
|
|
9
|
+
- Ranked suggestions using a Uyghur letter-confusion model; offsets always refer to the original text, and nothing is rewritten automatically.
|
|
10
|
+
- `normalize()`: lossless encoding fixes (presentation forms, ک → ك, tatweel, zero-width characters).
|
|
11
|
+
- `UserDictionary`: personal words, in memory by default, with optional storage such as `localStorage`. Unlike the app version, nothing runs on import.
|
|
12
|
+
- A seed list of a few hundred roots built in; the 60,000-word Wikipedia list is published separately as `@uyghurcommunity/spell-lexicon-wiki` (CC BY-SA 4.0).
|
|
13
|
+
- TypeScript declarations.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Waris Ruzi and UyghurCommunity contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ئۇيغۇرچە ئىملا · Uyghur Spell
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
ئۇيغۇرچە ئىملا تەكشۈرۈش ۋە تۈزىتىش قورالى.
|
|
4
|
+
|
|
5
|
+
Spell-checking and correction for Uyghur in Arabic script. It recognises inflected words through Uyghur morphology, ranks corrections with a model of letters that are easily confused, and never rewrites your text on its own. It runs in the browser and in Node.js, with no runtime dependencies.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @uyghurcommunity/spell
|
|
9
|
+
# optional: the 60,000-word list (CC BY-SA 4.0)
|
|
10
|
+
npm install @uyghurcommunity/spell-lexicon-wiki
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
import { createSpellChecker } from '@uyghurcommunity/spell';
|
|
17
|
+
import { loadWikiWordList } from '@uyghurcommunity/spell-lexicon-wiki';
|
|
18
|
+
|
|
19
|
+
const { words, frequencies } = await loadWikiWordList();
|
|
20
|
+
const spell = createSpellChecker({ words, frequencies });
|
|
21
|
+
|
|
22
|
+
const result = spell.check('مەن مەكتەت كە باردىم');
|
|
23
|
+
for (const issue of result.issues) {
|
|
24
|
+
console.log(issue.original, issue.start, issue.end, issue.suggestions.map((s) => s.text));
|
|
25
|
+
// مەكتەت 4 10 [ 'مەكتەپ', 'مەكتەب' ]
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
spell.isKnown('كىتابلىرىمىز'); // true: كىتاب + plural + possessive
|
|
29
|
+
spell.suggest('ھۆكۈمەد'); // [{ text: 'ھۆكۈمدە', ... }, { text: 'ھۆكۈمەت', ... }, ...]
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Without a word list, `createSpellChecker()` uses a built-in seed of a few hundred common roots. That's enough to try the API, but it flags most words in real text. Use the full list, or your own, for real work.
|
|
33
|
+
|
|
34
|
+
## What it does
|
|
35
|
+
|
|
36
|
+
- **Recognises inflected forms.** Strips case, possessive, plural and derivational suffixes and checks the stem, respecting vowel harmony, verb endings and particles (‑لا، ‑مۇ، ‑چۇ، ‑غۇ). A form that only parses through suffixes, but is one slip away from a very common word, is still flagged (ئۈنىڭ → ئۇنىڭ).
|
|
37
|
+
- **Ranks suggestions** with a confusion model of Uyghur letters (ۇ/ۈ، و/ۆ، ك/گ/ق، initial ئ …), word frequency, and your personal dictionary.
|
|
38
|
+
- **Reports, never rewrites.** Every issue has exact UTF-16 offsets into the original text. You decide what to apply, with `applyCorrections(text, edits)`.
|
|
39
|
+
- **Normalizes safely.** `normalize(text)` makes only lossless fixes: presentation forms to base letters, ک → ك, tatweel, zero-width characters. Characters that need a judgement are reported as `ambiguous-character` issues instead.
|
|
40
|
+
- **Learns.** A `UserDictionary` remembers words the user confirms. It lives in memory unless you pass storage:
|
|
41
|
+
|
|
42
|
+
```js
|
|
43
|
+
import { createSpellChecker, UserDictionary } from '@uyghurcommunity/spell';
|
|
44
|
+
|
|
45
|
+
const dictionary = new UserDictionary({ storage: localStorage }); // optional persistence
|
|
46
|
+
const spell = createSpellChecker({ words, frequencies, dictionary });
|
|
47
|
+
spell.learn('توختىنياز'); // now known, and saved
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Accuracy
|
|
51
|
+
|
|
52
|
+
The engine was developed and measured in [uyghur-ocr](https://github.com/WarisWorks/uyghur-ocr), on synthetic pages rendered from held-out Uyghur Wikipedia sentences and read back with Tesseract. With the Wikipedia list it caught about **84%** of misspelled words on clean pages and **80%** on degraded ones. About **76%** of what it flagged were real errors, and the right word was the top suggestion about **70%** of the time.
|
|
53
|
+
|
|
54
|
+
These numbers come from OCR errors on single-font synthetic pages. Typing mistakes and real scans behave differently, so treat them as a baseline. The method is in uyghur-ocr's `bench/README.md`.
|
|
55
|
+
|
|
56
|
+
## Status and review
|
|
57
|
+
|
|
58
|
+
- **Not reviewed by a native speaker yet:** the seed list (`src/data/roots.js`), the suffix tables and the confusion model. Corrections from Uyghur speakers are the most valuable contribution.
|
|
59
|
+
- **The Wikipedia list contains typos from Wikipedia itself.** A minimum count filters rare forms, but can't guarantee correctness.
|
|
60
|
+
- **Tuned for OCR errors.** Ordinary typos are handled through edit distance, but the ranking was optimised for OCR.
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
| Export | Purpose |
|
|
65
|
+
|---|---|
|
|
66
|
+
| `createSpellChecker(options)` | An independent checker: `check`, `suggest`, `isKnown`, `learn`, `lexicon` |
|
|
67
|
+
| `normalize(text)`, `describeNormalization(text)` | Lossless encoding fixes, and what they would change |
|
|
68
|
+
| `analyze(text, { lexicon })`, `suggestFor(word, lexicon)` | The engine behind `check` and `suggest` |
|
|
69
|
+
| `applyCorrections(text, edits)` | Apply the corrections you accepted |
|
|
70
|
+
| `UserDictionary` | Personal words, optional storage |
|
|
71
|
+
| `Lexicon`, `segment`, `tokenize`, `editDistance` … | Lower-level building blocks |
|
|
72
|
+
|
|
73
|
+
Full types are in `src/index.d.ts`.
|
|
74
|
+
|
|
75
|
+
## Development
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
npm install
|
|
79
|
+
npm test # engine tests (Vitest)
|
|
80
|
+
cd packages/lexicon-wiki && npm test
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
The word list can be rebuilt from a Uyghur Wikipedia dump with `packages/lexicon-wiki/scripts/build-lexicon.mjs`.
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
- **Code:** [MIT](LICENSE).
|
|
88
|
+
- **Word list** (`@uyghurcommunity/spell-lexicon-wiki`): derived from Uyghur Wikipedia, licensed [CC BY-SA 4.0](packages/lexicon-wiki/LICENSE) by Wikipedia contributors. If you redistribute it, keep the attribution, and share changes to the list under the same licence.
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uyghurcommunity/spell",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Uyghur spell-checking and correction: morphology-aware word recognition, ranked suggestions, safe normalization and a personal dictionary. No runtime dependencies.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"import": "./src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE",
|
|
18
|
+
"CHANGELOG.md"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"engines": {
|
|
22
|
+
"node": ">=18"
|
|
23
|
+
},
|
|
24
|
+
"scripts": {
|
|
25
|
+
"test": "vitest run",
|
|
26
|
+
"check": "node --check src/index.js && node -e \"import('./src/index.js').then(m => { if (typeof m.createSpellChecker !== 'function') process.exit(1) })\""
|
|
27
|
+
},
|
|
28
|
+
"keywords": ["uyghur", "spellcheck", "spell-checker", "nlp", "morphology", "arabic-script", "rtl", "low-resource-languages", "ocr"],
|
|
29
|
+
"author": "UyghurCommunity",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+https://github.com/UyghurCommunity/uyghur-spell.git"
|
|
34
|
+
},
|
|
35
|
+
"homepage": "https://github.com/UyghurCommunity/uyghur-spell#readme",
|
|
36
|
+
"bugs": "https://github.com/UyghurCommunity/uyghur-spell/issues",
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"vitest": "^2.1.9"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCR confusion model for the Uyghur Arabic script.
|
|
3
|
+
*
|
|
4
|
+
* A plain edit distance treats every substitution as equally likely, which is
|
|
5
|
+
* wrong for this script and wrong in a way that matters. In Arabic script most
|
|
6
|
+
* letters are built from a small number of shared skeletons distinguished only
|
|
7
|
+
* by dots: ب پ ت ن ي are one skeleton with different dotting, as are ج چ خ,
|
|
8
|
+
* and ر ز ژ. An OCR engine that loses or invents a dot produces a different
|
|
9
|
+
* letter, and that is by far the most common error on this material.
|
|
10
|
+
*
|
|
11
|
+
* Weighting those substitutions cheaply — and unrelated ones at full cost —
|
|
12
|
+
* means the top suggestion for a misread word is usually the intended word,
|
|
13
|
+
* rather than an unrelated word that happens to be one generic edit away.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Groups of letters that share a skeleton or a diacritic position and are
|
|
18
|
+
* therefore mutually confusable. Each group carries the cost of substituting
|
|
19
|
+
* one member for another.
|
|
20
|
+
*
|
|
21
|
+
* @type {Array<{letters: string[], cost: number, reason: string}>}
|
|
22
|
+
*/
|
|
23
|
+
export const CONFUSION_GROUPS = [
|
|
24
|
+
{
|
|
25
|
+
// The "tooth" skeleton: identical body, distinguished only by dots above
|
|
26
|
+
// or below. The single largest source of OCR error in Uyghur.
|
|
27
|
+
letters: ['ب', 'پ', 'ت', 'ن', 'ي', 'ى', 'ئ'],
|
|
28
|
+
cost: 0.3,
|
|
29
|
+
reason: 'shared tooth skeleton, differing only in dots',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
letters: ['ج', 'چ', 'خ'],
|
|
33
|
+
cost: 0.3,
|
|
34
|
+
reason: 'shared body, differing in dots',
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
letters: ['ر', 'ز', 'ژ'],
|
|
38
|
+
cost: 0.3,
|
|
39
|
+
reason: 'shared body, differing in dots',
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
letters: ['س', 'ش'],
|
|
43
|
+
cost: 0.3,
|
|
44
|
+
reason: 'shared body, differing in dots',
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
letters: ['ف', 'ق'],
|
|
48
|
+
cost: 0.4,
|
|
49
|
+
reason: 'similar body, differing in dots',
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
letters: ['ك', 'گ', 'ڭ'],
|
|
53
|
+
cost: 0.3,
|
|
54
|
+
reason: 'shared kaf skeleton, differing in stroke and dots',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
// Diacritics above waw. Frequently lost on low-resolution scans, which
|
|
58
|
+
// collapses four distinct vowels into one.
|
|
59
|
+
letters: ['و', 'ۇ', 'ۆ', 'ۈ', 'ۋ', 'ؤ'],
|
|
60
|
+
cost: 0.3,
|
|
61
|
+
reason: 'waw with differing diacritics',
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
// The commonest single slip in Tesseract's Uyghur output: the two dots of
|
|
65
|
+
// ۈ/ۆ lost or added. Cheaper than a consonant's dots, so تۈرۈپ ranks تۇرۇپ
|
|
66
|
+
// (vowel marks only) above تۈزۈپ (a consonant changed). Arabic ؤ is read
|
|
67
|
+
// for ۇ in the same way.
|
|
68
|
+
letters: ['ۇ', 'ۈ'],
|
|
69
|
+
cost: 0.15,
|
|
70
|
+
reason: 'rounded vowels differing only in their dots',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
letters: ['و', 'ۆ'],
|
|
74
|
+
cost: 0.15,
|
|
75
|
+
reason: 'rounded vowels differing only in their dots',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
letters: ['ؤ', 'ۇ'],
|
|
79
|
+
cost: 0.15,
|
|
80
|
+
reason: 'Arabic waw with hamza read for ۇ',
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
letters: ['ې', 'ى', 'ي'],
|
|
84
|
+
cost: 0.35,
|
|
85
|
+
reason: 'yeh-family vowels and glide',
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
letters: ['ھ', 'ە'],
|
|
89
|
+
cost: 0.4,
|
|
90
|
+
reason: 'heh-family letters with similar contours',
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
letters: ['غ', 'ع', 'خ'],
|
|
94
|
+
cost: 0.4,
|
|
95
|
+
reason: 'ain-family bodies, differing in dots',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
letters: ['د', 'ر'],
|
|
99
|
+
cost: 0.5,
|
|
100
|
+
reason: 'short descender bodies',
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
letters: ['ا', 'ل'],
|
|
104
|
+
cost: 0.6,
|
|
105
|
+
reason: 'bare vertical strokes',
|
|
106
|
+
},
|
|
107
|
+
];
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Substitution cost lookup, built once from the groups above.
|
|
111
|
+
* @type {Map<string, number>}
|
|
112
|
+
*/
|
|
113
|
+
const substitutionCosts = buildCostTable();
|
|
114
|
+
|
|
115
|
+
function buildCostTable() {
|
|
116
|
+
const table = new Map();
|
|
117
|
+
for (const group of CONFUSION_GROUPS) {
|
|
118
|
+
for (const a of group.letters) {
|
|
119
|
+
for (const b of group.letters) {
|
|
120
|
+
if (a === b) continue;
|
|
121
|
+
const key = `${a} ${b}`;
|
|
122
|
+
// A pair appearing in several groups takes the lowest (most forgiving)
|
|
123
|
+
// cost, since any one of those relationships makes the confusion likely.
|
|
124
|
+
const existing = table.get(key);
|
|
125
|
+
if (existing === undefined || group.cost < existing) table.set(key, group.cost);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return table;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Combining marks that OCR adds or drops far more readily than whole letters.
|
|
134
|
+
* Written as escapes because they are invisible on their own in an editor.
|
|
135
|
+
*/
|
|
136
|
+
const COMBINING_MARKS = new Set([
|
|
137
|
+
'ٔ', // hamza above
|
|
138
|
+
'ٕ', // hamza below
|
|
139
|
+
'ً', 'ٌ', 'ٍ', // tanween
|
|
140
|
+
'َ', 'ُ', 'ِ', // short vowels
|
|
141
|
+
'ّ', 'ْ', // shadda, sukun
|
|
142
|
+
]);
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Cost of substituting `b` for `a`. 0 when identical, 1 when unrelated.
|
|
146
|
+
* @param {string} a
|
|
147
|
+
* @param {string} b
|
|
148
|
+
* @returns {number}
|
|
149
|
+
*/
|
|
150
|
+
export function substitutionCost(a, b) {
|
|
151
|
+
if (a === b) return 0;
|
|
152
|
+
return substitutionCosts.get(`${a} ${b}`) ?? 1;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Cost of inserting or deleting a character.
|
|
157
|
+
*
|
|
158
|
+
* The hamza carrier and combining marks are dropped and spuriously added far
|
|
159
|
+
* more often than full letters, so they cost less to insert or delete.
|
|
160
|
+
*
|
|
161
|
+
* @param {string} char
|
|
162
|
+
* @returns {number}
|
|
163
|
+
*/
|
|
164
|
+
export function indelCost(char) {
|
|
165
|
+
if (char === 'ئ') return 0.5;
|
|
166
|
+
if (COMBINING_MARKS.has(char)) return 0.3;
|
|
167
|
+
return 1;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Whether two letters are considered confusable at all.
|
|
172
|
+
* @param {string} a
|
|
173
|
+
* @param {string} b
|
|
174
|
+
* @returns {boolean}
|
|
175
|
+
*/
|
|
176
|
+
export function areConfusable(a, b) {
|
|
177
|
+
return a !== b && substitutionCosts.has(`${a} ${b}`);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Describe why two words might have been confused, for display next to a
|
|
182
|
+
* suggestion. Returns null when the difference is not a single substitution.
|
|
183
|
+
*
|
|
184
|
+
* @param {string} a
|
|
185
|
+
* @param {string} b
|
|
186
|
+
* @returns {{from: string, to: string, reason: string} | null}
|
|
187
|
+
*/
|
|
188
|
+
export function explainDifference(a, b) {
|
|
189
|
+
if (a.length !== b.length) return null;
|
|
190
|
+
|
|
191
|
+
let diffIndex = -1;
|
|
192
|
+
for (let i = 0; i < a.length; i++) {
|
|
193
|
+
if (a[i] === b[i]) continue;
|
|
194
|
+
if (diffIndex !== -1) return null; // more than one difference
|
|
195
|
+
diffIndex = i;
|
|
196
|
+
}
|
|
197
|
+
if (diffIndex === -1) return null;
|
|
198
|
+
|
|
199
|
+
const from = a[diffIndex];
|
|
200
|
+
const to = b[diffIndex];
|
|
201
|
+
const group = CONFUSION_GROUPS.find((g) => g.letters.includes(from) && g.letters.includes(to));
|
|
202
|
+
return group ? { from, to, reason: group.reason } : null;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Skeleton classes: the confusion groups merged wherever they share a letter,
|
|
207
|
+
* so that every cheap substitution stays inside one class. Used to bound edit
|
|
208
|
+
* distance from below without running it (see `skeletonLowerBound`).
|
|
209
|
+
*
|
|
210
|
+
* @type {Map<string, number>} letter → class index
|
|
211
|
+
*/
|
|
212
|
+
export const SKELETON_CLASS = (() => {
|
|
213
|
+
const parent = new Map();
|
|
214
|
+
const find = (x) => {
|
|
215
|
+
while (parent.get(x) !== x) x = parent.get(x);
|
|
216
|
+
return x;
|
|
217
|
+
};
|
|
218
|
+
for (const { letters } of CONFUSION_GROUPS) {
|
|
219
|
+
for (const l of letters) if (!parent.has(l)) parent.set(l, l);
|
|
220
|
+
for (const l of letters.slice(1)) parent.set(find(l), find(letters[0]));
|
|
221
|
+
}
|
|
222
|
+
const ids = new Map();
|
|
223
|
+
const classes = new Map();
|
|
224
|
+
for (const l of parent.keys()) {
|
|
225
|
+
const root = find(l);
|
|
226
|
+
if (!ids.has(root)) ids.set(root, ids.size);
|
|
227
|
+
classes.set(l, ids.get(root));
|
|
228
|
+
}
|
|
229
|
+
return classes;
|
|
230
|
+
})();
|
|
231
|
+
|
|
232
|
+
/** Number of skeleton classes, plus one shared bucket for every other letter. */
|
|
233
|
+
export const SKELETON_CLASS_COUNT = Math.max(-1, ...SKELETON_CLASS.values()) + 1;
|
|
234
|
+
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Seed root lexicon for Uyghur.
|
|
3
|
+
*
|
|
4
|
+
* ── SCOPE AND STATUS ────────────────────────────────────────────────────────
|
|
5
|
+
* This is a SEED, not a dictionary. It holds a few hundred high-frequency roots
|
|
6
|
+
* and function words so the correction engine has something to work against out
|
|
7
|
+
* of the box. It is nowhere near the coverage real text needs, and it has not
|
|
8
|
+
* been reviewed by a native speaker.
|
|
9
|
+
*
|
|
10
|
+
* Two consequences follow, and both are enforced in `suggest.js` rather than
|
|
11
|
+
* left to convention:
|
|
12
|
+
*
|
|
13
|
+
* 1. A word missing from this list means nothing on its own. Absence is never
|
|
14
|
+
* reported as a misspelling — only a word that is BOTH unknown AND has a
|
|
15
|
+
* close known neighbour is surfaced, and then only as a suggestion.
|
|
16
|
+
* 2. Nothing here is ever applied automatically. A spelling tool that injects
|
|
17
|
+
* its own errors into the user's text is worse than no tool at all.
|
|
18
|
+
*
|
|
19
|
+
* ── EXTENDING ───────────────────────────────────────────────────────────────
|
|
20
|
+
* Load a real lexicon at runtime with `loadLexicon()` from `../lexicon.js`; it
|
|
21
|
+
* takes any iterable of words and supersedes this list. A word list of 50-100k
|
|
22
|
+
* inflected forms, or 20-30k roots paired with the morphology module, is what
|
|
23
|
+
* this engine is actually designed for.
|
|
24
|
+
*
|
|
25
|
+
* Entries are stored as roots. The morphology module strips plural, possessive
|
|
26
|
+
* and case suffixes before lookup, so كىتاب covers كىتابلار, كىتابىم,
|
|
27
|
+
* كىتابلىرىمىزدىن and the rest without listing them.
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* High-frequency Uyghur roots and function words.
|
|
32
|
+
* Grouped by part of speech for reviewability rather than for any runtime use.
|
|
33
|
+
*
|
|
34
|
+
* @type {string[]}
|
|
35
|
+
*/
|
|
36
|
+
export const SEED_ROOTS = [
|
|
37
|
+
// ── Pronouns and determiners ──
|
|
38
|
+
'مەن', 'سەن', 'سىز', 'ئۇ', 'بىز', 'سىلەر', 'ئۇلار',
|
|
39
|
+
'بۇ', 'شۇ', 'ئاشۇ', 'مۇشۇ', 'ھەر', 'ھەممە', 'بەزى', 'ئۆز',
|
|
40
|
+
|
|
41
|
+
// ── Question words ──
|
|
42
|
+
'كىم', 'نېمە', 'قانداق', 'قاچان', 'قەيەر', 'نەدە', 'نەگە', 'قانچە', 'نېمىشقا',
|
|
43
|
+
|
|
44
|
+
// ── Conjunctions, particles, postpositions ──
|
|
45
|
+
'ۋە', 'بىلەن', 'ئۈچۈن', 'ئەمما', 'لېكىن', 'ياكى', 'ھەم', 'گەرچە',
|
|
46
|
+
'چۈنكى', 'ئەگەر', 'ئاندىن', 'يەنە', 'ئەمەس', 'يوق', 'بار', 'ياق',
|
|
47
|
+
'كېيىن', 'بۇرۇن', 'ئارقىلىق', 'توغرىسىدا', 'قارىتا',
|
|
48
|
+
|
|
49
|
+
// ── Numbers ──
|
|
50
|
+
'بىر', 'ئىككى', 'ئۈچ', 'تۆت', 'بەش', 'ئالتە', 'يەتتە', 'سەككىز',
|
|
51
|
+
'توققۇز', 'ئون', 'يىگىرمە', 'ئوتتۇز', 'قىرىق', 'ئەللىك', 'ئاتمىش',
|
|
52
|
+
'يەتمىش', 'سەكسەن', 'توقسان', 'يۈز', 'مىڭ', 'مىليون',
|
|
53
|
+
|
|
54
|
+
// ── People and society ──
|
|
55
|
+
'ئادەم', 'كىشى', 'بالا', 'ئانا', 'ئاتا', 'دادا', 'ئاپا', 'ئوغۇل', 'قىز',
|
|
56
|
+
'ئاكا', 'ئۇكا', 'ئاچا', 'سىڭىل', 'دوست', 'خەلق', 'مىللەت', 'ئائىلە',
|
|
57
|
+
'ئايال', 'ئەر', 'بوۋاي', 'مومام', 'ئوقۇغۇچى', 'ئوقۇتقۇچى', 'دوختۇر',
|
|
58
|
+
'ئىشچى', 'دېھقان', 'يازغۇچى', 'شائىر',
|
|
59
|
+
|
|
60
|
+
// ── Places ──
|
|
61
|
+
'ئۆي', 'مەكتەپ', 'شەھەر', 'يېزا', 'يۇرت', 'ۋەتەن', 'دۆلەت', 'دۇنيا',
|
|
62
|
+
'بازار', 'كوچا', 'يول', 'ئۆلكە', 'ناھىيە', 'دۆڭ', 'باغ', 'ئىشخانا',
|
|
63
|
+
'دوختۇرخانا', 'كۈتۈپخانا', 'مۇزېي',
|
|
64
|
+
|
|
65
|
+
// ── Nature and time ──
|
|
66
|
+
'يەر', 'ئاسمان', 'قۇياش', 'ئاي', 'يۇلتۇز', 'بۇلۇت', 'يامغۇر', 'قار',
|
|
67
|
+
'شامال', 'ئوت', 'سۇ', 'تاغ', 'دەريا', 'كۆل', 'دېڭىز', 'چۆل',
|
|
68
|
+
'گۈل', 'دەرەخ', 'ياپراق', 'ئوت', 'تاش', 'قۇم',
|
|
69
|
+
'كۈن', 'يىل', 'ۋاقىت', 'سائەت', 'مىنۇت', 'ھەپتە', 'ئەتىگەن', 'چۈش',
|
|
70
|
+
'كەچ', 'كېچە', 'بۈگۈن', 'ئەتە', 'تۈنۈگۈن', 'ھازىر', 'باھار', 'ياز',
|
|
71
|
+
'كۈز', 'قىش',
|
|
72
|
+
|
|
73
|
+
// ── Animals ──
|
|
74
|
+
'ئات', 'قوي', 'كالا', 'ئۆچكە', 'توخۇ', 'قۇش', 'بېلىق', 'ئىت', 'مۈشۈك',
|
|
75
|
+
'تۆگە', 'ئېشەك', 'بۆرە', 'تۈلكە',
|
|
76
|
+
|
|
77
|
+
// ── Food ──
|
|
78
|
+
'نان', 'گۆش', 'چاي', 'سۈت', 'تۇز', 'شېكەر', 'ياغ', 'تۇخۇم', 'گۈرۈچ',
|
|
79
|
+
'ئالما', 'ئۈزۈم', 'قوغۇن', 'تاۋۇز', 'ئانار', 'ئەنجۈر', 'ياڭاق',
|
|
80
|
+
'پولۇ', 'لەغمەن', 'سامسا', 'مانتا', 'چۆچۈرە', 'تاماق',
|
|
81
|
+
|
|
82
|
+
// ── Language, learning, culture ──
|
|
83
|
+
'تىل', 'سۆز', 'خەت', 'قەلەم', 'كىتاب', 'دەپتەر', 'ھەرپ', 'جۈملە',
|
|
84
|
+
'تارىخ', 'مەدەنىيەت', 'سەنئەت', 'ناخشا', 'مۇزىكا', 'ئۇسۇل', 'شېئىر',
|
|
85
|
+
'ھېكايە', 'رومان', 'ماقالە', 'گېزىت', 'ژۇرنال', 'ئىلىم', 'پەن',
|
|
86
|
+
'دەرس', 'ئىمتىھان', 'سوئال', 'جاۋاب',
|
|
87
|
+
|
|
88
|
+
// ── Everyday objects ──
|
|
89
|
+
'ئىش', 'نەرسە', 'ئىشىك', 'دېرىزە', 'ئۈستەل', 'ئورۇندۇق', 'كارىۋات',
|
|
90
|
+
'كىيىم', 'ئاياغ', 'دوپپا', 'پۇل', 'ماشىنا', 'پويىز', 'ئايروپىلان',
|
|
91
|
+
'تېلېفون', 'كومپيۇتېر', 'رەسىم', 'سۈرەت',
|
|
92
|
+
|
|
93
|
+
// ── Body ──
|
|
94
|
+
'باش', 'كۆز', 'قۇلاق', 'بۇرۇن', 'ئېغىز', 'قول', 'پۇت', 'يۈرەك',
|
|
95
|
+
'چاچ', 'تىل', 'چىش', 'يۈز',
|
|
96
|
+
|
|
97
|
+
// ── Adjectives ──
|
|
98
|
+
'ياخشى', 'يامان', 'چوڭ', 'كىچىك', 'ئۇزۇن', 'قىسقا', 'يېڭى', 'كونا',
|
|
99
|
+
'ئىسسىق', 'سوغۇق', 'گۈزەل', 'چىرايلىق', 'ئېغىر', 'يېنىك', 'كۆپ', 'ئاز',
|
|
100
|
+
'توغرا', 'خاتا', 'ئاسان', 'قىيىن', 'تېز', 'ئاستا', 'يىراق', 'يېقىن',
|
|
101
|
+
'ئوچۇق', 'ئېنىق', 'مۇھىم', 'كېرەك', 'باي', 'كەمبەغەل',
|
|
102
|
+
|
|
103
|
+
// ── Colours ──
|
|
104
|
+
'قىزىل', 'ئاق', 'قارا', 'كۆك', 'سېرىق', 'يېشىل', 'بوز', 'قوڭۇر',
|
|
105
|
+
|
|
106
|
+
// ── Verb roots ──
|
|
107
|
+
'كەل', 'بار', 'قىل', 'بول', 'كۆر', 'ئاڭلا', 'ئېيت', 'دە', 'سورا',
|
|
108
|
+
'ئوقۇ', 'يېز', 'ئال', 'بەر', 'يە', 'ئىچ', 'ياز', 'تۇر', 'ئولتۇر',
|
|
109
|
+
'ماڭ', 'يۈر', 'قال', 'چىق', 'كىر', 'باشلا', 'تۈگە', 'بىل', 'ئويلا',
|
|
110
|
+
'سۆزلە', 'ئىشلە', 'ئوينا', 'كۈل', 'يىغلا', 'ئۇخلا', 'ئويغان', 'يۇ',
|
|
111
|
+
'كىي', 'ياسا', 'ئاچ', 'ياپ', 'تاپ', 'يوقات', 'ئىزدە', 'كۈت', 'ئۆت',
|
|
112
|
+
'قايت', 'ئەكەل', 'ئاپار', 'ئۆگەن', 'ئۆگەت', 'چۈشەن', 'ئەسلە', 'ئۇنۇت',
|
|
113
|
+
'ياخشىلا', 'ياردەملەش', 'ساقلا', 'كۆرسەت', 'ئىشەن', 'خالا', 'سۆي',
|
|
114
|
+
];
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Words that are correct but that a root-plus-suffix analysis would not reach,
|
|
118
|
+
* usually because they are irregular or lexicalised.
|
|
119
|
+
* @type {string[]}
|
|
120
|
+
*/
|
|
121
|
+
export const SEED_EXCEPTIONS = [
|
|
122
|
+
'ھەئە', 'ماقۇل', 'رەھمەت', 'كەچۈرۈڭ', 'مەرھەمەت', 'خەير',
|
|
123
|
+
'ياخشىمۇسىز', 'سالام', 'خوش',
|
|
124
|
+
];
|