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/src/types.ts CHANGED
@@ -85,6 +85,15 @@ export interface SpellCheckResult {
85
85
  isCorrect: boolean;
86
86
  word: string;
87
87
  suggestion?: string;
88
+ isInflected?: boolean;
89
+ root?: string;
90
+ }
91
+
92
+ export interface StemResult {
93
+ word: string;
94
+ root: string;
95
+ isInflected: boolean;
96
+ candidates?: string[];
88
97
  }
89
98
 
90
99
  export interface WordOfTheDay {
@@ -109,6 +118,7 @@ export interface WordComparisonSide {
109
118
  origin: string | null;
110
119
  syllables: string[];
111
120
  harmony: boolean;
121
+ labialHarmony?: boolean;
112
122
  }
113
123
 
114
124
  export interface WordComparison {
@@ -121,6 +131,44 @@ export interface WordAnalysis {
121
131
  found: boolean;
122
132
  meaning: string | null;
123
133
  origin: string | null;
134
+ root?: string;
135
+ isInflected?: boolean;
136
+ }
137
+
138
+ export interface ProofreadIssue {
139
+ type: "spelling" | "conjunction_da" | "conjunction_ki" | "question_particle";
140
+ word: string;
141
+ startIndex: number;
142
+ endIndex: number;
143
+ suggestion?: string;
144
+ message: string;
145
+ }
146
+
147
+ export interface ProofreadResult {
148
+ text: string;
149
+ issues: ProofreadIssue[];
150
+ isCorrect: boolean;
151
+ }
152
+
153
+ export interface PatternSearchOptions {
154
+ maxResults?: number;
155
+ }
156
+
157
+ export interface AnagramOptions {
158
+ exactLength?: boolean;
159
+ maxResults?: number;
160
+ }
161
+
162
+ export interface RhymeOptions {
163
+ minLetters?: number;
164
+ maxResults?: number;
165
+ }
166
+
167
+ export interface TDKConfig {
168
+ timeoutMs?: number;
169
+ retries?: number;
170
+ cache?: boolean;
171
+ maxCacheSize?: number;
124
172
  }
125
173
 
126
174
  export interface KubbealtiEntry {
@@ -134,3 +182,4 @@ export interface WiktionaryEntry {
134
182
  }
135
183
 
136
184
  export type TDKResponse = WordInfo[] | { error: string };
185
+
@@ -0,0 +1,52 @@
1
+ const assert = require("node:assert");
2
+ const { TDK } = require("../dist/index.js");
3
+
4
+ async function runTests() {
5
+ console.log("=== Running Grammar & Phonology Unit Tests ===");
6
+
7
+ // 1. Büyük Ünlü Uyumu (Major Vowel Harmony)
8
+ console.log("1. Testing checkVowelHarmony (Büyük Ünlü Uyumu)...");
9
+ assert.strictEqual(TDK.checkVowelHarmony("adım"), true);
10
+ assert.strictEqual(TDK.checkVowelHarmony("kapı"), true);
11
+ assert.strictEqual(TDK.checkVowelHarmony("gözlük"), true);
12
+ assert.strictEqual(TDK.checkVowelHarmony("otobüs"), false);
13
+ assert.strictEqual(TDK.checkVowelHarmony("kalem"), false);
14
+ assert.strictEqual(TDK.checkVowelHarmony("kitap"), false);
15
+ assert.strictEqual(TDK.checkVowelHarmony("ev"), true);
16
+ console.log(" ✓ checkVowelHarmony passed.");
17
+
18
+ // 2. Küçük Ünlü Uyumu (Minor Vowel / Labial Harmony)
19
+ console.log("2. Testing checkLabialHarmony (Küçük Ünlü Uyumu)...");
20
+ assert.strictEqual(TDK.checkLabialHarmony("elma"), true);
21
+ assert.strictEqual(TDK.checkLabialHarmony("kalem"), true);
22
+ assert.strictEqual(TDK.checkLabialHarmony("odun"), true);
23
+ assert.strictEqual(TDK.checkLabialHarmony("kömür"), true);
24
+ assert.strictEqual(TDK.checkLabialHarmony("çocuk"), true);
25
+ assert.strictEqual(TDK.checkLabialHarmony("armut"), false);
26
+ assert.strictEqual(TDK.checkLabialHarmony("yağmur"), false);
27
+ assert.strictEqual(TDK.checkLabialHarmony("tavuk"), false);
28
+ assert.strictEqual(TDK.checkLabialHarmony("doktor"), false);
29
+ assert.strictEqual(TDK.checkLabialHarmony("horoz"), false);
30
+ assert.strictEqual(TDK.checkLabialHarmony("müzik"), false);
31
+ assert.strictEqual(TDK.checkLabialHarmony("ev"), true);
32
+ console.log(" ✓ checkLabialHarmony passed.");
33
+
34
+ // 3. Heceleme (Syllabification)
35
+ console.log("3. Testing syllabicate...");
36
+ assert.deepStrictEqual(TDK.syllabicate("kalem"), ["ka", "lem"]);
37
+ assert.deepStrictEqual(TDK.syllabicate("ilkokul"), ["il", "ko", "kul"]);
38
+ assert.deepStrictEqual(TDK.syllabicate("muvaffakiyet"), ["mu", "vaf", "fa", "ki", "yet"]);
39
+ assert.deepStrictEqual(TDK.syllabicate("elektrik"), ["e", "lek", "trik"]);
40
+ assert.deepStrictEqual(TDK.syllabicate("kontrol"), ["kon", "trol"]);
41
+ assert.deepStrictEqual(TDK.syllabicate("orkestra"), ["or", "kes", "tra"]);
42
+ assert.deepStrictEqual(TDK.syllabicate("kral"), ["kral"]);
43
+ assert.deepStrictEqual(TDK.syllabicate("tren"), ["tren"]);
44
+ console.log(" ✓ syllabicate passed.");
45
+
46
+ console.log("\n All grammar & phonology tests passed successfully!");
47
+ }
48
+
49
+ runTests().catch((err) => {
50
+ console.error("Test failed:", err);
51
+ process.exit(1);
52
+ });
@@ -0,0 +1,129 @@
1
+ const assert = require("node:assert");
2
+ const {
3
+ TDK,
4
+ getStemCandidates,
5
+ restoreConsonantSoftening,
6
+ restoreVowelDrop,
7
+ restoreInfinitive,
8
+ restoreGemination,
9
+ restoreVowelNarrowing,
10
+ } = require("../dist/index.js");
11
+
12
+ async function runTests() {
13
+ console.log("=== Running Morphology Unit & Integration Tests ===");
14
+
15
+ // 1. Phonology helpers
16
+ console.log("1. Testing phonology helper functions...");
17
+ assert.deepStrictEqual(restoreConsonantSoftening("kitab"), ["kitap"]);
18
+ assert.deepStrictEqual(restoreConsonantSoftening("çocuğ"), ["çocuk"]);
19
+ assert.deepStrictEqual(restoreConsonantSoftening("ağac"), ["ağaç"]);
20
+ assert.deepStrictEqual(restoreConsonantSoftening("kanad"), ["kanat"]);
21
+ assert.deepStrictEqual(restoreConsonantSoftening("reng"), ["renk"]);
22
+ assert.deepStrictEqual(restoreVowelDrop("akl"), ["akıl"]);
23
+ assert.deepStrictEqual(restoreVowelDrop("şehr"), ["şehir"]);
24
+ assert.deepStrictEqual(restoreVowelDrop("omz"), ["omuz"]);
25
+ assert.deepStrictEqual(restoreInfinitive("oku"), ["okumak"]);
26
+ assert.deepStrictEqual(restoreInfinitive("gel"), ["gelmek"]);
27
+ assert.deepStrictEqual(restoreGemination("hakk"), ["hak"]);
28
+ assert.deepStrictEqual(restoreGemination("hiss"), ["his"]);
29
+ assert.deepStrictEqual(restoreGemination("redd"), ["red", "ret"]);
30
+ assert.deepStrictEqual(restoreGemination("aff"), ["af"]);
31
+ assert.deepStrictEqual(restoreVowelNarrowing("başlı"), ["başla"]);
32
+ assert.deepStrictEqual(restoreVowelNarrowing("bekli"), ["bekle"]);
33
+ assert.deepStrictEqual(restoreVowelNarrowing("di"), ["de"]);
34
+ assert.deepStrictEqual(restoreVowelNarrowing("yi"), ["ye"]);
35
+ console.log(" ✓ Phonology helpers passed.");
36
+
37
+ // 2. Candidate generation
38
+ console.log("2. Testing getStemCandidates...");
39
+ const c1 = getStemCandidates("halılarımızın");
40
+ assert(c1.includes("halı"), "halılarımızın must contain halı");
41
+
42
+ const c2 = getStemCandidates("kitabımız");
43
+ assert(c2.includes("kitap"), "kitabımız must contain kitap");
44
+
45
+ const c3 = getStemCandidates("çocuğa");
46
+ assert(c3.includes("çocuk"), "çocuğa must contain çocuk");
47
+
48
+ const c4 = getStemCandidates("şehre");
49
+ assert(c4.includes("şehir"), "şehre must contain şehir");
50
+
51
+ const c5 = getStemCandidates("aklımızda");
52
+ assert(c5.includes("akıl"), "aklımızda must contain akıl");
53
+
54
+ const c6 = getStemCandidates("okuyoruz");
55
+ assert(c6.includes("okumak"), "okuyoruz must contain okumak");
56
+
57
+ const c7 = getStemCandidates("gideceğiz");
58
+ assert(c7.includes("gitmek"), "gideceğiz must contain gitmek");
59
+
60
+ const c8 = getStemCandidates("İstanbul'da");
61
+ assert(c8.includes("istanbul"), "İstanbul'da must contain istanbul");
62
+ console.log(" ✓ Candidate generation passed.");
63
+
64
+ // 3. TDK.isHeadword
65
+ console.log("3. Testing TDK.isHeadword...");
66
+ assert.strictEqual(await TDK.isHeadword("halı"), true);
67
+ assert.strictEqual(await TDK.isHeadword("kitap"), true);
68
+ assert.strictEqual(await TDK.isHeadword("okumak"), true);
69
+ assert.strictEqual(await TDK.isHeadword("gelmek"), true);
70
+ assert.strictEqual(await TDK.isHeadword("asdfqwertyzzz"), false);
71
+ console.log(" ✓ TDK.isHeadword passed.");
72
+
73
+ // 4. TDK.findRoot
74
+ console.log("4. Testing TDK.findRoot...");
75
+ assert.strictEqual(await TDK.findRoot("halılarımızın"), "halı");
76
+ assert.strictEqual(await TDK.findRoot("kitabımız"), "kitap");
77
+ assert.strictEqual(await TDK.findRoot("okuyoruz"), "okumak");
78
+ assert.strictEqual(await TDK.findRoot("çocukların"), "çocuk");
79
+ assert.strictEqual(await TDK.findRoot("kitap"), "kitap");
80
+ assert.strictEqual(await TDK.findRoot("hakkımızda"), "hak");
81
+ assert.strictEqual(await TDK.findRoot("başlıyor"), "başlamak");
82
+ assert.strictEqual(await TDK.findRoot("diyor"), "demek");
83
+ console.log(" ✓ TDK.findRoot passed.");
84
+
85
+ // 5. TDK.stem
86
+ console.log("5. Testing TDK.stem...");
87
+ const stem1 = await TDK.stem("halılarımızın");
88
+ assert(stem1 !== null);
89
+ assert.strictEqual(stem1.root, "halı");
90
+ assert.strictEqual(stem1.isInflected, true);
91
+
92
+ const stem2 = await TDK.stem("kitap");
93
+ assert(stem2 !== null);
94
+ assert.strictEqual(stem2.root, "kitap");
95
+ assert.strictEqual(stem2.isInflected, false);
96
+
97
+ const stem3 = await TDK.stem("hakkımızda");
98
+ assert(stem3 !== null);
99
+ assert.strictEqual(stem3.root, "hak");
100
+ assert.strictEqual(stem3.isInflected, true);
101
+ console.log(" ✓ TDK.stem passed.");
102
+
103
+ // 6. TDK.checkSpelling with morphology fallback
104
+ console.log("6. Testing TDK.checkSpelling with morphology fallback...");
105
+ const sp1 = await TDK.checkSpelling("halılarımızın");
106
+ assert.strictEqual(sp1.isCorrect, true);
107
+ assert.strictEqual(sp1.isInflected, true);
108
+ assert.strictEqual(sp1.root, "halı");
109
+
110
+ const sp2 = await TDK.checkSpelling("kitabımız");
111
+ assert.strictEqual(sp2.isCorrect, true);
112
+ assert.strictEqual(sp2.isInflected, true);
113
+ assert.strictEqual(sp2.root, "kitap");
114
+
115
+ const sp3 = await TDK.checkSpelling("yanlız");
116
+ assert.strictEqual(sp3.isCorrect, false);
117
+ assert.strictEqual(sp3.suggestion, "yalnız");
118
+
119
+ const sp4 = await TDK.checkSpelling("asdfxyz12345");
120
+ assert.strictEqual(sp4.isCorrect, false);
121
+ console.log(" ✓ TDK.checkSpelling passed.");
122
+
123
+ console.log("\n All morphology tests passed successfully!");
124
+ }
125
+
126
+ runTests().catch((err) => {
127
+ console.error("Test failed:", err);
128
+ process.exit(1);
129
+ });
@@ -0,0 +1,60 @@
1
+ const assert = require("node:assert");
2
+ const { TDK } = require("../dist/index.js");
3
+
4
+ async function runTests() {
5
+ console.log("=== Running Proofread Unit & Integration Tests ===");
6
+
7
+ // 1. Question Particle 'mi/mı/mu/mü'
8
+ console.log("1. Testing question particle detection...");
9
+ const q1 = await TDK.proofread("Sen dün okula gittinmi?");
10
+ assert.strictEqual(q1.isCorrect, false);
11
+ assert.strictEqual(q1.issues.length, 1);
12
+ assert.strictEqual(q1.issues[0].type, "question_particle");
13
+ assert.strictEqual(q1.issues[0].suggestion, "gittin mi");
14
+ console.log(" ✓ Question particle passed.");
15
+
16
+ // 2. Conjunction 'da/de'
17
+ console.log("2. Testing conjunction da/de detection...");
18
+ const d1 = await TDK.proofread("Sen gitsende ben kalacağım.");
19
+ assert.strictEqual(d1.isCorrect, false);
20
+ assert.strictEqual(d1.issues.length, 1);
21
+ assert.strictEqual(d1.issues[0].type, "conjunction_da");
22
+ assert.strictEqual(d1.issues[0].suggestion, "gitsen de");
23
+
24
+ // Normal locative 'evde' should NOT trigger issue
25
+ const d2 = await TDK.proofread("Bugün evde oturdum.");
26
+ assert.strictEqual(d2.isCorrect, true);
27
+ assert.strictEqual(d2.issues.length, 0);
28
+ console.log(" ✓ Conjunction da/de passed.");
29
+
30
+ // 3. Conjunction 'ki'
31
+ console.log("3. Testing conjunction ki detection...");
32
+ const k1 = await TDK.proofread("Anladımki beni dinlemiyorsun.");
33
+ assert.strictEqual(k1.isCorrect, false);
34
+ assert.strictEqual(k1.issues.length, 1);
35
+ assert.strictEqual(k1.issues[0].type, "conjunction_ki");
36
+ assert.strictEqual(k1.issues[0].suggestion, "anladım ki");
37
+
38
+ // SOMBAHÇEMİ exceptions like 'çünkü', 'oysaki' should NOT trigger issue
39
+ const k2 = await TDK.proofread("Oysaki seni çok sevmiştim çünkü güzeldin.");
40
+ assert.strictEqual(k2.isCorrect, true);
41
+ assert.strictEqual(k2.issues.length, 0);
42
+ console.log(" ✓ Conjunction ki passed.");
43
+
44
+ // 4. Combined sentence
45
+ console.log("4. Testing combined sentence proofread...");
46
+ const combo = await TDK.proofread("Gördümki gelmedin, bilsende gelirdin ve yaptınmı?");
47
+ assert.strictEqual(combo.isCorrect, false);
48
+ assert.strictEqual(combo.issues.length, 3);
49
+ assert.strictEqual(combo.issues.some((i) => i.type === "conjunction_ki"), true);
50
+ assert.strictEqual(combo.issues.some((i) => i.type === "conjunction_da"), true);
51
+ assert.strictEqual(combo.issues.some((i) => i.type === "question_particle"), true);
52
+ console.log(" ✓ Combined proofread passed.");
53
+
54
+ console.log("\n All proofread tests passed successfully!");
55
+ }
56
+
57
+ runTests().catch((err) => {
58
+ console.error("Test failed:", err);
59
+ process.exit(1);
60
+ });
@@ -0,0 +1,51 @@
1
+ const assert = require("node:assert");
2
+ const { TDK, TDKClient } = require("../dist/index.js");
3
+
4
+ async function runTests() {
5
+ console.log("=== Running Linguistic Tools & Client Tests ===");
6
+
7
+ // 1. Pattern / Wildcard Search
8
+ console.log("1. Testing patternSearch...");
9
+ const p1 = await TDK.patternSearch("k_l_m");
10
+ assert(p1.includes("kalem"), "k_l_m must contain kalem");
11
+ assert(p1.includes("kilim"), "k_l_m must contain kilim");
12
+
13
+ const p2 = await TDK.patternSearch("*istan");
14
+ assert(p2.some((w) => w.toLowerCase().endsWith("istan")), "*istan must match words ending with istan");
15
+ console.log(" ✓ patternSearch passed.");
16
+
17
+ // 2. Anagram Solver
18
+ console.log("2. Testing findAnagrams...");
19
+ const a1 = await TDK.findAnagrams("kalem");
20
+ assert(a1.includes("kelam"), "Anagrams of kalem must contain kelam");
21
+ assert(a1.includes("kemal"), "Anagrams of kalem must contain kemal");
22
+ console.log(" ✓ findAnagrams passed.");
23
+
24
+ // 3. Rhyme Finder
25
+ console.log("3. Testing findRhymes...");
26
+ const r1 = await TDK.findRhymes("bahar");
27
+ assert(r1.includes("sonbahar") || r1.includes("ilkbahar") || r1.includes("buhar"));
28
+ console.log(" ✓ findRhymes passed.");
29
+
30
+ // 4. Configuration & TDKClient
31
+ console.log("4. Testing TDK.configure and TDKClient...");
32
+ TDK.configure({ timeoutMs: 10000, retries: 2, maxCacheSize: 500 });
33
+
34
+ const client = new TDKClient({ timeoutMs: 5000, cache: true });
35
+ assert.strictEqual(typeof client.getWord, "function");
36
+ assert.strictEqual(typeof client.checkSpelling, "function");
37
+ assert.strictEqual(typeof client.findRoot, "function");
38
+ assert.strictEqual(typeof client.proofread, "function");
39
+ assert.strictEqual(typeof client.patternSearch, "function");
40
+ assert.strictEqual(typeof client.findAnagrams, "function");
41
+ assert.strictEqual(typeof client.findRhymes, "function");
42
+ assert.strictEqual(typeof client.checkLabialHarmony, "function");
43
+ console.log(" ✓ TDKClient passed.");
44
+
45
+ console.log("\n All linguistic tools & client tests passed successfully!");
46
+ }
47
+
48
+ runTests().catch((err) => {
49
+ console.error("Test failed:", err);
50
+ process.exit(1);
51
+ });