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/cli.mjs
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import {
|
|
3
3
|
TDK
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-7KJHYRJZ.mjs";
|
|
5
5
|
|
|
6
6
|
// src/cli.ts
|
|
7
7
|
var rawArgs = process.argv.slice(2);
|
|
8
8
|
var jsonMode = rawArgs.includes("--json");
|
|
9
9
|
var args = rawArgs.filter((a) => a !== "--json");
|
|
10
|
+
var isColor = !jsonMode && Boolean(process.stdout.isTTY);
|
|
11
|
+
var c = {
|
|
12
|
+
bold: (s) => isColor ? `\x1B[1m${s}\x1B[0m` : s,
|
|
13
|
+
dim: (s) => isColor ? `\x1B[2m${s}\x1B[0m` : s,
|
|
14
|
+
green: (s) => isColor ? `\x1B[32m${s}\x1B[0m` : s,
|
|
15
|
+
yellow: (s) => isColor ? `\x1B[33m${s}\x1B[0m` : s,
|
|
16
|
+
cyan: (s) => isColor ? `\x1B[36m${s}\x1B[0m` : s,
|
|
17
|
+
red: (s) => isColor ? `\x1B[31m${s}\x1B[0m` : s
|
|
18
|
+
};
|
|
10
19
|
var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
11
20
|
"ara",
|
|
12
21
|
"anlam",
|
|
@@ -14,7 +23,11 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
14
23
|
"ornek",
|
|
15
24
|
"hece",
|
|
16
25
|
"uyum",
|
|
26
|
+
"kucukuyum",
|
|
17
27
|
"yazim",
|
|
28
|
+
"kok",
|
|
29
|
+
"stem",
|
|
30
|
+
"deyim",
|
|
18
31
|
"gunun",
|
|
19
32
|
"rastgele",
|
|
20
33
|
"esanlam",
|
|
@@ -25,6 +38,14 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
25
38
|
"karsilastir",
|
|
26
39
|
"analiz",
|
|
27
40
|
"oneri",
|
|
41
|
+
"bulmaca",
|
|
42
|
+
"pattern",
|
|
43
|
+
"anagram",
|
|
44
|
+
"kafiye",
|
|
45
|
+
"rhyme",
|
|
46
|
+
"denetle",
|
|
47
|
+
"proofread",
|
|
48
|
+
"repl",
|
|
28
49
|
"kubbealti",
|
|
29
50
|
"nisanyan",
|
|
30
51
|
"viki"
|
|
@@ -46,17 +67,93 @@ function printError(message) {
|
|
|
46
67
|
if (jsonMode) {
|
|
47
68
|
console.log(JSON.stringify({ error: message }));
|
|
48
69
|
} else {
|
|
49
|
-
console.log(`Hata: ${message}`);
|
|
70
|
+
console.log(c.red(`Hata: ${message}`));
|
|
50
71
|
}
|
|
51
72
|
}
|
|
73
|
+
async function startRepl() {
|
|
74
|
+
const readline = await import("readline");
|
|
75
|
+
const rl = readline.createInterface({
|
|
76
|
+
input: process.stdin,
|
|
77
|
+
output: process.stdout,
|
|
78
|
+
prompt: c.cyan("tdk> ")
|
|
79
|
+
});
|
|
80
|
+
console.log(c.bold("TDK \u0130nteraktif S\xF6zl\xFCk Kabu\u011Fu (\xC7\u0131kmak i\xE7in 'exit' veya Ctrl+C)"));
|
|
81
|
+
console.log(c.dim("Komutlar: ara <kelime>, hece <kelime>, bulmaca <desen>, denetle <metin> veya do\u011Frudan kelime"));
|
|
82
|
+
rl.prompt();
|
|
83
|
+
rl.on("line", async (line) => {
|
|
84
|
+
const trimmed = line.trim();
|
|
85
|
+
if (!trimmed) {
|
|
86
|
+
rl.prompt();
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (trimmed === "exit" || trimmed === "quit" || trimmed === ".exit") {
|
|
90
|
+
rl.close();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const parts = trimmed.split(/\s+/);
|
|
94
|
+
let subCmd = parts[0].toLowerCase();
|
|
95
|
+
let subArg = parts.slice(1).join(" ");
|
|
96
|
+
if (!KNOWN_COMMANDS.has(subCmd)) {
|
|
97
|
+
subArg = trimmed;
|
|
98
|
+
subCmd = "anlam";
|
|
99
|
+
}
|
|
100
|
+
try {
|
|
101
|
+
if (subCmd === "ara" || subCmd === "anlam") {
|
|
102
|
+
const meanings = await TDK.getMeanings(subArg);
|
|
103
|
+
if (meanings.length === 0)
|
|
104
|
+
console.log(c.dim("Sonu\xE7 bulunamad\u0131."));
|
|
105
|
+
else
|
|
106
|
+
meanings.forEach((m, i) => console.log(`${i + 1}. ${c.green(m)}`));
|
|
107
|
+
} else if (subCmd === "koken") {
|
|
108
|
+
const origin = await TDK.getOrigin(subArg);
|
|
109
|
+
console.log(`K\xF6ken: ${c.cyan(origin || "Bilinmiyor")}`);
|
|
110
|
+
} else if (subCmd === "hece") {
|
|
111
|
+
const s = TDK.syllabicate(subArg);
|
|
112
|
+
console.log(`Heceler: ${c.yellow(s.join("-"))}`);
|
|
113
|
+
} else if (subCmd === "uyum") {
|
|
114
|
+
const h = TDK.checkVowelHarmony(subArg);
|
|
115
|
+
console.log(`B\xFCy\xFCk \xDCnl\xFC Uyumu: ${h ? c.green("Uyar") : c.red("Uymaz")}`);
|
|
116
|
+
} else if (subCmd === "kucukuyum") {
|
|
117
|
+
const h = TDK.checkLabialHarmony(subArg);
|
|
118
|
+
console.log(`K\xFC\xE7\xFCk \xDCnl\xFC Uyumu: ${h ? c.green("Uyar") : c.red("Uymaz")}`);
|
|
119
|
+
} else if (subCmd === "bulmaca" || subCmd === "pattern") {
|
|
120
|
+
const matches = await TDK.patternSearch(subArg);
|
|
121
|
+
console.log(matches.slice(0, 15).join(", "));
|
|
122
|
+
} else if (subCmd === "denetle" || subCmd === "proofread") {
|
|
123
|
+
const res = await TDK.proofread(subArg);
|
|
124
|
+
if (res.isCorrect)
|
|
125
|
+
console.log(c.green("\u2713 Sorun bulunamad\u0131."));
|
|
126
|
+
else
|
|
127
|
+
res.issues.forEach((iss) => console.log(`- ${c.yellow(iss.word)}: ${iss.message}${iss.suggestion ? " -> " + c.green(iss.suggestion) : ""}`));
|
|
128
|
+
} else {
|
|
129
|
+
console.log(c.dim("\xD6rnek komutlar: 'ara kalem', 'hece elektrik', 'bulmaca k_l_m', 'denetle Bug\xFCn evdeyim'"));
|
|
130
|
+
}
|
|
131
|
+
} catch (e) {
|
|
132
|
+
console.log(c.red(`Hata: ${e?.message || e}`));
|
|
133
|
+
}
|
|
134
|
+
rl.prompt();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
52
137
|
async function run() {
|
|
53
|
-
if (!command
|
|
138
|
+
if (!command) {
|
|
139
|
+
if (process.stdin.isTTY) {
|
|
140
|
+
await startRepl();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
console.log("Kullan\u0131m: tdk [komut] <kelime> [--json]");
|
|
144
|
+
console.log(
|
|
145
|
+
"Komutlar: ara, anlam, koken, ornek, hece, uyum, kucukuyum, yazim, kok, deyim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, bulmaca, anagram, kafiye, denetle, repl, kubbealti, nisanyan, viki"
|
|
146
|
+
);
|
|
147
|
+
console.log("Not: Komut belirtilmezse do\u011Frudan kelime anlam\u0131 aran\u0131r (\xF6rn: tdk selam)");
|
|
148
|
+
process.exit(1);
|
|
149
|
+
}
|
|
150
|
+
if (command === "--help" || command === "-h") {
|
|
54
151
|
console.log("Kullan\u0131m: tdk [komut] <kelime> [--json]");
|
|
55
152
|
console.log(
|
|
56
|
-
"Komutlar: ara, anlam, koken, ornek, hece, uyum, yazim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, kubbealti, nisanyan, viki"
|
|
153
|
+
"Komutlar: ara, anlam, koken, ornek, hece, uyum, kucukuyum, yazim, kok, deyim, gunun, rastgele, esanlam, karsit, yabanci, kurallar, kural, karsilastir, analiz, oneri, bulmaca, anagram, kafiye, denetle, repl, kubbealti, nisanyan, viki"
|
|
57
154
|
);
|
|
58
155
|
console.log("Not: Komut belirtilmezse do\u011Frudan kelime anlam\u0131 aran\u0131r (\xF6rn: tdk selam)");
|
|
59
|
-
process.exit(
|
|
156
|
+
process.exit(0);
|
|
60
157
|
}
|
|
61
158
|
TDK.enableCache(false);
|
|
62
159
|
try {
|
|
@@ -115,19 +212,63 @@ async function run() {
|
|
|
115
212
|
);
|
|
116
213
|
break;
|
|
117
214
|
}
|
|
215
|
+
case "kucukuyum":
|
|
216
|
+
case "labial": {
|
|
217
|
+
if (!word)
|
|
218
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
219
|
+
const isHarmony = TDK.checkLabialHarmony(word);
|
|
220
|
+
printResult(
|
|
221
|
+
{ word, labialHarmony: isHarmony },
|
|
222
|
+
() => console.log(`K\xFC\xE7\xFCk \xDCnl\xFC Uyumu: ${isHarmony ? "Uyar" : "Uymaz"}`)
|
|
223
|
+
);
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
118
226
|
case "yazim": {
|
|
119
227
|
if (!word)
|
|
120
228
|
throw new Error("Kelime belirtmelisiniz.");
|
|
121
229
|
const spellResult = await TDK.checkSpelling(word);
|
|
122
230
|
printResult(spellResult, () => {
|
|
123
231
|
if (spellResult.isCorrect) {
|
|
124
|
-
|
|
232
|
+
if (spellResult.isInflected && spellResult.root) {
|
|
233
|
+
console.log(`Do\u011Fru yaz\u0131m (\xE7ekimli bi\xE7im, k\xF6k: ${spellResult.root}).`);
|
|
234
|
+
} else {
|
|
235
|
+
console.log("Do\u011Fru yaz\u0131m.");
|
|
236
|
+
}
|
|
125
237
|
} else {
|
|
126
238
|
console.log(`Yanl\u0131\u015F yaz\u0131m.${spellResult.suggestion ? " Do\u011Frusu: " + spellResult.suggestion : ""}`);
|
|
127
239
|
}
|
|
128
240
|
});
|
|
129
241
|
break;
|
|
130
242
|
}
|
|
243
|
+
case "kok":
|
|
244
|
+
case "stem": {
|
|
245
|
+
if (!word)
|
|
246
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
247
|
+
const stemResult = await TDK.stem(word);
|
|
248
|
+
printResult(stemResult, () => {
|
|
249
|
+
if (!stemResult) {
|
|
250
|
+
console.log("K\xF6k bulunamad\u0131.");
|
|
251
|
+
} else if (stemResult.isInflected) {
|
|
252
|
+
console.log(`K\xF6k: ${stemResult.root} (\xE7ekimli bi\xE7im)`);
|
|
253
|
+
} else {
|
|
254
|
+
console.log(`K\xF6k: ${stemResult.root} (yal\u0131n bi\xE7im)`);
|
|
255
|
+
}
|
|
256
|
+
});
|
|
257
|
+
break;
|
|
258
|
+
}
|
|
259
|
+
case "deyim": {
|
|
260
|
+
if (!word)
|
|
261
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
262
|
+
const proverbs = await TDK.getProverbs(word);
|
|
263
|
+
printResult(proverbs, () => {
|
|
264
|
+
if (proverbs.length === 0) {
|
|
265
|
+
console.log("Atas\xF6z\xFC/deyim bulunamad\u0131.");
|
|
266
|
+
} else {
|
|
267
|
+
proverbs.forEach((p, i) => console.log(`${i + 1}. ${p}`));
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
break;
|
|
271
|
+
}
|
|
131
272
|
case "gunun": {
|
|
132
273
|
const wotd = await TDK.getWordOfTheDay();
|
|
133
274
|
printResult(wotd, () => {
|
|
@@ -234,7 +375,8 @@ async function run() {
|
|
|
234
375
|
} else {
|
|
235
376
|
analysis.forEach((a) => {
|
|
236
377
|
if (a.found) {
|
|
237
|
-
|
|
378
|
+
const rootLabel = a.isInflected && a.root ? ` (k\xF6k: ${a.root})` : "";
|
|
379
|
+
console.log(`${a.word}${rootLabel}: ${a.meaning ?? "-"} (${a.origin})`);
|
|
238
380
|
} else {
|
|
239
381
|
console.log(`${a.word}: bulunamad\u0131`);
|
|
240
382
|
}
|
|
@@ -256,6 +398,76 @@ async function run() {
|
|
|
256
398
|
});
|
|
257
399
|
break;
|
|
258
400
|
}
|
|
401
|
+
case "bulmaca":
|
|
402
|
+
case "pattern": {
|
|
403
|
+
if (!word)
|
|
404
|
+
throw new Error("Desen belirtmelisiniz (\xF6rn: k_l_m).");
|
|
405
|
+
const matches = await TDK.patternSearch(word);
|
|
406
|
+
printResult(matches, () => {
|
|
407
|
+
if (matches.length === 0) {
|
|
408
|
+
console.log("E\u015Fle\u015Fen kelime bulunamad\u0131.");
|
|
409
|
+
} else {
|
|
410
|
+
console.log(c.bold(`Bulunan Kelimeler (${matches.length}):`));
|
|
411
|
+
matches.forEach((m, i) => console.log(`${i + 1}. ${c.cyan(m)}`));
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
break;
|
|
415
|
+
}
|
|
416
|
+
case "anagram": {
|
|
417
|
+
if (!word)
|
|
418
|
+
throw new Error("Harfler belirtmelisiniz.");
|
|
419
|
+
const anagrams = await TDK.findAnagrams(word);
|
|
420
|
+
printResult(anagrams, () => {
|
|
421
|
+
if (anagrams.length === 0) {
|
|
422
|
+
console.log("Anagram veya bu harflerle t\xFCretilebilecek kelime bulunamad\u0131.");
|
|
423
|
+
} else {
|
|
424
|
+
const clean = word.trim().toLocaleLowerCase("tr-TR").replace(/[^a-zçğıöşüâîû]/gi, "");
|
|
425
|
+
const hasExact = anagrams.some((a) => a.length === clean.length);
|
|
426
|
+
const title = hasExact ? `Anagramlar (${anagrams.length}):` : `Birebir anagram bulunamad\u0131. Bu harflerle t\xFCretilen kelimeler (${anagrams.length}):`;
|
|
427
|
+
console.log(c.bold(title));
|
|
428
|
+
anagrams.forEach((a, i) => console.log(`${i + 1}. ${c.green(a)} ${c.dim(`(${a.length} harf)`)}`));
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
break;
|
|
432
|
+
}
|
|
433
|
+
case "kafiye":
|
|
434
|
+
case "rhyme": {
|
|
435
|
+
if (!word)
|
|
436
|
+
throw new Error("Kelime belirtmelisiniz.");
|
|
437
|
+
const rhymes = await TDK.findRhymes(word);
|
|
438
|
+
printResult(rhymes, () => {
|
|
439
|
+
if (rhymes.length === 0) {
|
|
440
|
+
console.log("Kafiye bulunamad\u0131.");
|
|
441
|
+
} else {
|
|
442
|
+
console.log(c.bold(`Kafiyeli Kelimeler (${rhymes.length}):`));
|
|
443
|
+
rhymes.forEach((r, i) => console.log(`${i + 1}. ${c.yellow(r)}`));
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
case "denetle":
|
|
449
|
+
case "proofread": {
|
|
450
|
+
if (!word)
|
|
451
|
+
throw new Error("Metin belirtmelisiniz.");
|
|
452
|
+
const result = await TDK.proofread(word);
|
|
453
|
+
printResult(result, () => {
|
|
454
|
+
if (result.isCorrect) {
|
|
455
|
+
console.log(c.green("\u2713 Metinde imla veya ba\u011Fla\xE7 hatas\u0131 tespit edilmedi."));
|
|
456
|
+
} else {
|
|
457
|
+
console.log(c.bold(c.red(`Metinde ${result.issues.length} olas\u0131 sorun tespit edildi:`)));
|
|
458
|
+
result.issues.forEach((issue, i) => {
|
|
459
|
+
const label = c.yellow(`[${issue.type}]`);
|
|
460
|
+
const sug = issue.suggestion ? c.green(` -> \xD6neri: ${issue.suggestion}`) : "";
|
|
461
|
+
console.log(`${i + 1}. ${label} "${c.bold(issue.word)}": ${issue.message}${sug}`);
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
break;
|
|
466
|
+
}
|
|
467
|
+
case "repl": {
|
|
468
|
+
await startRepl();
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
259
471
|
case "kubbealti": {
|
|
260
472
|
if (!word)
|
|
261
473
|
throw new Error("Kelime belirtmelisiniz.");
|
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;
|
|
@@ -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 };
|