tinyfix-tr 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/LICENSE +21 -0
- package/README.md +138 -2
- package/dist/pkg/src/context.d.ts +13 -0
- package/dist/pkg/src/context.js +80 -0
- package/dist/pkg/src/data.d.ts +50 -0
- package/dist/pkg/src/data.js +495 -0
- package/dist/pkg/src/engine.d.ts +39 -0
- package/dist/pkg/src/engine.js +357 -0
- package/dist/pkg/src/index.d.ts +30 -0
- package/dist/pkg/src/index.js +85 -0
- package/dist/pkg/src/protocol.d.ts +64 -0
- package/dist/pkg/src/protocol.js +1 -0
- package/dist/pkg/src/types.d.ts +184 -0
- package/dist/pkg/src/types.js +16 -0
- package/dist/pkg/src/worker.d.ts +11 -0
- package/dist/pkg/src/worker.js +111 -0
- package/dist/pkg/src/workerClient.d.ts +3 -0
- package/dist/pkg/src/workerClient.js +202 -0
- package/dist/src/context-vocab.d.ts +1 -0
- package/dist/src/context-vocab.js +2 -0
- package/dist/src/context.d.ts +92 -0
- package/dist/src/context.js +390 -0
- package/dist/src/corrector.d.ts +338 -0
- package/dist/src/corrector.js +2684 -0
- package/dist/src/known.d.ts +88 -0
- package/dist/src/known.js +286 -0
- package/dist/src/lexicon-binary.d.ts +85 -0
- package/dist/src/lexicon-binary.js +805 -0
- package/dist/src/lexicon.d.ts +24 -0
- package/dist/src/lexicon.js +79 -0
- package/dist/src/morphology/analyzer.d.ts +30 -0
- package/dist/src/morphology/analyzer.js +311 -0
- package/dist/src/morphology/binary.d.ts +22 -0
- package/dist/src/morphology/binary.js +372 -0
- package/dist/src/morphology/dictionary.d.ts +21 -0
- package/dist/src/morphology/dictionary.js +559 -0
- package/dist/src/morphology/fuzzy.d.ts +44 -0
- package/dist/src/morphology/fuzzy.js +599 -0
- package/dist/src/morphology/index.d.ts +40 -0
- package/dist/src/morphology/index.js +81 -0
- package/dist/src/morphology/morphotactics.d.ts +148 -0
- package/dist/src/morphology/morphotactics.js +1871 -0
- package/dist/src/morphology/phonetics.d.ts +71 -0
- package/dist/src/morphology/phonetics.js +309 -0
- package/dist/src/morphology/prior.d.ts +61 -0
- package/dist/src/morphology/prior.js +457 -0
- package/dist/src/morphology/types.d.ts +110 -0
- package/dist/src/morphology/types.js +32 -0
- package/dist/src/rules/proper-names.d.ts +145 -0
- package/dist/src/rules/proper-names.js +1217 -0
- package/dist/src/rules/turkish-rules.d.ts +126 -0
- package/dist/src/rules/turkish-rules.js +365 -0
- package/dist/src/sentence.d.ts +83 -0
- package/dist/src/sentence.js +2408 -0
- package/dist/src/turkish.d.ts +20 -0
- package/dist/src/turkish.js +94 -0
- package/package.json +60 -4
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** Turkish-aware casing and letter helpers. JavaScript's own toLowerCase gets I/ı and İ/i wrong for Turkish. */
|
|
2
|
+
export declare const LETTERS = "A-Za-z\u00C7\u011E\u0130\u00D6\u015E\u00DC\u00E7\u011F\u0131\u00F6\u015F\u00FC\u00C2\u00CE\u00DB\u00E2\u00EE\u00FB";
|
|
3
|
+
export declare function lowerTr(text: string): string;
|
|
4
|
+
export declare function upperTr(text: string): string;
|
|
5
|
+
export declare function isLetter(char: string): boolean;
|
|
6
|
+
export declare function isUpperInitial(word: string): boolean;
|
|
7
|
+
export declare function isAllUpper(word: string): boolean;
|
|
8
|
+
/** Gives the replacement the typed word's casing: "Cok" becomes "Çok", "COK" becomes "ÇOK". */
|
|
9
|
+
export declare function matchCase(typed: string, replacement: string): string;
|
|
10
|
+
/**
|
|
11
|
+
* Words that differ from a lowercase word only in Turkish marks: "cok" gives "çok", "çök", "cök", "çok"...
|
|
12
|
+
* Only ASCII letters are toggled to Turkish ones, except a leading "ı" which is how a typed capital "I" lowercases
|
|
13
|
+
* ("Istanbul" lowercases to "ıstanbul" and should be able to reach "istanbul").
|
|
14
|
+
*/
|
|
15
|
+
export declare function markVariants(word: string, limit?: number): string[];
|
|
16
|
+
export declare function hasTurkishMarks(text: string): boolean;
|
|
17
|
+
/** Replaces Turkish letters with their plain forms inside the given [start, end) ranges; the length stays the same. */
|
|
18
|
+
export declare function stripMarksIn(text: string, ranges: readonly (readonly [number, number])[]): string;
|
|
19
|
+
export declare function areNearKeys(first: string, second: string): boolean;
|
|
20
|
+
export declare const ALPHABET = "abc\u00E7defg\u011Fh\u0131ijklmno\u00F6prs\u015Ftu\u00FCvyz";
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/** Turkish-aware casing and letter helpers. JavaScript's own toLowerCase gets I/ı and İ/i wrong for Turkish. */
|
|
2
|
+
export const LETTERS = "A-Za-zÇĞİÖŞÜçğıöşüÂÎÛâîû";
|
|
3
|
+
const LETTER = new RegExp(`^[${LETTERS}]$`);
|
|
4
|
+
export function lowerTr(text) {
|
|
5
|
+
return text.replaceAll("I", "ı").replaceAll("İ", "i").toLowerCase().replaceAll("’", "'");
|
|
6
|
+
}
|
|
7
|
+
export function upperTr(text) {
|
|
8
|
+
return text.replaceAll("i", "İ").replaceAll("ı", "I").toUpperCase();
|
|
9
|
+
}
|
|
10
|
+
export function isLetter(char) {
|
|
11
|
+
return LETTER.test(char);
|
|
12
|
+
}
|
|
13
|
+
export function isUpperInitial(word) {
|
|
14
|
+
const first = word[0] ?? "";
|
|
15
|
+
return first !== lowerTr(first);
|
|
16
|
+
}
|
|
17
|
+
export function isAllUpper(word) {
|
|
18
|
+
return word.length > 1 && word === upperTr(word) && word !== lowerTr(word);
|
|
19
|
+
}
|
|
20
|
+
/** Gives the replacement the typed word's casing: "Cok" becomes "Çok", "COK" becomes "ÇOK". */
|
|
21
|
+
export function matchCase(typed, replacement) {
|
|
22
|
+
if (isAllUpper(typed))
|
|
23
|
+
return upperTr(replacement);
|
|
24
|
+
if (isUpperInitial(typed))
|
|
25
|
+
return upperTr(replacement.slice(0, 1)) + replacement.slice(1);
|
|
26
|
+
return replacement;
|
|
27
|
+
}
|
|
28
|
+
/** Letters that lose their marks when typed on a keyboard without Turkish characters, and back. */
|
|
29
|
+
const TOGGLE = { c: "ç", g: "ğ", i: "ı", o: "ö", s: "ş", u: "ü", ı: "i", ç: "c", ğ: "g", ö: "o", ş: "s", ü: "u" };
|
|
30
|
+
const ASCII_SIDE = new Set(["c", "g", "i", "o", "s", "u"]);
|
|
31
|
+
/**
|
|
32
|
+
* Words that differ from a lowercase word only in Turkish marks: "cok" gives "çok", "çök", "cök", "çok"...
|
|
33
|
+
* Only ASCII letters are toggled to Turkish ones, except a leading "ı" which is how a typed capital "I" lowercases
|
|
34
|
+
* ("Istanbul" lowercases to "ıstanbul" and should be able to reach "istanbul").
|
|
35
|
+
*/
|
|
36
|
+
export function markVariants(word, limit = 512) {
|
|
37
|
+
const positions = [];
|
|
38
|
+
for (let index = 0; index < word.length; index++) {
|
|
39
|
+
const char = word[index];
|
|
40
|
+
if (ASCII_SIDE.has(char) || (char === "ı" && index === 0))
|
|
41
|
+
positions.push(index);
|
|
42
|
+
}
|
|
43
|
+
const variants = [];
|
|
44
|
+
const count = Math.min(2 ** positions.length, limit);
|
|
45
|
+
for (let mask = 1; mask < count; mask++) {
|
|
46
|
+
const chars = [...word];
|
|
47
|
+
positions.forEach((position, bit) => {
|
|
48
|
+
if (mask & (1 << bit))
|
|
49
|
+
chars[position] = TOGGLE[chars[position]];
|
|
50
|
+
});
|
|
51
|
+
variants.push(chars.join(""));
|
|
52
|
+
}
|
|
53
|
+
return variants;
|
|
54
|
+
}
|
|
55
|
+
export function hasTurkishMarks(text) {
|
|
56
|
+
return /[çğıöşüÇĞİÖŞÜ]/.test(text);
|
|
57
|
+
}
|
|
58
|
+
const UNMARKED = { ç: "c", ğ: "g", ı: "i", ö: "o", ş: "s", ü: "u", Ç: "C", Ğ: "G", İ: "I", Ö: "O", Ş: "S", Ü: "U" };
|
|
59
|
+
/** Replaces Turkish letters with their plain forms inside the given [start, end) ranges; the length stays the same. */
|
|
60
|
+
export function stripMarksIn(text, ranges) {
|
|
61
|
+
if (ranges.length === 0)
|
|
62
|
+
return text;
|
|
63
|
+
const chars = text.split(""); // UTF-16 units, so the ranges line up with string offsets
|
|
64
|
+
for (const [start, end] of ranges) {
|
|
65
|
+
for (let i = Math.max(0, start); i < Math.min(end, chars.length); i++)
|
|
66
|
+
chars[i] = UNMARKED[chars[i]] ?? chars[i];
|
|
67
|
+
}
|
|
68
|
+
return chars.join("");
|
|
69
|
+
}
|
|
70
|
+
/** Turkish Q keyboard rows, used to judge how likely a slip of the fingers is. */
|
|
71
|
+
const KEYBOARD_ROWS = ["qwertyuıopğü", "asdfghjklşi", "zxcvbnmöç"];
|
|
72
|
+
const NEAR = new Map();
|
|
73
|
+
KEYBOARD_ROWS.forEach((row, rowIndex) => {
|
|
74
|
+
[...row].forEach((key, keyIndex) => {
|
|
75
|
+
const near = new Set();
|
|
76
|
+
for (const [r, c] of [
|
|
77
|
+
[rowIndex, keyIndex - 1],
|
|
78
|
+
[rowIndex, keyIndex + 1],
|
|
79
|
+
[rowIndex - 1, keyIndex],
|
|
80
|
+
[rowIndex - 1, keyIndex + 1],
|
|
81
|
+
[rowIndex + 1, keyIndex],
|
|
82
|
+
[rowIndex + 1, keyIndex - 1],
|
|
83
|
+
]) {
|
|
84
|
+
const key2 = KEYBOARD_ROWS[r]?.[c];
|
|
85
|
+
if (key2)
|
|
86
|
+
near.add(key2);
|
|
87
|
+
}
|
|
88
|
+
NEAR.set(key, near);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
export function areNearKeys(first, second) {
|
|
92
|
+
return NEAR.get(first)?.has(second) ?? false;
|
|
93
|
+
}
|
|
94
|
+
export const ALPHABET = "abcçdefgğhıijklmnoöprsştuüvyz";
|
package/package.json
CHANGED
|
@@ -1,6 +1,62 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tinyfix-tr",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Tarayıcıda internetsiz çalışan Türkçe otomatik düzeltme paketi",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"turkish",
|
|
7
|
+
"turkce",
|
|
8
|
+
"autocorrect",
|
|
9
|
+
"spellcheck",
|
|
10
|
+
"offline",
|
|
11
|
+
"browser",
|
|
12
|
+
"nlp"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/imhalid/tinyfix-tr.git",
|
|
18
|
+
"directory": "pkg"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/imhalid/tinyfix-tr#readme",
|
|
21
|
+
"bugs": {
|
|
22
|
+
"url": "https://github.com/imhalid/tinyfix-tr/issues"
|
|
23
|
+
},
|
|
24
|
+
"type": "module",
|
|
25
|
+
"sideEffects": false,
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md",
|
|
29
|
+
"LICENSE"
|
|
30
|
+
],
|
|
31
|
+
"main": "./dist/pkg/src/index.js",
|
|
32
|
+
"types": "./dist/pkg/src/index.d.ts",
|
|
33
|
+
"exports": {
|
|
34
|
+
".": {
|
|
35
|
+
"types": "./dist/pkg/src/index.d.ts",
|
|
36
|
+
"default": "./dist/pkg/src/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./worker": {
|
|
39
|
+
"types": "./dist/pkg/src/worker.d.ts",
|
|
40
|
+
"default": "./dist/pkg/src/worker.js"
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
"scripts": {
|
|
44
|
+
"build": "tsc -p tsconfig.build.json",
|
|
45
|
+
"check": "tsc --noEmit",
|
|
46
|
+
"test": "node --test test/*.test.ts",
|
|
47
|
+
"prepublishOnly": "npm run build && npm test"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"onnxruntime-web": "^1.20.1"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"@types/node": "^22.10.0",
|
|
54
|
+
"typescript": "^5.8.0"
|
|
55
|
+
},
|
|
56
|
+
"engines": {
|
|
57
|
+
"node": ">=22"
|
|
58
|
+
},
|
|
59
|
+
"publishConfig": {
|
|
60
|
+
"access": "public"
|
|
61
|
+
}
|
|
62
|
+
}
|