tdk-api-wrapper 1.4.0 → 1.5.1

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
@@ -118,6 +118,7 @@ export interface WordComparisonSide {
118
118
  origin: string | null;
119
119
  syllables: string[];
120
120
  harmony: boolean;
121
+ labialHarmony?: boolean;
121
122
  }
122
123
 
123
124
  export interface WordComparison {
@@ -134,6 +135,42 @@ export interface WordAnalysis {
134
135
  isInflected?: boolean;
135
136
  }
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;
172
+ }
173
+
137
174
  export interface KubbealtiEntry {
138
175
  kelime: string;
139
176
  anlam: string;
@@ -145,3 +182,4 @@ export interface WiktionaryEntry {
145
182
  }
146
183
 
147
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
+ });
@@ -1,5 +1,13 @@
1
1
  const assert = require("node:assert");
2
- const { TDK, getStemCandidates, restoreConsonantSoftening, restoreVowelDrop, restoreInfinitive } = require("../dist/index.js");
2
+ const {
3
+ TDK,
4
+ getStemCandidates,
5
+ restoreConsonantSoftening,
6
+ restoreVowelDrop,
7
+ restoreInfinitive,
8
+ restoreGemination,
9
+ restoreVowelNarrowing,
10
+ } = require("../dist/index.js");
3
11
 
4
12
  async function runTests() {
5
13
  console.log("=== Running Morphology Unit & Integration Tests ===");
@@ -16,6 +24,14 @@ async function runTests() {
16
24
  assert.deepStrictEqual(restoreVowelDrop("omz"), ["omuz"]);
17
25
  assert.deepStrictEqual(restoreInfinitive("oku"), ["okumak"]);
18
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"]);
19
35
  console.log(" ✓ Phonology helpers passed.");
20
36
 
21
37
  // 2. Candidate generation
@@ -61,6 +77,9 @@ async function runTests() {
61
77
  assert.strictEqual(await TDK.findRoot("okuyoruz"), "okumak");
62
78
  assert.strictEqual(await TDK.findRoot("çocukların"), "çocuk");
63
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");
64
83
  console.log(" ✓ TDK.findRoot passed.");
65
84
 
66
85
  // 5. TDK.stem
@@ -74,6 +93,11 @@ async function runTests() {
74
93
  assert(stem2 !== null);
75
94
  assert.strictEqual(stem2.root, "kitap");
76
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);
77
101
  console.log(" ✓ TDK.stem passed.");
78
102
 
79
103
  // 6. TDK.checkSpelling with morphology fallback
@@ -0,0 +1,88 @@
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
+ // 5. Şey detachment check (herşey, hersey, birşeyler -> her şey, bir şeyler)
55
+ console.log("5. Testing -şey detachment...");
56
+ const s1 = await TDK.proofread("burda herşey yolunda");
57
+ assert.strictEqual(s1.isCorrect, false);
58
+ assert.strictEqual(s1.issues.length, 2);
59
+ assert.strictEqual(s1.issues[0].word, "burda");
60
+ assert.strictEqual(s1.issues[0].suggestion, "burada");
61
+ assert.strictEqual(s1.issues[1].word, "herşey");
62
+ assert.strictEqual(s1.issues[1].suggestion, "her şey");
63
+
64
+ const s2 = await TDK.proofread("hersey çok güzel");
65
+ assert.strictEqual(s2.isCorrect, false);
66
+ assert.strictEqual(s2.issues[0].word, "hersey");
67
+ assert.strictEqual(s2.issues[0].suggestion, "her şey");
68
+ console.log(" ✓ -şey detachment passed.");
69
+
70
+ // 6. Erroneously separated compound phrases (hiç bir, bir çok, git gide)
71
+ console.log("6. Testing compound phrases...");
72
+ const p1 = await TDK.proofread("hiç bir şey bilmiyor");
73
+ assert.strictEqual(p1.isCorrect, false);
74
+ assert.strictEqual(p1.issues[0].word, "hiç bir");
75
+ assert.strictEqual(p1.issues[0].suggestion, "hiçbir");
76
+
77
+ const p2 = await TDK.proofread("yada gelme");
78
+ assert.strictEqual(p2.isCorrect, false);
79
+ assert.strictEqual(p2.issues[0].suggestion, "ya da");
80
+ console.log(" ✓ Compound phrases passed.");
81
+
82
+ console.log("\n All proofread tests passed successfully!");
83
+ }
84
+
85
+ runTests().catch((err) => {
86
+ console.error("Test failed:", err);
87
+ process.exit(1);
88
+ });
@@ -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
+ });