tdk-api-wrapper 1.3.1 → 1.5.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/README.md +52 -15
- package/dist/{chunk-ACMGCL7T.mjs → chunk-7KJHYRJZ.mjs} +1041 -16
- package/dist/cli.js +1205 -21
- package/dist/cli.mjs +219 -7
- package/dist/index.d.mts +206 -1
- package/dist/index.d.ts +206 -1
- package/dist/index.js +1052 -17
- package/dist/index.mjs +23 -3
- package/package.json +3 -2
- package/src/cli.ts +224 -6
- package/src/index.ts +2 -1
- package/src/morphology.ts +324 -0
- package/src/tdk.ts +560 -15
- package/src/types.ts +49 -0
- package/test/grammar.test.js +52 -0
- package/test/morphology.test.js +129 -0
- package/test/proofread.test.js +60 -0
- package/test/tools.test.js +51 -0
package/dist/index.d.ts
CHANGED
|
@@ -95,6 +95,14 @@ interface SpellCheckResult {
|
|
|
95
95
|
isCorrect: boolean;
|
|
96
96
|
word: string;
|
|
97
97
|
suggestion?: string;
|
|
98
|
+
isInflected?: boolean;
|
|
99
|
+
root?: string;
|
|
100
|
+
}
|
|
101
|
+
interface StemResult {
|
|
102
|
+
word: string;
|
|
103
|
+
root: string;
|
|
104
|
+
isInflected: boolean;
|
|
105
|
+
candidates?: string[];
|
|
98
106
|
}
|
|
99
107
|
interface WordOfTheDay {
|
|
100
108
|
word: string;
|
|
@@ -115,6 +123,7 @@ interface WordComparisonSide {
|
|
|
115
123
|
origin: string | null;
|
|
116
124
|
syllables: string[];
|
|
117
125
|
harmony: boolean;
|
|
126
|
+
labialHarmony?: boolean;
|
|
118
127
|
}
|
|
119
128
|
interface WordComparison {
|
|
120
129
|
a: WordComparisonSide;
|
|
@@ -125,6 +134,38 @@ interface WordAnalysis {
|
|
|
125
134
|
found: boolean;
|
|
126
135
|
meaning: string | null;
|
|
127
136
|
origin: string | null;
|
|
137
|
+
root?: string;
|
|
138
|
+
isInflected?: boolean;
|
|
139
|
+
}
|
|
140
|
+
interface ProofreadIssue {
|
|
141
|
+
type: "spelling" | "conjunction_da" | "conjunction_ki" | "question_particle";
|
|
142
|
+
word: string;
|
|
143
|
+
startIndex: number;
|
|
144
|
+
endIndex: number;
|
|
145
|
+
suggestion?: string;
|
|
146
|
+
message: string;
|
|
147
|
+
}
|
|
148
|
+
interface ProofreadResult {
|
|
149
|
+
text: string;
|
|
150
|
+
issues: ProofreadIssue[];
|
|
151
|
+
isCorrect: boolean;
|
|
152
|
+
}
|
|
153
|
+
interface PatternSearchOptions {
|
|
154
|
+
maxResults?: number;
|
|
155
|
+
}
|
|
156
|
+
interface AnagramOptions {
|
|
157
|
+
exactLength?: boolean;
|
|
158
|
+
maxResults?: number;
|
|
159
|
+
}
|
|
160
|
+
interface RhymeOptions {
|
|
161
|
+
minLetters?: number;
|
|
162
|
+
maxResults?: number;
|
|
163
|
+
}
|
|
164
|
+
interface TDKConfig {
|
|
165
|
+
timeoutMs?: number;
|
|
166
|
+
retries?: number;
|
|
167
|
+
cache?: boolean;
|
|
168
|
+
maxCacheSize?: number;
|
|
128
169
|
}
|
|
129
170
|
interface KubbealtiEntry {
|
|
130
171
|
kelime: string;
|
|
@@ -158,10 +199,19 @@ declare class TDK {
|
|
|
158
199
|
* fail-closed contract as the rest of this file's fragile integrations.
|
|
159
200
|
*/
|
|
160
201
|
private static readonly KUBBEALTI_EXTRA_CA;
|
|
202
|
+
private static defaultTimeoutMs;
|
|
203
|
+
private static defaultRetries;
|
|
204
|
+
private static maxCacheSize;
|
|
161
205
|
private static isCacheEnabled;
|
|
162
206
|
private static wordCache;
|
|
163
207
|
private static dailyContentCache;
|
|
164
208
|
private static autocompleteCache;
|
|
209
|
+
private static autocompleteSet;
|
|
210
|
+
private static stemCache;
|
|
211
|
+
/**
|
|
212
|
+
* Configures global client options such as network timeout, retries, and cache size.
|
|
213
|
+
*/
|
|
214
|
+
static configure(config: TDKConfig): void;
|
|
165
215
|
/**
|
|
166
216
|
* Enables or disables in-memory caching for API requests.
|
|
167
217
|
*/
|
|
@@ -170,7 +220,12 @@ declare class TDK {
|
|
|
170
220
|
* Clears the internal cache.
|
|
171
221
|
*/
|
|
172
222
|
static clearCache(): void;
|
|
223
|
+
private static setBoundedCache;
|
|
173
224
|
private static delay;
|
|
225
|
+
/**
|
|
226
|
+
* Internal helper that performs HTTP fetch with timeout and automatic retry on network/5xx errors.
|
|
227
|
+
*/
|
|
228
|
+
private static fetchWithRetry;
|
|
174
229
|
/**
|
|
175
230
|
* Fetches detailed information for a given word from the TDK Dictionary.
|
|
176
231
|
*/
|
|
@@ -191,6 +246,10 @@ declare class TDK {
|
|
|
191
246
|
* this, this fails closed to `[]` rather than throwing.
|
|
192
247
|
*/
|
|
193
248
|
private static fetchAutocompleteData;
|
|
249
|
+
/**
|
|
250
|
+
* Ensures TDK's ~81k headword list is loaded in memory for fast O(1) set operations.
|
|
251
|
+
*/
|
|
252
|
+
private static ensureAutocompleteLoaded;
|
|
194
253
|
/**
|
|
195
254
|
* Returns autocomplete suggestions for a given prefix, searched over TDK's
|
|
196
255
|
* full headword list (see `fetchAutocompleteData`). The list is fetched
|
|
@@ -198,6 +257,27 @@ declare class TDK {
|
|
|
198
257
|
* caching behavior as before — and only cleared by `clearCache()`.
|
|
199
258
|
*/
|
|
200
259
|
static getSuggestions(prefix: string): Promise<string[]>;
|
|
260
|
+
/**
|
|
261
|
+
* Checks whether a word exists as a known headword in TDK dictionary.
|
|
262
|
+
* Checks in-memory autocompleteSet (81k headwords) if loaded, or queries TDK API.
|
|
263
|
+
*/
|
|
264
|
+
static isHeadword(word: string): Promise<boolean>;
|
|
265
|
+
/**
|
|
266
|
+
* Generates candidate roots for a given Turkish word using progressive BFS suffix stripping,
|
|
267
|
+
* consonant mutation restoration, and vowel drop restoration.
|
|
268
|
+
*/
|
|
269
|
+
static getStemCandidates(word: string): string[];
|
|
270
|
+
/**
|
|
271
|
+
* Finds the dictionary root (headword) of a word by checking direct existence
|
|
272
|
+
* and evaluating candidate stems generated by morphological analysis.
|
|
273
|
+
* Returns the root headword string if found, or null if no match in TDK.
|
|
274
|
+
*/
|
|
275
|
+
static findRoot(word: string): Promise<string | null>;
|
|
276
|
+
/**
|
|
277
|
+
* Performs morphological stemming on a Turkish word.
|
|
278
|
+
* Returns a StemResult containing the original word, resolved root, and whether it is inflected.
|
|
279
|
+
*/
|
|
280
|
+
static stem(word: string): Promise<StemResult | null>;
|
|
201
281
|
/**
|
|
202
282
|
* Returns a list of proverbs and idioms containing the word.
|
|
203
283
|
*/
|
|
@@ -434,6 +514,8 @@ declare class TDK {
|
|
|
434
514
|
static getWordsBatch(words: string[]): Promise<WordInfo[][]>;
|
|
435
515
|
/**
|
|
436
516
|
* Syllabicates a Turkish word based on general grammar rules.
|
|
517
|
+
* Handles syllable separation for vowels, single consonants, double consonants,
|
|
518
|
+
* and western loanword three-consonant clusters (e.g. e-lek-trik, kon-trol, or-kes-tra).
|
|
437
519
|
*/
|
|
438
520
|
static syllabicate(word: string): string[];
|
|
439
521
|
/**
|
|
@@ -443,6 +525,65 @@ declare class TDK {
|
|
|
443
525
|
* (dotless) as the front vowel "i" (dotted).
|
|
444
526
|
*/
|
|
445
527
|
static checkVowelHarmony(word: string): boolean;
|
|
528
|
+
/**
|
|
529
|
+
* Checks if a word follows Turkish Minor Vowel Harmony (Küçük Ünlü Uyumu / Labial Harmony).
|
|
530
|
+
* Rules:
|
|
531
|
+
* 1. After an unrounded vowel (a, e, ı, i), only unrounded vowels (a, e, ı, i) can follow.
|
|
532
|
+
* 2. After a rounded vowel (o, ö, u, ü), either an unrounded wide (a, e) or rounded narrow (u, ü) vowel can follow.
|
|
533
|
+
* Single-syllable words and words with <=1 vowel are considered compliant by convention.
|
|
534
|
+
*/
|
|
535
|
+
static checkLabialHarmony(word: string): boolean;
|
|
536
|
+
/**
|
|
537
|
+
* Searches TDK headwords using a wildcard / pattern string.
|
|
538
|
+
* Wildcards:
|
|
539
|
+
* '_' or '?' matches any single character
|
|
540
|
+
* '*' matches zero or more characters
|
|
541
|
+
* Example: "k_l_m" matches "kalem", "kelam", "kilim".
|
|
542
|
+
* Runs in-memory against TDK's 81k headword list.
|
|
543
|
+
*/
|
|
544
|
+
static patternSearch(pattern: string, options?: PatternSearchOptions): Promise<string[]>;
|
|
545
|
+
/**
|
|
546
|
+
* Finds headwords in TDK that can be formed from the given letters (anagrams).
|
|
547
|
+
* If exact-length anagrams exist, they are returned.
|
|
548
|
+
* If none exist (or exactLength is false), valid sub-anagrams (words using a subset of the letters,
|
|
549
|
+
* minimum 3 letters) are returned, sorted by length descending.
|
|
550
|
+
*/
|
|
551
|
+
static findAnagrams(letters: string, options?: AnagramOptions): Promise<string[]>;
|
|
552
|
+
/**
|
|
553
|
+
* Finds words in TDK that rhyme with the given word (sharing the same ending suffix/letters).
|
|
554
|
+
* @param word The target word
|
|
555
|
+
* @param options.minLetters Minimum number of ending characters that must match (default: 3)
|
|
556
|
+
* @param options.maxResults Maximum number of rhyme results to return (default: 50)
|
|
557
|
+
*/
|
|
558
|
+
static findRhymes(word: string, options?: RhymeOptions): Promise<string[]>;
|
|
559
|
+
/**
|
|
560
|
+
* Performs comprehensive spelling, grammar, and syntax proofreading on a Turkish text.
|
|
561
|
+
* Detects:
|
|
562
|
+
* 1. Conjunction 'da/de' erroneously joined to verbs or words (e.g. "gitsende" -> "gitsen de")
|
|
563
|
+
* 2. Conjunction 'ki' erroneously joined to verbs (e.g. "gördümki" -> "gördüm ki"), respecting SOMBAHÇEMİ exceptions
|
|
564
|
+
* 3. Question particle 'mi/mı/mu/mü' erroneously joined to words (e.g. "geldimi" -> "geldi mi")
|
|
565
|
+
* 4. Misspelled words with dictionary suggestions (via edit-distance & morphology)
|
|
566
|
+
*/
|
|
567
|
+
static proofread(text: string): Promise<ProofreadResult>;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Configurable instance-based client for TDK API.
|
|
571
|
+
* Useful for multi-tenant applications or backend services requiring isolated configurations.
|
|
572
|
+
*/
|
|
573
|
+
declare class TDKClient {
|
|
574
|
+
constructor(config?: TDKConfig);
|
|
575
|
+
getWord(word: string): Promise<WordInfo[]>;
|
|
576
|
+
getMeanings(word: string): Promise<string[]>;
|
|
577
|
+
checkSpelling(word: string): Promise<SpellCheckResult>;
|
|
578
|
+
findRoot(word: string): Promise<string | null>;
|
|
579
|
+
stem(word: string): Promise<StemResult | null>;
|
|
580
|
+
proofread(text: string): Promise<ProofreadResult>;
|
|
581
|
+
patternSearch(pattern: string, options?: PatternSearchOptions): Promise<string[]>;
|
|
582
|
+
findAnagrams(letters: string, options?: AnagramOptions): Promise<string[]>;
|
|
583
|
+
findRhymes(word: string, options?: RhymeOptions): Promise<string[]>;
|
|
584
|
+
syllabicate(word: string): string[];
|
|
585
|
+
checkVowelHarmony(word: string): boolean;
|
|
586
|
+
checkLabialHarmony(word: string): boolean;
|
|
446
587
|
}
|
|
447
588
|
|
|
448
589
|
/**
|
|
@@ -470,4 +611,68 @@ declare class TDKNetworkError extends TDKError {
|
|
|
470
611
|
});
|
|
471
612
|
}
|
|
472
613
|
|
|
473
|
-
|
|
614
|
+
/**
|
|
615
|
+
* Turkish Morphology Engine & Stem Candidate Generator.
|
|
616
|
+
*
|
|
617
|
+
* Implements heuristic-based progressive suffix stripping (BFS) with:
|
|
618
|
+
* 1. Comprehensive Turkish suffix catalogue (inflectional, derivational, composite)
|
|
619
|
+
* 2. Reverse consonant mutation (ünsüz yumuşaması / sertleşmesi: b->p, c->ç, d->t, ğ->k, g->k)
|
|
620
|
+
* 3. Reverse vowel drop (ünlü düşmesi: akl->akıl, şehr->şehir, omz->omuz)
|
|
621
|
+
* 4. Infinitive restoration (-mek / -mak for verbal stems)
|
|
622
|
+
* 5. Apostrophe stripping for proper nouns (İstanbul'da -> İstanbul)
|
|
623
|
+
*/
|
|
624
|
+
declare const TURKISH_VOWELS = "ae\u0131io\u00F6u\u00FC";
|
|
625
|
+
declare function isVowel(ch: string): boolean;
|
|
626
|
+
/**
|
|
627
|
+
* Turkish suffixes ordered strictly by descending length so that longer
|
|
628
|
+
* composite suffixes match before their individual subcomponents.
|
|
629
|
+
*/
|
|
630
|
+
declare const TURKISH_SUFFIXES: readonly string[];
|
|
631
|
+
/**
|
|
632
|
+
* Reverses Turkish consonant softening (ünsüz yumuşaması):
|
|
633
|
+
* When a root ends with p, ç, t, k, it softens to b, c, d, ğ, g before a vowel.
|
|
634
|
+
* This restores the hardened dictionary headword form.
|
|
635
|
+
*/
|
|
636
|
+
declare function restoreConsonantSoftening(stem: string): string[];
|
|
637
|
+
/**
|
|
638
|
+
* Reverses Turkish vowel drop (ünlü düşmesi):
|
|
639
|
+
* In words like akıl->aklım, şehir->şehre, burun->burnu, omuz->omzum,
|
|
640
|
+
* the narrow vowel in the second syllable drops when receiving a vowel-initial suffix.
|
|
641
|
+
* This restores the harmonic dropped vowel between the final consonant cluster.
|
|
642
|
+
*/
|
|
643
|
+
declare function restoreVowelDrop(stem: string): string[];
|
|
644
|
+
/**
|
|
645
|
+
* Reverses Turkish consonant gemination (ünsüz türemesi / ikizleşmesi):
|
|
646
|
+
* In words of Arabic/foreign origin, when receiving a vowel-initial suffix, the final consonant doubles:
|
|
647
|
+
* e.g. hak->hakkı, his->hissi, sır->sırrı, af->affı, ret->reddi, tıp->tıbbı, zam->zammı, hat->hattı.
|
|
648
|
+
* Restores the single consonant form and checks consonant softening on the result (e.g. redd -> red -> ret).
|
|
649
|
+
*/
|
|
650
|
+
declare function restoreGemination(stem: string): string[];
|
|
651
|
+
/**
|
|
652
|
+
* Reverses Turkish vowel narrowing (ünlü daralması):
|
|
653
|
+
* Verbs ending in wide vowels 'a' or 'e' narrow to 'ı', 'i', 'u', 'ü' before the continuous tense suffix -yor:
|
|
654
|
+
* e.g. başla-yor -> başlıyor, bekle-yor -> bekliyor, özle-yor -> özlüyor, anla-yor -> anlıyor.
|
|
655
|
+
* Also handles irregular monosyllabic verbs: de-yor -> diyor, ye-yor -> yiyor.
|
|
656
|
+
*/
|
|
657
|
+
declare function restoreVowelNarrowing(stem: string): string[];
|
|
658
|
+
/**
|
|
659
|
+
* Restores verb infinitive headword form (-mek / -mak):
|
|
660
|
+
* Since TDK registers verbs in their infinitive form (e.g. okumak, gelmek, yazmak),
|
|
661
|
+
* conjugated verb stems (e.g. oku, gel, yaz) need -mak/-mek appended according to vowel harmony.
|
|
662
|
+
*/
|
|
663
|
+
declare function restoreInfinitive(stem: string): string[];
|
|
664
|
+
/**
|
|
665
|
+
* Generates candidate roots for a given Turkish word using progressive BFS suffix stripping,
|
|
666
|
+
* consonant mutation restoration, vowel drop restoration, and infinitive restoration.
|
|
667
|
+
*
|
|
668
|
+
* Candidates are sorted so that longer base stems (less aggressive stripping) are checked first,
|
|
669
|
+
* preventing spurious 2-letter roots from overshadowing genuine headwords.
|
|
670
|
+
*
|
|
671
|
+
* @param word The input word to analyze
|
|
672
|
+
* @param minStemLength Minimum allowed length for candidate stems (default: 2)
|
|
673
|
+
* @param maxDepth Maximum levels of progressive suffix stripping (default: 4)
|
|
674
|
+
* @returns Array of unique candidate roots in prioritized order
|
|
675
|
+
*/
|
|
676
|
+
declare function getStemCandidates(word: string, minStemLength?: number, maxDepth?: number): string[];
|
|
677
|
+
|
|
678
|
+
export { type AnagramOptions, type Author, type DailyContent, type DailyPick, type Example, type Feature, type KubbealtiEntry, type Meaning, type PatternSearchOptions, type ProofreadIssue, type ProofreadResult, type Proverb, type RhymeOptions, type SpellCheckResult, type StemResult, TDK, TDKClient, type TDKConfig, TDKError, TDKNetworkError, type TDKResponse, type TDKRule, TDKValidationError, TURKISH_SUFFIXES, TURKISH_VOWELS, type WiktionaryEntry, type WordAnalysis, type WordComparison, type WordComparisonSide, type WordInfo, type WordOfTheDay, getStemCandidates, isVowel, restoreConsonantSoftening, restoreGemination, restoreInfinitive, restoreVowelDrop, restoreVowelNarrowing };
|