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,126 @@
|
|
|
1
|
+
/** Words that are written apart from the word before them and follow its vowels. */
|
|
2
|
+
export declare const QUESTION: RegExp;
|
|
3
|
+
export declare const ALSO: RegExp;
|
|
4
|
+
/**
|
|
5
|
+
* Stems a locative can't attach to directly, so "-da/-de" after them must be the separate word "da/de".
|
|
6
|
+
* Used as fallback when morphology is not loaded or when a stem is outside the morphology dictionary.
|
|
7
|
+
*/
|
|
8
|
+
export declare const NO_LOCATIVE_AFTER: RegExp;
|
|
9
|
+
/**
|
|
10
|
+
* Unambiguous non-noun-root endings for OOV stems outside the morphology dictionary (e.g. "subtropiklerdede").
|
|
11
|
+
* Excludes bare "-da/-de/-sa/-se" so OOV compound nouns ("mikromaddede", "multisitede") are not over-split.
|
|
12
|
+
*/
|
|
13
|
+
export declare const STRONG_NO_LOCATIVE_AFTER: RegExp;
|
|
14
|
+
/** Finite verbs and the copula, which "ki" follows as a separate word ("diyor ki", "beceridir ki", "öyle ki"). */
|
|
15
|
+
export declare const FINITE: RegExp;
|
|
16
|
+
/** Never stand alone: splitting these off a word is never a fix ("kmdir", "kitaplar"). */
|
|
17
|
+
export declare const NEVER_ALONE: Set<string>;
|
|
18
|
+
/** Short words that people often write apart from a word they belong with ("hiç bir", "bir çok", "her hangi"). */
|
|
19
|
+
export declare const JOIN_FIRST: Set<string>;
|
|
20
|
+
/** Suffix-like words that belong on the word before when they're the locative or ablative ("ev de" for "evde"). */
|
|
21
|
+
export declare const JOIN_SECOND: Set<string>;
|
|
22
|
+
/** Traditional SOMBAHÇEMİ forms written joined with "ki" (excluding ambiguous/contested forms like "illa ki"). */
|
|
23
|
+
export declare const SOMBAHCEMI_KI: Set<string>;
|
|
24
|
+
/** Function words after which a separate "te/ta" is almost always a devoiced conjunction ("çok ta" -> "çok da") or adverb "ta". */
|
|
25
|
+
export declare const TE_TA_SKIP: Set<string>;
|
|
26
|
+
/**
|
|
27
|
+
* Suffixes accepted by the generic (unseen-form) apostrophe rule after a clear proper name:
|
|
28
|
+
* genitive, locative, ablative, -deki/-daki, instrumental, copula, dative/accusative.
|
|
29
|
+
*/
|
|
30
|
+
export declare const NAME_SUFFIX: RegExp;
|
|
31
|
+
/** Turkish honorific titles that take an apostrophe when following a proper name ("Aclan Bey'in", "Ayşe Hanım'a"). */
|
|
32
|
+
export declare const HONORIFIC_TITLES: Set<string>;
|
|
33
|
+
/**
|
|
34
|
+
* Closed list of TDK geographic, place, landmark, and state head words (mostly P3sg forms) that take an apostrophe
|
|
35
|
+
* when preceded by a capitalized proper name ("Marmara Denizi'nin", "Türkiye Cumhuriyeti'nin", "Kadıköy Mahallesi'nde",
|
|
36
|
+
* "Büyük Okyanus'ta", "Osmanlı Devleti'nin").
|
|
37
|
+
* Institution and organization head words ("Üniversitesi", "Partisi", "Bakanlığı", "Kurumu", ...) are deliberately excluded.
|
|
38
|
+
*/
|
|
39
|
+
export declare const PLACE_APOSTROPHE_HEADS: Set<string>;
|
|
40
|
+
/** Suffixes after a P3sg vowel-final place/state head word (pronominal buffer "n", "y", or copula). */
|
|
41
|
+
export declare const PLACE_P3SG_SUFFIX: RegExp;
|
|
42
|
+
/** True when `stem` is a TDK geographic/place/state head word (plus the explicit TDK exception "Avrupa Birliği"). */
|
|
43
|
+
export declare function isPlaceApostropheHead(stem: string, prevWord?: string): boolean;
|
|
44
|
+
/** Validates a suffix attached with an apostrophe to a TDK place/geographic/state head word. */
|
|
45
|
+
export declare function isValidPlaceApostrophe(stem: string, suffix: string): boolean;
|
|
46
|
+
/**
|
|
47
|
+
* TDK compound verbs that must be written joined across all conjugations (due to vowel drop, consonant doubling,
|
|
48
|
+
* or lexicalization): maps the separate first word to { auxStem, prefix, strictZeroPair? }.
|
|
49
|
+
* E.g. "vaz" + "geçtim" -> "vazgeçtim", "kayıp" + "ediyorum" -> "kaybediyorum", "his" + "ettik" -> "hissettik".
|
|
50
|
+
*/
|
|
51
|
+
export interface CompoundVerbJoinRule {
|
|
52
|
+
readonly auxStem: string;
|
|
53
|
+
readonly prefix: string;
|
|
54
|
+
readonly strictZeroPair?: boolean;
|
|
55
|
+
}
|
|
56
|
+
export declare const COMPOUND_VERB_JOINS: ReadonlyMap<string, readonly CompoundVerbJoinRule[]>;
|
|
57
|
+
/** Stems whose compound with "etmek" undergoes sound change and must be joined, not split ("hisettiniz" -> "hissettiniz"). */
|
|
58
|
+
export declare const JOINED_ETMEK_STEMS: Set<string>;
|
|
59
|
+
/** Three-letter noun stems that productively form separate-written compound verbs with "etmek" per TDK. */
|
|
60
|
+
export declare const SEPARATE_ETMEK_SHORT: Set<string>;
|
|
61
|
+
/** Common stems allowed to split before bare 2-letter imperative "et" ("farket" -> "fark et", "meraket" -> "merak et"). */
|
|
62
|
+
export declare const SEPARATE_ETMEK_BARE_IMPERATIVE: Set<string>;
|
|
63
|
+
/** Standalone month and weekday names take no apostrophe at sentence start ("Ekimde havalar soğur"). */
|
|
64
|
+
export declare const TIME_NAMES_NO_START_APOSTROPHE: Set<string>;
|
|
65
|
+
/** Musical note words/modifiers that guard standalone "mi" from being rewritten to "mı". */
|
|
66
|
+
export declare const MUSIC_NOTES: Set<string>;
|
|
67
|
+
export declare const MUSIC_AFTER: Set<string>;
|
|
68
|
+
export declare function lastVowel(word: string): string | undefined;
|
|
69
|
+
/** True when a two-way (e/a) or four-way (i/ı/u/ü) vowel follows the stem's last vowel. */
|
|
70
|
+
export declare function followsHarmony(stem: string, vowel: string): boolean;
|
|
71
|
+
/** "misiniz", "mıydı" and "müsün" keep one high vowel throughout; "misın" doesn't exist. */
|
|
72
|
+
export declare function sameHighVowels(particle: string): boolean;
|
|
73
|
+
/** True when a lowercase word ends in a Turkish voiceless consonant (f, s, t, k, ç, ş, h, p). */
|
|
74
|
+
export declare function isVoicelessFinal(word: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Stems that do not take an apostrophe by TDK rules in generic/boosted inference:
|
|
77
|
+
* - possessive-ending institution/place stems ("Cumhuriyetinde", "Bakanlığından"),
|
|
78
|
+
* - plural stems and inflected plurals ("Türklerin", "Müslümanlara", "Japonların", "Yunanlardan"),
|
|
79
|
+
* - long derivational language/manner stems in -ca/-ce/-ça/-çe and their inflections ("Hırvatçadan", "Türkçeden").
|
|
80
|
+
*/
|
|
81
|
+
export declare function hasBlockedApostropheStem(stem: string, skipBareCa?: boolean, allowPlaceHead?: boolean): boolean;
|
|
82
|
+
/**
|
|
83
|
+
* Phonological and TDK checks for attaching an unseen suffix to a proper name with an apostrophe.
|
|
84
|
+
* Prevents impossible Turkish splits like "Ankara'in", "Mark'ya", "Zeynep'den", or "Müslümanlar'a".
|
|
85
|
+
*/
|
|
86
|
+
export declare function isValidGenericApostrophe(stem: string, suffix: string, skipBareCa?: boolean): boolean;
|
|
87
|
+
/** Matches an all-caps acronym or mixed-case tech/brand name ending in 2+ uppercase letters glued to a Turkish suffix ("HEXIMden", "MacOSdaki"). */
|
|
88
|
+
export declare function matchAcronymApostrophe(typed: string): {
|
|
89
|
+
prefix: string;
|
|
90
|
+
suffix: string;
|
|
91
|
+
withMark: string;
|
|
92
|
+
} | null;
|
|
93
|
+
/**
|
|
94
|
+
* Guards stem-suffixation of multi-word particle rules in KnownMisspellings ("kimmi -> kim mi", "yada -> ya da"):
|
|
95
|
+
* - Rules ending in "de", "da", "ki" must never absorb trailing letters ("yadacı" is not "ya dacı").
|
|
96
|
+
* - Rules ending in "mi/mı/mu/mü" may only absorb suffixes that keep the last word a valid harmonized question particle
|
|
97
|
+
* ("varmısın" -> "var mısın" is valid; "kimmiş" -> "kim miş" and "varmış" -> "var mış" are blocked).
|
|
98
|
+
*/
|
|
99
|
+
export declare function isValidKnownParticleSuffix(baseRight: string, suffix: string): boolean;
|
|
100
|
+
/**
|
|
101
|
+
* True when every vowel altered inside an apostrophe suffix ("i" -> "ı", "u" -> "ü", "o" -> "ö")
|
|
102
|
+
* harmonizes with the preceding vowel (starting from the resulting stem's last vowel).
|
|
103
|
+
* Blocks disharmonious changes like "Mortimer'i" -> "Mortimer'ı" while keeping "Ravenna'nin" -> "Ravenna'nın".
|
|
104
|
+
*/
|
|
105
|
+
export declare function isHarmoniousApostropheMarkChange(formStem: string, wordSuffix: string, formSuffix: string, isInverseStem?: boolean): boolean;
|
|
106
|
+
/**
|
|
107
|
+
* Detects a doubled-locative typo around the plural suffix ("bölgedelerde" for "bölgelerde",
|
|
108
|
+
* "alandalarda" for "alanlarda"): returns the collapsed locative plural form when the pattern matches.
|
|
109
|
+
*/
|
|
110
|
+
export declare function collapsedDoubledLocative(first: string, second: string): string | null;
|
|
111
|
+
/**
|
|
112
|
+
* Restores unambiguous internal back-vowel disharmony inside an apostrophe suffix typed without Turkish marks:
|
|
113
|
+
* e.g. "ukrayna'sinda" -> "ukrayna'sında", "ankara'sindaki" -> "ankara'sındaki", "kda'larin" -> "kda'ların".
|
|
114
|
+
* Never alters a trailing "-ki" and never guesses harmony from an unseen foreign stem.
|
|
115
|
+
*/
|
|
116
|
+
export declare function fixDisharmoniousApostropheSuffix(word: string): string | null;
|
|
117
|
+
/**
|
|
118
|
+
* Restores missing Turkish marks ("i" -> "ı", "u" -> "ü") on a standalone question particle ("mi", "mu", "misin", ...)
|
|
119
|
+
* in an ASCII-typed sentence using the preceding word's vowel harmony (respecting inverse-harmony loanwords like "saat", "alkol").
|
|
120
|
+
*/
|
|
121
|
+
export declare function harmonizeQuestionParticle(word: string, prevWord: string, isInverseHarmony: boolean): string | null;
|
|
122
|
+
/**
|
|
123
|
+
* "ol-" used as a helper verb after a participle ("yardım ediyor oluyorduk", "gelmiş olacak", "gidecek olursa"):
|
|
124
|
+
* here it is never "öl-", however common "ölüyorduk" is on its own.
|
|
125
|
+
*/
|
|
126
|
+
export declare function isAuxiliaryOl(prevWord: string, word: string, replacement: string): boolean;
|
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
import { lowerTr } from "../turkish.js";
|
|
2
|
+
/** Words that are written apart from the word before them and follow its vowels. */
|
|
3
|
+
export const QUESTION = /^(m[iıuü])(y?[iıuü]m|s[iıuü]n|y?[iıuü]z|s[iıuü]n[iıuü]z|d[iıuü]r|d[iıuü]|ym[iıuü]ş|ys[ae]|yd[iıuü]|yken)?$/;
|
|
4
|
+
export const ALSO = /^(d[ae])$/;
|
|
5
|
+
/**
|
|
6
|
+
* Stems a locative can't attach to directly, so "-da/-de" after them must be the separate word "da/de".
|
|
7
|
+
* Used as fallback when morphology is not loaded or when a stem is outside the morphology dictionary.
|
|
8
|
+
*/
|
|
9
|
+
export const NO_LOCATIVE_AFTER = /(s[ıiuü]|s[ıiuü]n[aeıiuü]|l[ae]r[ıi]n[aeıiuü]|l[ae]r[ae]|m[ae]y[ıi]|yl[ae]|s[ae]l[ae]r|[ıiuü]ğ[ıiuü]|[dt][ae]|n[ıiuü]n|yor|m[ıiuü]ş|[ae]c[ae]k|[dt][ıiuü]|[dt][ıiuü]r|[dt][ıiuü]k|s[ae]|m[ae]l[ıi])$/;
|
|
10
|
+
/**
|
|
11
|
+
* Unambiguous non-noun-root endings for OOV stems outside the morphology dictionary (e.g. "subtropiklerdede").
|
|
12
|
+
* Excludes bare "-da/-de/-sa/-se" so OOV compound nouns ("mikromaddede", "multisitede") are not over-split.
|
|
13
|
+
*/
|
|
14
|
+
export const STRONG_NO_LOCATIVE_AFTER = /(?:l[ae]rd[ae]|[ıiuü]nd[ae]|s[ıiuü]nd[ae]|s[ıiuü]n[aeıiuü]|l[ae]r[ıi]n[aeıiuü]|l[ae]r[ıi]|l[ae]r[ae]|m[ae]y[ıi]|yl[ae]|s[ae]l[ae]r|[ıiuü]ğ[ıiuü]|yor|m[ıiuü]ş|[ae]c[ae]k|m[ae]l[ıi])$/;
|
|
15
|
+
/** Finite verbs and the copula, which "ki" follows as a separate word ("diyor ki", "beceridir ki", "öyle ki"). */
|
|
16
|
+
export const FINITE = /(yor(?:um|sun|uz|sunuz|lar|du)?|m[ıiuü]ş(?:t[ıiuü]r)?|[ae]c[ae]k|[dt][ıiuü]|[dt][ıiuü]r|[dt][ıiuü]k|[dt][ıiuü]m|[dt][ıiuü]n|m[ae]l[ıi]|s[ae]|[ae]r(?:[ıi]m|l[ae]r)?|[ıiuü]r(?:[ıiuü]m|l[ae]r)?|öyle|böyle|şöyle)$/;
|
|
17
|
+
/** Never stand alone: splitting these off a word is never a fix ("kmdir", "kitaplar"). */
|
|
18
|
+
export const NEVER_ALONE = new Set([
|
|
19
|
+
"dir", "dır", "dur", "dür", "tir", "tır", "tur", "tür",
|
|
20
|
+
"ler", "lar", "dı", "di", "du", "dü", "ti", "tı", "tu", "tü",
|
|
21
|
+
"in", "ın", "un", "ün", "e", "a", "i", "ı", "u", "ü", "le", "la",
|
|
22
|
+
]);
|
|
23
|
+
/** Short words that people often write apart from a word they belong with ("hiç bir", "bir çok", "her hangi"). */
|
|
24
|
+
export const JOIN_FIRST = new Set([
|
|
25
|
+
"bir", "her", "hiç", "ya", "hep", "kimi", "öbür", "birbiri",
|
|
26
|
+
"halbu", "oysa", "madem", "sanki", "meğer",
|
|
27
|
+
]);
|
|
28
|
+
/** Suffix-like words that belong on the word before when they're the locative or ablative ("ev de" for "evde"). */
|
|
29
|
+
export const JOIN_SECOND = new Set([
|
|
30
|
+
"de", "da", "te", "ta", "den", "dan", "ten", "tan",
|
|
31
|
+
"ki", "deki", "daki", "teki", "taki",
|
|
32
|
+
]);
|
|
33
|
+
/** Traditional SOMBAHÇEMİ forms written joined with "ki" (excluding ambiguous/contested forms like "illa ki"). */
|
|
34
|
+
export const SOMBAHCEMI_KI = new Set(["oysa", "halbu", "madem", "meğer"]);
|
|
35
|
+
/** Function words after which a separate "te/ta" is almost always a devoiced conjunction ("çok ta" -> "çok da") or adverb "ta". */
|
|
36
|
+
export const TE_TA_SKIP = new Set([
|
|
37
|
+
"çok", "yok", "pek", "hiç", "hep", "artık", "ancak", "fakat",
|
|
38
|
+
"hem", "daha", "bile", "yine", "gene", "ve", "ama", "çünkü", "da", "de",
|
|
39
|
+
]);
|
|
40
|
+
/**
|
|
41
|
+
* Suffixes accepted by the generic (unseen-form) apostrophe rule after a clear proper name:
|
|
42
|
+
* genitive, locative, ablative, -deki/-daki, instrumental, copula, dative/accusative.
|
|
43
|
+
*/
|
|
44
|
+
export const NAME_SUFFIX = /^(?:n?[ıiuü]n|[dt][ae]|[dt][ae]n|[dt][ae]ki|y?l[ae]|[dt][ıiuü]r|y?[aeıiuü]|yd[ıiuü]|ym[ıiuü]ş)$/;
|
|
45
|
+
/** Suffixes accepted after an all-caps acronym ("HEXIM'den", "KDA'ların", "TLS'nin"). Always 2+ letters to avoid English "-s". */
|
|
46
|
+
const ACRONYM_SUFFIX = /^(?:l[ae]r(?:[ıiuü]n|[dt][ae]n?|[dt][ae]ki|l[ae]|[aeıiuü])?|n?[ıiuü]n|[dt][ae]n?|[dt][ae]ki|y?l[ae]|y[aeıiuü]|[dt][ıiuü]r)$/;
|
|
47
|
+
const ACRONYM_WORD = /^([A-ZÇĞİÖŞÜa-zçğıöşü]*[A-ZÇĞİÖŞÜ]{2,})([a-zçğıöşü]{2,})$/;
|
|
48
|
+
/** Turkish honorific titles that take an apostrophe when following a proper name ("Aclan Bey'in", "Ayşe Hanım'a"). */
|
|
49
|
+
export const HONORIFIC_TITLES = new Set(["bey", "hanım", "paşa", "efendi", "ağa"]);
|
|
50
|
+
/**
|
|
51
|
+
* Closed list of TDK geographic, place, landmark, and state head words (mostly P3sg forms) that take an apostrophe
|
|
52
|
+
* when preceded by a capitalized proper name ("Marmara Denizi'nin", "Türkiye Cumhuriyeti'nin", "Kadıköy Mahallesi'nde",
|
|
53
|
+
* "Büyük Okyanus'ta", "Osmanlı Devleti'nin").
|
|
54
|
+
* Institution and organization head words ("Üniversitesi", "Partisi", "Bakanlığı", "Kurumu", ...) are deliberately excluded.
|
|
55
|
+
*/
|
|
56
|
+
export const PLACE_APOSTROPHE_HEADS = new Set([
|
|
57
|
+
// Water bodies & coastal geography
|
|
58
|
+
"denizi", "okyanusu", "okyanus", "gölü", "nehri", "ırmağı", "çayı", "deresi",
|
|
59
|
+
"boğazı", "körfezi", "kanalı", "şelalesi", "adası", "yarımadası", "takımadası",
|
|
60
|
+
// Landforms
|
|
61
|
+
"dağı", "ovası", "yaylası", "platosu", "vadisi", "kanyonu", "çölü", "ormanı",
|
|
62
|
+
"mağarası", "havzası", "kıtası",
|
|
63
|
+
// Urban & administrative places
|
|
64
|
+
"mahallesi", "caddesi", "sokağı", "bulvarı", "meydanı",
|
|
65
|
+
"eyaleti", "oblastı", "bölgesi",
|
|
66
|
+
// Historical landmarks
|
|
67
|
+
"sarayı", "kalesi", "köprüsü", "kulesi",
|
|
68
|
+
// States & polities
|
|
69
|
+
"cumhuriyeti", "devleti", "imparatorluğu", "krallığı", "prensliği",
|
|
70
|
+
]);
|
|
71
|
+
/** Suffixes after a P3sg vowel-final place/state head word (pronominal buffer "n", "y", or copula). */
|
|
72
|
+
export const PLACE_P3SG_SUFFIX = /^(?:n[ıiuü]n|nd[ae]n?|nd[ae]ki|n[aeıiuü]|yl[ae]|[dt][ıiuü]r|yd[ıiuü]|ym[ıiuü]ş)$/;
|
|
73
|
+
/** True when `stem` is a TDK geographic/place/state head word (plus the explicit TDK exception "Avrupa Birliği"). */
|
|
74
|
+
export function isPlaceApostropheHead(stem, prevWord) {
|
|
75
|
+
return PLACE_APOSTROPHE_HEADS.has(stem) || (stem === "birliği" && prevWord === "avrupa");
|
|
76
|
+
}
|
|
77
|
+
/** Validates a suffix attached with an apostrophe to a TDK place/geographic/state head word. */
|
|
78
|
+
export function isValidPlaceApostrophe(stem, suffix) {
|
|
79
|
+
const vowelFinal = /[aeıioöuüâîû]$/.test(stem);
|
|
80
|
+
if (vowelFinal) {
|
|
81
|
+
if (!PLACE_P3SG_SUFFIX.test(suffix))
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
if (!NAME_SUFFIX.test(suffix))
|
|
86
|
+
return false;
|
|
87
|
+
if (/^(?:n[ıiuü]n|y)/.test(suffix))
|
|
88
|
+
return false;
|
|
89
|
+
if (suffix.startsWith("d") && isVoicelessFinal(stem))
|
|
90
|
+
return false;
|
|
91
|
+
if (suffix.startsWith("t") && !isVoicelessFinal(stem))
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
const firstVowel = [...suffix].find((ch) => "aeıioöuü".includes(ch));
|
|
95
|
+
if (firstVowel && !followsHarmony(stem, firstVowel))
|
|
96
|
+
return false;
|
|
97
|
+
return true;
|
|
98
|
+
}
|
|
99
|
+
export const COMPOUND_VERB_JOINS = new Map([
|
|
100
|
+
["vaz", [{ auxStem: "geç", prefix: "vaz" }]],
|
|
101
|
+
["baş", [{ auxStem: "vur", prefix: "baş", strictZeroPair: true }]],
|
|
102
|
+
["var", [{ auxStem: "say", prefix: "var", strictZeroPair: true }]],
|
|
103
|
+
["ön", [{ auxStem: "gör", prefix: "ön", strictZeroPair: true }]],
|
|
104
|
+
["alı", [{ auxStem: "koy", prefix: "alı" }]],
|
|
105
|
+
["devir", [{ auxStem: "al", prefix: "devr" }, { auxStem: "et", prefix: "devr" }]],
|
|
106
|
+
["af", [{ auxStem: "et", prefix: "aff" }]],
|
|
107
|
+
["his", [{ auxStem: "et", prefix: "hiss" }]],
|
|
108
|
+
["red", [{ auxStem: "et", prefix: "redd" }]],
|
|
109
|
+
["ret", [{ auxStem: "et", prefix: "redd" }]],
|
|
110
|
+
["hal", [{ auxStem: "et", prefix: "hall" }]],
|
|
111
|
+
["zan", [{ auxStem: "et", prefix: "zann" }]],
|
|
112
|
+
["kayıp", [{ auxStem: "et", prefix: "kayb" }, { auxStem: "ol", prefix: "kayb" }]],
|
|
113
|
+
["kayıt", [{ auxStem: "et", prefix: "kayd" }, { auxStem: "ol", prefix: "kayd" }]],
|
|
114
|
+
["seyir", [{ auxStem: "et", prefix: "seyr" }]],
|
|
115
|
+
["emir", [{ auxStem: "et", prefix: "emr" }]],
|
|
116
|
+
["hapis", [{ auxStem: "et", prefix: "haps" }]],
|
|
117
|
+
["nakil", [{ auxStem: "et", prefix: "nakl" }]],
|
|
118
|
+
["keşif", [{ auxStem: "et", prefix: "keşf" }]],
|
|
119
|
+
["sabır", [{ auxStem: "et", prefix: "sabr" }]],
|
|
120
|
+
["şükür", [{ auxStem: "et", prefix: "şükr" }]],
|
|
121
|
+
["bahis", [{ auxStem: "et", prefix: "bahs" }]],
|
|
122
|
+
["fetih", [{ auxStem: "et", prefix: "feth" }]],
|
|
123
|
+
["mahv", [{ auxStem: "et", prefix: "mahv" }, { auxStem: "ol", prefix: "mahv" }]],
|
|
124
|
+
["vaat", [{ auxStem: "et", prefix: "vad" }]],
|
|
125
|
+
["def", [{ auxStem: "et", prefix: "def" }]],
|
|
126
|
+
["men", [{ auxStem: "et", prefix: "men" }]],
|
|
127
|
+
]);
|
|
128
|
+
/** Stems whose compound with "etmek" undergoes sound change and must be joined, not split ("hisettiniz" -> "hissettiniz"). */
|
|
129
|
+
export const JOINED_ETMEK_STEMS = new Set([
|
|
130
|
+
"af", "his", "red", "ret", "hal", "zan", "kayıp", "kayıt", "seyir", "emir",
|
|
131
|
+
"hapis", "nakil", "keşif", "devir", "sabır", "şükür", "bahis", "fetih", "mahv", "vaat", "def", "men", "kat",
|
|
132
|
+
]);
|
|
133
|
+
/** Three-letter noun stems that productively form separate-written compound verbs with "etmek" per TDK. */
|
|
134
|
+
export const SEPARATE_ETMEK_SHORT = new Set(["hak", "arz", "yok", "söz", "not", "göç", "alt"]);
|
|
135
|
+
/** Common stems allowed to split before bare 2-letter imperative "et" ("farket" -> "fark et", "meraket" -> "merak et"). */
|
|
136
|
+
export const SEPARATE_ETMEK_BARE_IMPERATIVE = new Set([
|
|
137
|
+
"fark", "terk", "hak", "park", "devam", "dikkat", "merak", "kabul", "iptal", "kontrol", "takip", "yardım", "rica", "teşekkür",
|
|
138
|
+
]);
|
|
139
|
+
/** Standalone month and weekday names take no apostrophe at sentence start ("Ekimde havalar soğur"). */
|
|
140
|
+
export const TIME_NAMES_NO_START_APOSTROPHE = new Set([
|
|
141
|
+
"ocak", "şubat", "mart", "nisan", "mayıs", "haziran",
|
|
142
|
+
"temmuz", "ağustos", "eylül", "ekim", "kasım", "aralık",
|
|
143
|
+
"pazartesi", "salı", "çarşamba", "perşembe", "cuma", "cumartesi", "pazar",
|
|
144
|
+
]);
|
|
145
|
+
/** Musical note words/modifiers that guard standalone "mi" from being rewritten to "mı". */
|
|
146
|
+
export const MUSIC_NOTES = new Set(["do", "re", "mi", "fa", "sol", "la", "si"]);
|
|
147
|
+
export const MUSIC_AFTER = new Set([
|
|
148
|
+
"majör", "minör", "major", "minor", "bemol", "diyez",
|
|
149
|
+
"notası", "notasi", "anahtarı", "anahtari",
|
|
150
|
+
]);
|
|
151
|
+
const BACK = new Set(["a", "ı", "o", "u", "â", "û"]);
|
|
152
|
+
const FRONT = new Set(["e", "i", "ö", "ü", "î"]);
|
|
153
|
+
const ROUND = new Set(["o", "u", "ö", "ü", "û"]);
|
|
154
|
+
export function lastVowel(word) {
|
|
155
|
+
for (let index = word.length - 1; index >= 0; index--) {
|
|
156
|
+
const char = word[index];
|
|
157
|
+
if (BACK.has(char) || FRONT.has(char))
|
|
158
|
+
return char;
|
|
159
|
+
}
|
|
160
|
+
return undefined;
|
|
161
|
+
}
|
|
162
|
+
/** True when a two-way (e/a) or four-way (i/ı/u/ü) vowel follows the stem's last vowel. */
|
|
163
|
+
export function followsHarmony(stem, vowel) {
|
|
164
|
+
const last = lastVowel(stem);
|
|
165
|
+
if (!last)
|
|
166
|
+
return true;
|
|
167
|
+
const back = BACK.has(last);
|
|
168
|
+
if (vowel === "a" || vowel === "e")
|
|
169
|
+
return back === (vowel === "a");
|
|
170
|
+
const round = ROUND.has(last);
|
|
171
|
+
const want = back ? (round ? "u" : "ı") : round ? "ü" : "i";
|
|
172
|
+
return vowel === want;
|
|
173
|
+
}
|
|
174
|
+
/** "misiniz", "mıydı" and "müsün" keep one high vowel throughout; "misın" doesn't exist. */
|
|
175
|
+
export function sameHighVowels(particle) {
|
|
176
|
+
const high = [...particle].filter((char) => "ıiuü".includes(char));
|
|
177
|
+
return high.every((char) => char === high[0]);
|
|
178
|
+
}
|
|
179
|
+
/** True when a lowercase word ends in a Turkish voiceless consonant (f, s, t, k, ç, ş, h, p). */
|
|
180
|
+
export function isVoicelessFinal(word) {
|
|
181
|
+
return /[fstkçşhp]$/.test(word);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Stems that do not take an apostrophe by TDK rules in generic/boosted inference:
|
|
185
|
+
* - possessive-ending institution/place stems ("Cumhuriyetinde", "Bakanlığından"),
|
|
186
|
+
* - plural stems and inflected plurals ("Türklerin", "Müslümanlara", "Japonların", "Yunanlardan"),
|
|
187
|
+
* - long derivational language/manner stems in -ca/-ce/-ça/-çe and their inflections ("Hırvatçadan", "Türkçeden").
|
|
188
|
+
*/
|
|
189
|
+
export function hasBlockedApostropheStem(stem, skipBareCa = false, allowPlaceHead = false) {
|
|
190
|
+
if (!allowPlaceHead && /[^aeıioöuü](s?[ıiuü])$/.test(stem))
|
|
191
|
+
return true;
|
|
192
|
+
if (/l[ae]r$/.test(stem))
|
|
193
|
+
return true;
|
|
194
|
+
if (/[aıouâû][^aeıioöuü]*lar(?:ın(?:dan?|a|ı)?|ıyla|dan?|a|la)$/.test(stem))
|
|
195
|
+
return true;
|
|
196
|
+
if (/[eiöüî][^aeıioöuü]*ler(?:in(?:den?|e|i)?|iyle|den?|e|le)$/.test(stem))
|
|
197
|
+
return true;
|
|
198
|
+
if (!skipBareCa && stem.length >= 6 && /[cç][ae]$/.test(stem))
|
|
199
|
+
return true;
|
|
200
|
+
if (stem.length >= 8 && /[cç][ae](?:d[ae]n?|n[ıi]n|y[aeıi]|yl[ae])$/.test(stem))
|
|
201
|
+
return true;
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Phonological and TDK checks for attaching an unseen suffix to a proper name with an apostrophe.
|
|
206
|
+
* Prevents impossible Turkish splits like "Ankara'in", "Mark'ya", "Zeynep'den", or "Müslümanlar'a".
|
|
207
|
+
*/
|
|
208
|
+
export function isValidGenericApostrophe(stem, suffix, skipBareCa = false) {
|
|
209
|
+
if (!NAME_SUFFIX.test(suffix))
|
|
210
|
+
return false;
|
|
211
|
+
if (hasBlockedApostropheStem(stem, skipBareCa))
|
|
212
|
+
return false;
|
|
213
|
+
// Buffer "n" (genitive -nın/-nin/-nun/-nün) and buffer "y" (-ya/-ye/-yı/-yle/-ydı/-ymış) follow a vowel or "y".
|
|
214
|
+
if (/^(?:n[ıiuü]n|y)/.test(suffix) && !/[aeıioöuüâîûy]$/.test(stem))
|
|
215
|
+
return false;
|
|
216
|
+
// Vowel-initial suffixes follow a consonant (or a silent final "-e" in foreign names like "Google'ın", "Blake'i").
|
|
217
|
+
if (/^[aeıiuü]/.test(suffix) && /[aıioöuüâîû]$/.test(stem))
|
|
218
|
+
return false;
|
|
219
|
+
// Locative/ablative/copula voicing harmony: voiceless final takes "t-", voiced/vowel final takes "d-".
|
|
220
|
+
if (suffix.startsWith("d") && isVoicelessFinal(stem))
|
|
221
|
+
return false;
|
|
222
|
+
if (suffix.startsWith("t") && !/[fstkçşhpcx]$/.test(stem))
|
|
223
|
+
return false;
|
|
224
|
+
return true;
|
|
225
|
+
}
|
|
226
|
+
/** Matches an all-caps acronym or mixed-case tech/brand name ending in 2+ uppercase letters glued to a Turkish suffix ("HEXIMden", "MacOSdaki"). */
|
|
227
|
+
export function matchAcronymApostrophe(typed) {
|
|
228
|
+
const match = ACRONYM_WORD.exec(typed);
|
|
229
|
+
if (!match)
|
|
230
|
+
return null;
|
|
231
|
+
const prefix = match[1];
|
|
232
|
+
const suffix = match[2];
|
|
233
|
+
if (prefix.length < 3 || !ACRONYM_SUFFIX.test(suffix))
|
|
234
|
+
return null;
|
|
235
|
+
return { prefix, suffix, withMark: `${lowerTr(prefix)}'${suffix}` };
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Guards stem-suffixation of multi-word particle rules in KnownMisspellings ("kimmi -> kim mi", "yada -> ya da"):
|
|
239
|
+
* - Rules ending in "de", "da", "ki" must never absorb trailing letters ("yadacı" is not "ya dacı").
|
|
240
|
+
* - Rules ending in "mi/mı/mu/mü" may only absorb suffixes that keep the last word a valid harmonized question particle
|
|
241
|
+
* ("varmısın" -> "var mısın" is valid; "kimmiş" -> "kim miş" and "varmış" -> "var mış" are blocked).
|
|
242
|
+
*/
|
|
243
|
+
export function isValidKnownParticleSuffix(baseRight, suffix) {
|
|
244
|
+
const space = baseRight.lastIndexOf(" ");
|
|
245
|
+
if (space === -1)
|
|
246
|
+
return true;
|
|
247
|
+
const baseLast = baseRight.slice(space + 1);
|
|
248
|
+
if (baseLast === "de" || baseLast === "da" || baseLast === "ki")
|
|
249
|
+
return false;
|
|
250
|
+
if (/^m[iıuü]$/.test(baseLast)) {
|
|
251
|
+
const combined = baseLast + suffix;
|
|
252
|
+
return QUESTION.test(combined) && sameHighVowels(combined);
|
|
253
|
+
}
|
|
254
|
+
return true;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* True when every vowel altered inside an apostrophe suffix ("i" -> "ı", "u" -> "ü", "o" -> "ö")
|
|
258
|
+
* harmonizes with the preceding vowel (starting from the resulting stem's last vowel).
|
|
259
|
+
* Blocks disharmonious changes like "Mortimer'i" -> "Mortimer'ı" while keeping "Ravenna'nin" -> "Ravenna'nın".
|
|
260
|
+
*/
|
|
261
|
+
export function isHarmoniousApostropheMarkChange(formStem, wordSuffix, formSuffix, isInverseStem = false) {
|
|
262
|
+
if (wordSuffix === formSuffix || wordSuffix.length !== formSuffix.length)
|
|
263
|
+
return true;
|
|
264
|
+
for (let i = 0; i < formSuffix.length; i++) {
|
|
265
|
+
const before = wordSuffix[i];
|
|
266
|
+
const after = formSuffix[i];
|
|
267
|
+
if (before === undefined || after === undefined || before === after)
|
|
268
|
+
continue;
|
|
269
|
+
if (!BACK.has(after) && !FRONT.has(after))
|
|
270
|
+
continue;
|
|
271
|
+
const suffixVowel = lastVowel(formSuffix.slice(0, i));
|
|
272
|
+
let prev;
|
|
273
|
+
let inverse = false;
|
|
274
|
+
if (suffixVowel) {
|
|
275
|
+
prev = suffixVowel;
|
|
276
|
+
}
|
|
277
|
+
else if (/[^aeıioöuüâîû]y$/.test(formStem)) {
|
|
278
|
+
// Final syllabic "-y" in foreign names ("Mary", "Tony", "Lucy", "Murphy") is pronounced as front "/i/".
|
|
279
|
+
prev = "i";
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
prev = lastVowel(formStem);
|
|
283
|
+
inverse = isInverseStem;
|
|
284
|
+
}
|
|
285
|
+
if (!prev)
|
|
286
|
+
continue;
|
|
287
|
+
const back = !inverse && BACK.has(prev);
|
|
288
|
+
if (after === "o" || after === "ö") {
|
|
289
|
+
if (back !== (after === "o"))
|
|
290
|
+
return false;
|
|
291
|
+
continue;
|
|
292
|
+
}
|
|
293
|
+
const round = ROUND.has(prev);
|
|
294
|
+
const want = back ? (round ? "u" : "ı") : round ? "ü" : "i";
|
|
295
|
+
if (after !== want)
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
return true;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Detects a doubled-locative typo around the plural suffix ("bölgedelerde" for "bölgelerde",
|
|
302
|
+
* "alandalarda" for "alanlarda"): returns the collapsed locative plural form when the pattern matches.
|
|
303
|
+
*/
|
|
304
|
+
export function collapsedDoubledLocative(first, second) {
|
|
305
|
+
if (second === "de" && /[dt]eler$/.test(first) && first.length >= 7) {
|
|
306
|
+
return `${first.slice(0, -5)}lerde`;
|
|
307
|
+
}
|
|
308
|
+
if (second === "da" && /[dt]alar$/.test(first) && first.length >= 7) {
|
|
309
|
+
return `${first.slice(0, -5)}larda`;
|
|
310
|
+
}
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
const VALID_APOSTROPHE_BACK_SUFFIX = /^(?:(?:lar)?(?:s?ı)?(?:n?ın|n?[dt]an?|n?[dt]aki|n?a|n?ı|y?la)|y[aı])$/;
|
|
314
|
+
/**
|
|
315
|
+
* Restores unambiguous internal back-vowel disharmony inside an apostrophe suffix typed without Turkish marks:
|
|
316
|
+
* e.g. "ukrayna'sinda" -> "ukrayna'sında", "ankara'sindaki" -> "ankara'sındaki", "kda'larin" -> "kda'ların".
|
|
317
|
+
* Never alters a trailing "-ki" and never guesses harmony from an unseen foreign stem.
|
|
318
|
+
*/
|
|
319
|
+
export function fixDisharmoniousApostropheSuffix(word) {
|
|
320
|
+
const quote = word.indexOf("'");
|
|
321
|
+
if (quote < 2 || quote !== word.lastIndexOf("'"))
|
|
322
|
+
return null;
|
|
323
|
+
const stem = word.slice(0, quote);
|
|
324
|
+
const suffix = word.slice(quote + 1);
|
|
325
|
+
const keepKi = suffix.endsWith("ki");
|
|
326
|
+
const core = keepKi ? suffix.slice(0, -2) : suffix;
|
|
327
|
+
if (!core.includes("a") || !core.includes("i"))
|
|
328
|
+
return null;
|
|
329
|
+
const fixedSuffix = core.replaceAll("i", "ı") + (keepKi ? "ki" : "");
|
|
330
|
+
if (fixedSuffix === suffix || !VALID_APOSTROPHE_BACK_SUFFIX.test(fixedSuffix))
|
|
331
|
+
return null;
|
|
332
|
+
if (!isHarmoniousApostropheMarkChange(stem, suffix, fixedSuffix))
|
|
333
|
+
return null;
|
|
334
|
+
return `${stem}'${fixedSuffix}`;
|
|
335
|
+
}
|
|
336
|
+
/**
|
|
337
|
+
* Restores missing Turkish marks ("i" -> "ı", "u" -> "ü") on a standalone question particle ("mi", "mu", "misin", ...)
|
|
338
|
+
* in an ASCII-typed sentence using the preceding word's vowel harmony (respecting inverse-harmony loanwords like "saat", "alkol").
|
|
339
|
+
*/
|
|
340
|
+
export function harmonizeQuestionParticle(word, prevWord, isInverseHarmony) {
|
|
341
|
+
const match = QUESTION.exec(word);
|
|
342
|
+
if (!match || !sameHighVowels(word))
|
|
343
|
+
return null;
|
|
344
|
+
const last = lastVowel(prevWord);
|
|
345
|
+
if (!last)
|
|
346
|
+
return null;
|
|
347
|
+
const round = ROUND.has(last);
|
|
348
|
+
const front = isInverseHarmony || FRONT.has(last);
|
|
349
|
+
const want = front ? (round ? "ü" : "i") : round ? "u" : "ı";
|
|
350
|
+
const current = match[1][1];
|
|
351
|
+
if (current === want)
|
|
352
|
+
return null;
|
|
353
|
+
// Only restore missing marks (ASCII -> Turkish); never strip marks or guess across unrelated vowels.
|
|
354
|
+
if (!((current === "i" && want === "ı") || (current === "u" && want === "ü")))
|
|
355
|
+
return null;
|
|
356
|
+
const target = word.replaceAll(current, want);
|
|
357
|
+
return QUESTION.test(target) && sameHighVowels(target) ? target : null;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* "ol-" used as a helper verb after a participle ("yardım ediyor oluyorduk", "gelmiş olacak", "gidecek olursa"):
|
|
361
|
+
* here it is never "öl-", however common "ölüyorduk" is on its own.
|
|
362
|
+
*/
|
|
363
|
+
export function isAuxiliaryOl(prevWord, word, replacement) {
|
|
364
|
+
return /^ol/.test(word) && /^öl/.test(replacement) && /(?:[ıiuü]?yor|m[ıiuü]ş|[ae]c[ae]k)$/.test(prevWord);
|
|
365
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { KnownMisspellings } from "./known.ts";
|
|
2
|
+
/**
|
|
3
|
+
* Sentence punctuation, TDK proper-name capitalization, multi-word phrases, titles, dates,
|
|
4
|
+
* missing spaces after full stops, and apostrophe insertion/removal/relocation.
|
|
5
|
+
*
|
|
6
|
+
* Deliberately conservative on clean text: abbreviations ("Dr.", "vb."), ordinals/decimals
|
|
7
|
+
* ("3. sınıf", "3.5", "09.15'te"), initials ("A."), ellipses ("..."), URLs, emails, and file
|
|
8
|
+
* names are left untouched.
|
|
9
|
+
*/
|
|
10
|
+
/** Minimal shape shared with Corrector's Correction (kind is "punct" for changes made here). */
|
|
11
|
+
export interface SentenceCorrection {
|
|
12
|
+
start: number;
|
|
13
|
+
end: number;
|
|
14
|
+
original: string;
|
|
15
|
+
replacement: string;
|
|
16
|
+
kind: "punct";
|
|
17
|
+
margin: number;
|
|
18
|
+
}
|
|
19
|
+
interface AnyCorrection {
|
|
20
|
+
start: number;
|
|
21
|
+
end: number;
|
|
22
|
+
original: string;
|
|
23
|
+
replacement: string;
|
|
24
|
+
}
|
|
25
|
+
/** An unresolved ambiguous proper-name occurrence passed to an optional core or neural contextual disambiguator. */
|
|
26
|
+
export interface AmbigCandidateQuery {
|
|
27
|
+
readonly start: number;
|
|
28
|
+
readonly end: number;
|
|
29
|
+
readonly base: string;
|
|
30
|
+
readonly displayBase: string;
|
|
31
|
+
readonly suffix: string;
|
|
32
|
+
readonly hadApostrophe: boolean;
|
|
33
|
+
readonly atStart: boolean;
|
|
34
|
+
readonly isGiven: boolean;
|
|
35
|
+
readonly commonCand: string;
|
|
36
|
+
readonly properCand: string;
|
|
37
|
+
readonly leftRaw: string;
|
|
38
|
+
readonly rightRaw: string;
|
|
39
|
+
}
|
|
40
|
+
/** Optional rich lexical/morphological resources supplied by Corrector for full TDK proper-name rules. */
|
|
41
|
+
export interface SentenceResources {
|
|
42
|
+
readonly known?: KnownMisspellings;
|
|
43
|
+
readonly capitalShare?: (lower: string) => number;
|
|
44
|
+
readonly count?: (lower: string) => number;
|
|
45
|
+
readonly pair?: (first: string, second: string) => number;
|
|
46
|
+
readonly isMorphWord?: (lower: string) => boolean;
|
|
47
|
+
/** Optional contextual disambiguator for ambiguous names (core linear model or pre-scored neural context). */
|
|
48
|
+
readonly disambiguateAmbig?: (query: AmbigCandidateQuery) => string | null;
|
|
49
|
+
/** Optional sink populated with every unresolved ambiguous name query (used by Corrector.correctAsync to batch neural scoring). */
|
|
50
|
+
readonly collectAmbig?: AmbigCandidateQuery[];
|
|
51
|
+
}
|
|
52
|
+
export interface SentenceToken {
|
|
53
|
+
readonly start: number;
|
|
54
|
+
readonly end: number;
|
|
55
|
+
readonly raw: string;
|
|
56
|
+
eff: string;
|
|
57
|
+
low: string;
|
|
58
|
+
readonly isWord: boolean;
|
|
59
|
+
readonly isNumber: boolean;
|
|
60
|
+
/** Non-whitespace separator between previous token and this token. */
|
|
61
|
+
readonly sepBefore: string;
|
|
62
|
+
/** Exact raw substring between previous token and this token. */
|
|
63
|
+
readonly gapBefore: string;
|
|
64
|
+
/** Exact raw substring between this token and next token. */
|
|
65
|
+
gapAfter: string;
|
|
66
|
+
readonly atStart: boolean;
|
|
67
|
+
locked: boolean;
|
|
68
|
+
}
|
|
69
|
+
/** Common Turkish (and a few English) abbreviations written with a full stop. */
|
|
70
|
+
export declare const ABBREVIATIONS: Set<string>;
|
|
71
|
+
/** File extensions and top-level domains: "dosya.pdf", "site.com" are not two sentences. */
|
|
72
|
+
export declare const NOT_A_SENTENCE_START: Set<string>;
|
|
73
|
+
/**
|
|
74
|
+
* Checks whether a dot/exclamation/question glued between two letter runs (`left[punct]right`) is a
|
|
75
|
+
* real missing-space sentence boundary (and NOT a domain, filename, abbreviation, or camelCase/address).
|
|
76
|
+
*/
|
|
77
|
+
export declare function isMissingSpaceBoundary(text: string, leftStart: number, left: string, punctAt: number, rightStart: number, right: string, isWordOrFixable: (lower: string) => boolean): boolean;
|
|
78
|
+
/**
|
|
79
|
+
* Adds missing spaces, TDK proper-name capitals, multi-word phrases, titles, dates,
|
|
80
|
+
* apostrophe fixes, and sentence-start capitals to `corrections` (sorted, non-overlapping).
|
|
81
|
+
*/
|
|
82
|
+
export declare function applySentenceRules<T extends AnyCorrection>(text: string, corrections: readonly T[], isWord: (lower: string) => boolean, nameFor?: (lower: string, common?: boolean) => string | undefined, stemsOf?: (lower: string) => readonly string[] | null, resources?: SentenceResources): Array<T | SentenceCorrection>;
|
|
83
|
+
export {};
|