tdk-api-wrapper 1.3.1 → 1.4.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 +13 -5
- package/dist/{chunk-ACMGCL7T.mjs → chunk-5TYJDVHK.mjs} +620 -6
- package/dist/cli.js +653 -9
- package/dist/cli.mjs +41 -4
- package/dist/index.d.mts +88 -1
- package/dist/index.d.ts +88 -1
- package/dist/index.js +629 -8
- package/dist/index.mjs +17 -3
- package/package.json +3 -2
- package/src/cli.ts +40 -3
- package/src/index.ts +1 -0
- package/src/morphology.ts +214 -0
- package/src/tdk.ts +135 -6
- package/src/types.ts +11 -0
- package/test/morphology.test.js +105 -0
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
TDK
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-5TYJDVHK.mjs";
|
|
5
5
|
|
|
6
6
|
// src/cli.ts
|
|
7
7
|
var rawArgs = process.argv.slice(2);
|
|
@@ -15,6 +15,9 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
15
15
|
"hece",
|
|
16
16
|
"uyum",
|
|
17
17
|
"yazim",
|
|
18
|
+
"kok",
|
|
19
|
+
"stem",
|
|
20
|
+
"deyim",
|
|
18
21
|
"gunun",
|
|
19
22
|
"rastgele",
|
|
20
23
|
"esanlam",
|
|
@@ -53,7 +56,7 @@ async function run() {
|
|
|
53
56
|
if (!command || command === "--help" || command === "-h") {
|
|
54
57
|
console.log("Kullan\u0131m: tdk [komut] <kelime> [--json]");
|
|
55
58
|
console.log(
|
|
56
|
-
"Komutlar: ara, anlam, koken, ornek, hece, uyum, yazim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, kubbealti, nisanyan, viki"
|
|
59
|
+
"Komutlar: ara, anlam, koken, ornek, hece, uyum, yazim, kok, deyim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, kubbealti, nisanyan, viki"
|
|
57
60
|
);
|
|
58
61
|
console.log("Not: Komut belirtilmezse do\u011Frudan kelime anlam\u0131 aran\u0131r (\xF6rn: tdk selam)");
|
|
59
62
|
process.exit(command ? 0 : 1);
|
|
@@ -121,13 +124,46 @@ async function run() {
|
|
|
121
124
|
const spellResult = await TDK.checkSpelling(word);
|
|
122
125
|
printResult(spellResult, () => {
|
|
123
126
|
if (spellResult.isCorrect) {
|
|
124
|
-
|
|
127
|
+
if (spellResult.isInflected && spellResult.root) {
|
|
128
|
+
console.log(`Do\u011Fru yaz\u0131m (\xE7ekimli bi\xE7im, k\xF6k: ${spellResult.root}).`);
|
|
129
|
+
} else {
|
|
130
|
+
console.log("Do\u011Fru yaz\u0131m.");
|
|
131
|
+
}
|
|
125
132
|
} else {
|
|
126
133
|
console.log(`Yanl\u0131\u015F yaz\u0131m.${spellResult.suggestion ? " Do\u011Frusu: " + spellResult.suggestion : ""}`);
|
|
127
134
|
}
|
|
128
135
|
});
|
|
129
136
|
break;
|
|
130
137
|
}
|
|
138
|
+
case "kok":
|
|
139
|
+
case "stem": {
|
|
140
|
+
if (!word)
|
|
141
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
142
|
+
const stemResult = await TDK.stem(word);
|
|
143
|
+
printResult(stemResult, () => {
|
|
144
|
+
if (!stemResult) {
|
|
145
|
+
console.log("K\xF6k bulunamad\u0131.");
|
|
146
|
+
} else if (stemResult.isInflected) {
|
|
147
|
+
console.log(`K\xF6k: ${stemResult.root} (\xE7ekimli bi\xE7im)`);
|
|
148
|
+
} else {
|
|
149
|
+
console.log(`K\xF6k: ${stemResult.root} (yal\u0131n bi\xE7im)`);
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case "deyim": {
|
|
155
|
+
if (!word)
|
|
156
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
157
|
+
const proverbs = await TDK.getProverbs(word);
|
|
158
|
+
printResult(proverbs, () => {
|
|
159
|
+
if (proverbs.length === 0) {
|
|
160
|
+
console.log("Atas\xF6z\xFC/deyim bulunamad\u0131.");
|
|
161
|
+
} else {
|
|
162
|
+
proverbs.forEach((p, i) => console.log(`${i + 1}. ${p}`));
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
break;
|
|
166
|
+
}
|
|
131
167
|
case "gunun": {
|
|
132
168
|
const wotd = await TDK.getWordOfTheDay();
|
|
133
169
|
printResult(wotd, () => {
|
|
@@ -234,7 +270,8 @@ async function run() {
|
|
|
234
270
|
} else {
|
|
235
271
|
analysis.forEach((a) => {
|
|
236
272
|
if (a.found) {
|
|
237
|
-
|
|
273
|
+
const rootLabel = a.isInflected && a.root ? ` (k\xF6k: ${a.root})` : "";
|
|
274
|
+
console.log(`${a.word}${rootLabel}: ${a.meaning ?? "-"} (${a.origin})`);
|
|
238
275
|
} else {
|
|
239
276
|
console.log(`${a.word}: bulunamad\u0131`);
|
|
240
277
|
}
|
package/dist/index.d.mts
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;
|
|
@@ -125,6 +133,8 @@ interface WordAnalysis {
|
|
|
125
133
|
found: boolean;
|
|
126
134
|
meaning: string | null;
|
|
127
135
|
origin: string | null;
|
|
136
|
+
root?: string;
|
|
137
|
+
isInflected?: boolean;
|
|
128
138
|
}
|
|
129
139
|
interface KubbealtiEntry {
|
|
130
140
|
kelime: string;
|
|
@@ -162,6 +172,8 @@ declare class TDK {
|
|
|
162
172
|
private static wordCache;
|
|
163
173
|
private static dailyContentCache;
|
|
164
174
|
private static autocompleteCache;
|
|
175
|
+
private static autocompleteSet;
|
|
176
|
+
private static stemCache;
|
|
165
177
|
/**
|
|
166
178
|
* Enables or disables in-memory caching for API requests.
|
|
167
179
|
*/
|
|
@@ -191,6 +203,10 @@ declare class TDK {
|
|
|
191
203
|
* this, this fails closed to `[]` rather than throwing.
|
|
192
204
|
*/
|
|
193
205
|
private static fetchAutocompleteData;
|
|
206
|
+
/**
|
|
207
|
+
* Ensures TDK's ~81k headword list is loaded in memory for fast O(1) set operations.
|
|
208
|
+
*/
|
|
209
|
+
private static ensureAutocompleteLoaded;
|
|
194
210
|
/**
|
|
195
211
|
* Returns autocomplete suggestions for a given prefix, searched over TDK's
|
|
196
212
|
* full headword list (see `fetchAutocompleteData`). The list is fetched
|
|
@@ -198,6 +214,27 @@ declare class TDK {
|
|
|
198
214
|
* caching behavior as before — and only cleared by `clearCache()`.
|
|
199
215
|
*/
|
|
200
216
|
static getSuggestions(prefix: string): Promise<string[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Checks whether a word exists as a known headword in TDK dictionary.
|
|
219
|
+
* Checks in-memory autocompleteSet (81k headwords) if loaded, or queries TDK API.
|
|
220
|
+
*/
|
|
221
|
+
static isHeadword(word: string): Promise<boolean>;
|
|
222
|
+
/**
|
|
223
|
+
* Generates candidate roots for a given Turkish word using progressive BFS suffix stripping,
|
|
224
|
+
* consonant mutation restoration, and vowel drop restoration.
|
|
225
|
+
*/
|
|
226
|
+
static getStemCandidates(word: string): string[];
|
|
227
|
+
/**
|
|
228
|
+
* Finds the dictionary root (headword) of a word by checking direct existence
|
|
229
|
+
* and evaluating candidate stems generated by morphological analysis.
|
|
230
|
+
* Returns the root headword string if found, or null if no match in TDK.
|
|
231
|
+
*/
|
|
232
|
+
static findRoot(word: string): Promise<string | null>;
|
|
233
|
+
/**
|
|
234
|
+
* Performs morphological stemming on a Turkish word.
|
|
235
|
+
* Returns a StemResult containing the original word, resolved root, and whether it is inflected.
|
|
236
|
+
*/
|
|
237
|
+
static stem(word: string): Promise<StemResult | null>;
|
|
201
238
|
/**
|
|
202
239
|
* Returns a list of proverbs and idioms containing the word.
|
|
203
240
|
*/
|
|
@@ -470,4 +507,54 @@ declare class TDKNetworkError extends TDKError {
|
|
|
470
507
|
});
|
|
471
508
|
}
|
|
472
509
|
|
|
473
|
-
|
|
510
|
+
/**
|
|
511
|
+
* Turkish Morphology Engine & Stem Candidate Generator.
|
|
512
|
+
*
|
|
513
|
+
* Implements heuristic-based progressive suffix stripping (BFS) with:
|
|
514
|
+
* 1. Comprehensive Turkish suffix catalogue (inflectional, derivational, composite)
|
|
515
|
+
* 2. Reverse consonant mutation (ünsüz yumuşaması / sertleşmesi: b->p, c->ç, d->t, ğ->k, g->k)
|
|
516
|
+
* 3. Reverse vowel drop (ünlü düşmesi: akl->akıl, şehr->şehir, omz->omuz)
|
|
517
|
+
* 4. Infinitive restoration (-mek / -mak for verbal stems)
|
|
518
|
+
* 5. Apostrophe stripping for proper nouns (İstanbul'da -> İstanbul)
|
|
519
|
+
*/
|
|
520
|
+
declare const TURKISH_VOWELS = "ae\u0131io\u00F6u\u00FC";
|
|
521
|
+
declare function isVowel(ch: string): boolean;
|
|
522
|
+
/**
|
|
523
|
+
* Turkish suffixes ordered strictly by descending length so that longer
|
|
524
|
+
* composite suffixes match before their individual subcomponents.
|
|
525
|
+
*/
|
|
526
|
+
declare const TURKISH_SUFFIXES: readonly string[];
|
|
527
|
+
/**
|
|
528
|
+
* Reverses Turkish consonant softening (ünsüz yumuşaması):
|
|
529
|
+
* When a root ends with p, ç, t, k, it softens to b, c, d, ğ, g before a vowel.
|
|
530
|
+
* This restores the hardened dictionary headword form.
|
|
531
|
+
*/
|
|
532
|
+
declare function restoreConsonantSoftening(stem: string): string[];
|
|
533
|
+
/**
|
|
534
|
+
* Reverses Turkish vowel drop (ünlü düşmesi):
|
|
535
|
+
* In words like akıl->aklım, şehir->şehre, burun->burnu, omuz->omzum,
|
|
536
|
+
* the narrow vowel in the second syllable drops when receiving a vowel-initial suffix.
|
|
537
|
+
* This restores the harmonic dropped vowel between the final consonant cluster.
|
|
538
|
+
*/
|
|
539
|
+
declare function restoreVowelDrop(stem: string): string[];
|
|
540
|
+
/**
|
|
541
|
+
* Restores verb infinitive headword form (-mek / -mak):
|
|
542
|
+
* Since TDK registers verbs in their infinitive form (e.g. okumak, gelmek, yazmak),
|
|
543
|
+
* conjugated verb stems (e.g. oku, gel, yaz) need -mak/-mek appended according to vowel harmony.
|
|
544
|
+
*/
|
|
545
|
+
declare function restoreInfinitive(stem: string): string[];
|
|
546
|
+
/**
|
|
547
|
+
* Generates candidate roots for a given Turkish word using progressive BFS suffix stripping,
|
|
548
|
+
* consonant mutation restoration, vowel drop restoration, and infinitive restoration.
|
|
549
|
+
*
|
|
550
|
+
* Candidates are sorted so that longer base stems (less aggressive stripping) are checked first,
|
|
551
|
+
* preventing spurious 2-letter roots from overshadowing genuine headwords.
|
|
552
|
+
*
|
|
553
|
+
* @param word The input word to analyze
|
|
554
|
+
* @param minStemLength Minimum allowed length for candidate stems (default: 2)
|
|
555
|
+
* @param maxDepth Maximum levels of progressive suffix stripping (default: 4)
|
|
556
|
+
* @returns Array of unique candidate roots in prioritized order
|
|
557
|
+
*/
|
|
558
|
+
declare function getStemCandidates(word: string, minStemLength?: number, maxDepth?: number): string[];
|
|
559
|
+
|
|
560
|
+
export { type Author, type DailyContent, type DailyPick, type Example, type Feature, type KubbealtiEntry, type Meaning, type Proverb, type SpellCheckResult, type StemResult, TDK, 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, restoreInfinitive, restoreVowelDrop };
|
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;
|
|
@@ -125,6 +133,8 @@ interface WordAnalysis {
|
|
|
125
133
|
found: boolean;
|
|
126
134
|
meaning: string | null;
|
|
127
135
|
origin: string | null;
|
|
136
|
+
root?: string;
|
|
137
|
+
isInflected?: boolean;
|
|
128
138
|
}
|
|
129
139
|
interface KubbealtiEntry {
|
|
130
140
|
kelime: string;
|
|
@@ -162,6 +172,8 @@ declare class TDK {
|
|
|
162
172
|
private static wordCache;
|
|
163
173
|
private static dailyContentCache;
|
|
164
174
|
private static autocompleteCache;
|
|
175
|
+
private static autocompleteSet;
|
|
176
|
+
private static stemCache;
|
|
165
177
|
/**
|
|
166
178
|
* Enables or disables in-memory caching for API requests.
|
|
167
179
|
*/
|
|
@@ -191,6 +203,10 @@ declare class TDK {
|
|
|
191
203
|
* this, this fails closed to `[]` rather than throwing.
|
|
192
204
|
*/
|
|
193
205
|
private static fetchAutocompleteData;
|
|
206
|
+
/**
|
|
207
|
+
* Ensures TDK's ~81k headword list is loaded in memory for fast O(1) set operations.
|
|
208
|
+
*/
|
|
209
|
+
private static ensureAutocompleteLoaded;
|
|
194
210
|
/**
|
|
195
211
|
* Returns autocomplete suggestions for a given prefix, searched over TDK's
|
|
196
212
|
* full headword list (see `fetchAutocompleteData`). The list is fetched
|
|
@@ -198,6 +214,27 @@ declare class TDK {
|
|
|
198
214
|
* caching behavior as before — and only cleared by `clearCache()`.
|
|
199
215
|
*/
|
|
200
216
|
static getSuggestions(prefix: string): Promise<string[]>;
|
|
217
|
+
/**
|
|
218
|
+
* Checks whether a word exists as a known headword in TDK dictionary.
|
|
219
|
+
* Checks in-memory autocompleteSet (81k headwords) if loaded, or queries TDK API.
|
|
220
|
+
*/
|
|
221
|
+
static isHeadword(word: string): Promise<boolean>;
|
|
222
|
+
/**
|
|
223
|
+
* Generates candidate roots for a given Turkish word using progressive BFS suffix stripping,
|
|
224
|
+
* consonant mutation restoration, and vowel drop restoration.
|
|
225
|
+
*/
|
|
226
|
+
static getStemCandidates(word: string): string[];
|
|
227
|
+
/**
|
|
228
|
+
* Finds the dictionary root (headword) of a word by checking direct existence
|
|
229
|
+
* and evaluating candidate stems generated by morphological analysis.
|
|
230
|
+
* Returns the root headword string if found, or null if no match in TDK.
|
|
231
|
+
*/
|
|
232
|
+
static findRoot(word: string): Promise<string | null>;
|
|
233
|
+
/**
|
|
234
|
+
* Performs morphological stemming on a Turkish word.
|
|
235
|
+
* Returns a StemResult containing the original word, resolved root, and whether it is inflected.
|
|
236
|
+
*/
|
|
237
|
+
static stem(word: string): Promise<StemResult | null>;
|
|
201
238
|
/**
|
|
202
239
|
* Returns a list of proverbs and idioms containing the word.
|
|
203
240
|
*/
|
|
@@ -470,4 +507,54 @@ declare class TDKNetworkError extends TDKError {
|
|
|
470
507
|
});
|
|
471
508
|
}
|
|
472
509
|
|
|
473
|
-
|
|
510
|
+
/**
|
|
511
|
+
* Turkish Morphology Engine & Stem Candidate Generator.
|
|
512
|
+
*
|
|
513
|
+
* Implements heuristic-based progressive suffix stripping (BFS) with:
|
|
514
|
+
* 1. Comprehensive Turkish suffix catalogue (inflectional, derivational, composite)
|
|
515
|
+
* 2. Reverse consonant mutation (ünsüz yumuşaması / sertleşmesi: b->p, c->ç, d->t, ğ->k, g->k)
|
|
516
|
+
* 3. Reverse vowel drop (ünlü düşmesi: akl->akıl, şehr->şehir, omz->omuz)
|
|
517
|
+
* 4. Infinitive restoration (-mek / -mak for verbal stems)
|
|
518
|
+
* 5. Apostrophe stripping for proper nouns (İstanbul'da -> İstanbul)
|
|
519
|
+
*/
|
|
520
|
+
declare const TURKISH_VOWELS = "ae\u0131io\u00F6u\u00FC";
|
|
521
|
+
declare function isVowel(ch: string): boolean;
|
|
522
|
+
/**
|
|
523
|
+
* Turkish suffixes ordered strictly by descending length so that longer
|
|
524
|
+
* composite suffixes match before their individual subcomponents.
|
|
525
|
+
*/
|
|
526
|
+
declare const TURKISH_SUFFIXES: readonly string[];
|
|
527
|
+
/**
|
|
528
|
+
* Reverses Turkish consonant softening (ünsüz yumuşaması):
|
|
529
|
+
* When a root ends with p, ç, t, k, it softens to b, c, d, ğ, g before a vowel.
|
|
530
|
+
* This restores the hardened dictionary headword form.
|
|
531
|
+
*/
|
|
532
|
+
declare function restoreConsonantSoftening(stem: string): string[];
|
|
533
|
+
/**
|
|
534
|
+
* Reverses Turkish vowel drop (ünlü düşmesi):
|
|
535
|
+
* In words like akıl->aklım, şehir->şehre, burun->burnu, omuz->omzum,
|
|
536
|
+
* the narrow vowel in the second syllable drops when receiving a vowel-initial suffix.
|
|
537
|
+
* This restores the harmonic dropped vowel between the final consonant cluster.
|
|
538
|
+
*/
|
|
539
|
+
declare function restoreVowelDrop(stem: string): string[];
|
|
540
|
+
/**
|
|
541
|
+
* Restores verb infinitive headword form (-mek / -mak):
|
|
542
|
+
* Since TDK registers verbs in their infinitive form (e.g. okumak, gelmek, yazmak),
|
|
543
|
+
* conjugated verb stems (e.g. oku, gel, yaz) need -mak/-mek appended according to vowel harmony.
|
|
544
|
+
*/
|
|
545
|
+
declare function restoreInfinitive(stem: string): string[];
|
|
546
|
+
/**
|
|
547
|
+
* Generates candidate roots for a given Turkish word using progressive BFS suffix stripping,
|
|
548
|
+
* consonant mutation restoration, vowel drop restoration, and infinitive restoration.
|
|
549
|
+
*
|
|
550
|
+
* Candidates are sorted so that longer base stems (less aggressive stripping) are checked first,
|
|
551
|
+
* preventing spurious 2-letter roots from overshadowing genuine headwords.
|
|
552
|
+
*
|
|
553
|
+
* @param word The input word to analyze
|
|
554
|
+
* @param minStemLength Minimum allowed length for candidate stems (default: 2)
|
|
555
|
+
* @param maxDepth Maximum levels of progressive suffix stripping (default: 4)
|
|
556
|
+
* @returns Array of unique candidate roots in prioritized order
|
|
557
|
+
*/
|
|
558
|
+
declare function getStemCandidates(word: string, minStemLength?: number, maxDepth?: number): string[];
|
|
559
|
+
|
|
560
|
+
export { type Author, type DailyContent, type DailyPick, type Example, type Feature, type KubbealtiEntry, type Meaning, type Proverb, type SpellCheckResult, type StemResult, TDK, 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, restoreInfinitive, restoreVowelDrop };
|