tdk-api-wrapper 1.4.0 → 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 +43 -14
- package/dist/{chunk-5TYJDVHK.mjs → chunk-7KJHYRJZ.mjs} +426 -15
- package/dist/cli.js +559 -19
- package/dist/cli.mjs +180 -5
- package/dist/index.d.mts +119 -1
- package/dist/index.d.ts +119 -1
- package/dist/index.js +430 -16
- package/dist/index.mjs +9 -3
- package/package.json +2 -2
- package/src/cli.ts +185 -4
- package/src/index.ts +1 -1
- package/src/morphology.ts +115 -5
- package/src/tdk.ts +428 -12
- package/src/types.ts +38 -0
- package/test/grammar.test.js +52 -0
- package/test/morphology.test.js +25 -1
- 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,6 +23,7 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
14
23
|
"ornek",
|
|
15
24
|
"hece",
|
|
16
25
|
"uyum",
|
|
26
|
+
"kucukuyum",
|
|
17
27
|
"yazim",
|
|
18
28
|
"kok",
|
|
19
29
|
"stem",
|
|
@@ -28,6 +38,14 @@ var KNOWN_COMMANDS = /* @__PURE__ */ new Set([
|
|
|
28
38
|
"karsilastir",
|
|
29
39
|
"analiz",
|
|
30
40
|
"oneri",
|
|
41
|
+
"bulmaca",
|
|
42
|
+
"pattern",
|
|
43
|
+
"anagram",
|
|
44
|
+
"kafiye",
|
|
45
|
+
"rhyme",
|
|
46
|
+
"denetle",
|
|
47
|
+
"proofread",
|
|
48
|
+
"repl",
|
|
31
49
|
"kubbealti",
|
|
32
50
|
"nisanyan",
|
|
33
51
|
"viki"
|
|
@@ -49,17 +67,93 @@ function printError(message) {
|
|
|
49
67
|
if (jsonMode) {
|
|
50
68
|
console.log(JSON.stringify({ error: message }));
|
|
51
69
|
} else {
|
|
52
|
-
console.log(`Hata: ${message}`);
|
|
70
|
+
console.log(c.red(`Hata: ${message}`));
|
|
53
71
|
}
|
|
54
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
|
+
}
|
|
55
137
|
async function run() {
|
|
56
|
-
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") {
|
|
57
151
|
console.log("Kullan\u0131m: tdk [komut] <kelime> [--json]");
|
|
58
152
|
console.log(
|
|
59
|
-
"Komutlar: ara, anlam, koken, ornek, hece, uyum, yazim, kok, deyim, 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"
|
|
60
154
|
);
|
|
61
155
|
console.log("Not: Komut belirtilmezse do\u011Frudan kelime anlam\u0131 aran\u0131r (\xF6rn: tdk selam)");
|
|
62
|
-
process.exit(
|
|
156
|
+
process.exit(0);
|
|
63
157
|
}
|
|
64
158
|
TDK.enableCache(false);
|
|
65
159
|
try {
|
|
@@ -118,6 +212,17 @@ async function run() {
|
|
|
118
212
|
);
|
|
119
213
|
break;
|
|
120
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
|
+
}
|
|
121
226
|
case "yazim": {
|
|
122
227
|
if (!word)
|
|
123
228
|
throw new Error("Kelime belirtmelisiniz.");
|
|
@@ -293,6 +398,76 @@ async function run() {
|
|
|
293
398
|
});
|
|
294
399
|
break;
|
|
295
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
|
+
}
|
|
296
471
|
case "kubbealti": {
|
|
297
472
|
if (!word)
|
|
298
473
|
throw new Error("Kelime belirtmelisiniz.");
|
package/dist/index.d.mts
CHANGED
|
@@ -123,6 +123,7 @@ interface WordComparisonSide {
|
|
|
123
123
|
origin: string | null;
|
|
124
124
|
syllables: string[];
|
|
125
125
|
harmony: boolean;
|
|
126
|
+
labialHarmony?: boolean;
|
|
126
127
|
}
|
|
127
128
|
interface WordComparison {
|
|
128
129
|
a: WordComparisonSide;
|
|
@@ -136,6 +137,36 @@ interface WordAnalysis {
|
|
|
136
137
|
root?: string;
|
|
137
138
|
isInflected?: boolean;
|
|
138
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;
|
|
169
|
+
}
|
|
139
170
|
interface KubbealtiEntry {
|
|
140
171
|
kelime: string;
|
|
141
172
|
anlam: string;
|
|
@@ -168,12 +199,19 @@ declare class TDK {
|
|
|
168
199
|
* fail-closed contract as the rest of this file's fragile integrations.
|
|
169
200
|
*/
|
|
170
201
|
private static readonly KUBBEALTI_EXTRA_CA;
|
|
202
|
+
private static defaultTimeoutMs;
|
|
203
|
+
private static defaultRetries;
|
|
204
|
+
private static maxCacheSize;
|
|
171
205
|
private static isCacheEnabled;
|
|
172
206
|
private static wordCache;
|
|
173
207
|
private static dailyContentCache;
|
|
174
208
|
private static autocompleteCache;
|
|
175
209
|
private static autocompleteSet;
|
|
176
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;
|
|
177
215
|
/**
|
|
178
216
|
* Enables or disables in-memory caching for API requests.
|
|
179
217
|
*/
|
|
@@ -182,7 +220,12 @@ declare class TDK {
|
|
|
182
220
|
* Clears the internal cache.
|
|
183
221
|
*/
|
|
184
222
|
static clearCache(): void;
|
|
223
|
+
private static setBoundedCache;
|
|
185
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;
|
|
186
229
|
/**
|
|
187
230
|
* Fetches detailed information for a given word from the TDK Dictionary.
|
|
188
231
|
*/
|
|
@@ -471,6 +514,8 @@ declare class TDK {
|
|
|
471
514
|
static getWordsBatch(words: string[]): Promise<WordInfo[][]>;
|
|
472
515
|
/**
|
|
473
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).
|
|
474
519
|
*/
|
|
475
520
|
static syllabicate(word: string): string[];
|
|
476
521
|
/**
|
|
@@ -480,6 +525,65 @@ declare class TDK {
|
|
|
480
525
|
* (dotless) as the front vowel "i" (dotted).
|
|
481
526
|
*/
|
|
482
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;
|
|
483
587
|
}
|
|
484
588
|
|
|
485
589
|
/**
|
|
@@ -537,6 +641,20 @@ declare function restoreConsonantSoftening(stem: string): string[];
|
|
|
537
641
|
* This restores the harmonic dropped vowel between the final consonant cluster.
|
|
538
642
|
*/
|
|
539
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[];
|
|
540
658
|
/**
|
|
541
659
|
* Restores verb infinitive headword form (-mek / -mak):
|
|
542
660
|
* Since TDK registers verbs in their infinitive form (e.g. okumak, gelmek, yazmak),
|
|
@@ -557,4 +675,4 @@ declare function restoreInfinitive(stem: string): string[];
|
|
|
557
675
|
*/
|
|
558
676
|
declare function getStemCandidates(word: string, minStemLength?: number, maxDepth?: number): string[];
|
|
559
677
|
|
|
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 };
|
|
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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -123,6 +123,7 @@ interface WordComparisonSide {
|
|
|
123
123
|
origin: string | null;
|
|
124
124
|
syllables: string[];
|
|
125
125
|
harmony: boolean;
|
|
126
|
+
labialHarmony?: boolean;
|
|
126
127
|
}
|
|
127
128
|
interface WordComparison {
|
|
128
129
|
a: WordComparisonSide;
|
|
@@ -136,6 +137,36 @@ interface WordAnalysis {
|
|
|
136
137
|
root?: string;
|
|
137
138
|
isInflected?: boolean;
|
|
138
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;
|
|
169
|
+
}
|
|
139
170
|
interface KubbealtiEntry {
|
|
140
171
|
kelime: string;
|
|
141
172
|
anlam: string;
|
|
@@ -168,12 +199,19 @@ declare class TDK {
|
|
|
168
199
|
* fail-closed contract as the rest of this file's fragile integrations.
|
|
169
200
|
*/
|
|
170
201
|
private static readonly KUBBEALTI_EXTRA_CA;
|
|
202
|
+
private static defaultTimeoutMs;
|
|
203
|
+
private static defaultRetries;
|
|
204
|
+
private static maxCacheSize;
|
|
171
205
|
private static isCacheEnabled;
|
|
172
206
|
private static wordCache;
|
|
173
207
|
private static dailyContentCache;
|
|
174
208
|
private static autocompleteCache;
|
|
175
209
|
private static autocompleteSet;
|
|
176
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;
|
|
177
215
|
/**
|
|
178
216
|
* Enables or disables in-memory caching for API requests.
|
|
179
217
|
*/
|
|
@@ -182,7 +220,12 @@ declare class TDK {
|
|
|
182
220
|
* Clears the internal cache.
|
|
183
221
|
*/
|
|
184
222
|
static clearCache(): void;
|
|
223
|
+
private static setBoundedCache;
|
|
185
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;
|
|
186
229
|
/**
|
|
187
230
|
* Fetches detailed information for a given word from the TDK Dictionary.
|
|
188
231
|
*/
|
|
@@ -471,6 +514,8 @@ declare class TDK {
|
|
|
471
514
|
static getWordsBatch(words: string[]): Promise<WordInfo[][]>;
|
|
472
515
|
/**
|
|
473
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).
|
|
474
519
|
*/
|
|
475
520
|
static syllabicate(word: string): string[];
|
|
476
521
|
/**
|
|
@@ -480,6 +525,65 @@ declare class TDK {
|
|
|
480
525
|
* (dotless) as the front vowel "i" (dotted).
|
|
481
526
|
*/
|
|
482
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;
|
|
483
587
|
}
|
|
484
588
|
|
|
485
589
|
/**
|
|
@@ -537,6 +641,20 @@ declare function restoreConsonantSoftening(stem: string): string[];
|
|
|
537
641
|
* This restores the harmonic dropped vowel between the final consonant cluster.
|
|
538
642
|
*/
|
|
539
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[];
|
|
540
658
|
/**
|
|
541
659
|
* Restores verb infinitive headword form (-mek / -mak):
|
|
542
660
|
* Since TDK registers verbs in their infinitive form (e.g. okumak, gelmek, yazmak),
|
|
@@ -557,4 +675,4 @@ declare function restoreInfinitive(stem: string): string[];
|
|
|
557
675
|
*/
|
|
558
676
|
declare function getStemCandidates(word: string, minStemLength?: number, maxDepth?: number): string[];
|
|
559
677
|
|
|
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 };
|
|
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 };
|