tdk-api-wrapper 1.3.0 → 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 +15 -7
- package/dist/{chunk-SLNXKZKR.mjs → chunk-5TYJDVHK.mjs} +695 -25
- package/dist/cli.js +728 -28
- package/dist/cli.mjs +41 -4
- package/dist/index.d.mts +113 -5
- package/dist/index.d.ts +113 -5
- package/dist/index.js +704 -27
- 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 +211 -21
- package/src/types.ts +11 -0
- package/test/morphology.test.js +105 -0
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 {
|
|
@@ -121,6 +130,8 @@ export interface WordAnalysis {
|
|
|
121
130
|
found: boolean;
|
|
122
131
|
meaning: string | null;
|
|
123
132
|
origin: string | null;
|
|
133
|
+
root?: string;
|
|
134
|
+
isInflected?: boolean;
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
export interface KubbealtiEntry {
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
const assert = require("node:assert");
|
|
2
|
+
const { TDK, getStemCandidates, restoreConsonantSoftening, restoreVowelDrop, restoreInfinitive } = require("../dist/index.js");
|
|
3
|
+
|
|
4
|
+
async function runTests() {
|
|
5
|
+
console.log("=== Running Morphology Unit & Integration Tests ===");
|
|
6
|
+
|
|
7
|
+
// 1. Phonology helpers
|
|
8
|
+
console.log("1. Testing phonology helper functions...");
|
|
9
|
+
assert.deepStrictEqual(restoreConsonantSoftening("kitab"), ["kitap"]);
|
|
10
|
+
assert.deepStrictEqual(restoreConsonantSoftening("çocuğ"), ["çocuk"]);
|
|
11
|
+
assert.deepStrictEqual(restoreConsonantSoftening("ağac"), ["ağaç"]);
|
|
12
|
+
assert.deepStrictEqual(restoreConsonantSoftening("kanad"), ["kanat"]);
|
|
13
|
+
assert.deepStrictEqual(restoreConsonantSoftening("reng"), ["renk"]);
|
|
14
|
+
assert.deepStrictEqual(restoreVowelDrop("akl"), ["akıl"]);
|
|
15
|
+
assert.deepStrictEqual(restoreVowelDrop("şehr"), ["şehir"]);
|
|
16
|
+
assert.deepStrictEqual(restoreVowelDrop("omz"), ["omuz"]);
|
|
17
|
+
assert.deepStrictEqual(restoreInfinitive("oku"), ["okumak"]);
|
|
18
|
+
assert.deepStrictEqual(restoreInfinitive("gel"), ["gelmek"]);
|
|
19
|
+
console.log(" ✓ Phonology helpers passed.");
|
|
20
|
+
|
|
21
|
+
// 2. Candidate generation
|
|
22
|
+
console.log("2. Testing getStemCandidates...");
|
|
23
|
+
const c1 = getStemCandidates("halılarımızın");
|
|
24
|
+
assert(c1.includes("halı"), "halılarımızın must contain halı");
|
|
25
|
+
|
|
26
|
+
const c2 = getStemCandidates("kitabımız");
|
|
27
|
+
assert(c2.includes("kitap"), "kitabımız must contain kitap");
|
|
28
|
+
|
|
29
|
+
const c3 = getStemCandidates("çocuğa");
|
|
30
|
+
assert(c3.includes("çocuk"), "çocuğa must contain çocuk");
|
|
31
|
+
|
|
32
|
+
const c4 = getStemCandidates("şehre");
|
|
33
|
+
assert(c4.includes("şehir"), "şehre must contain şehir");
|
|
34
|
+
|
|
35
|
+
const c5 = getStemCandidates("aklımızda");
|
|
36
|
+
assert(c5.includes("akıl"), "aklımızda must contain akıl");
|
|
37
|
+
|
|
38
|
+
const c6 = getStemCandidates("okuyoruz");
|
|
39
|
+
assert(c6.includes("okumak"), "okuyoruz must contain okumak");
|
|
40
|
+
|
|
41
|
+
const c7 = getStemCandidates("gideceğiz");
|
|
42
|
+
assert(c7.includes("gitmek"), "gideceğiz must contain gitmek");
|
|
43
|
+
|
|
44
|
+
const c8 = getStemCandidates("İstanbul'da");
|
|
45
|
+
assert(c8.includes("istanbul"), "İstanbul'da must contain istanbul");
|
|
46
|
+
console.log(" ✓ Candidate generation passed.");
|
|
47
|
+
|
|
48
|
+
// 3. TDK.isHeadword
|
|
49
|
+
console.log("3. Testing TDK.isHeadword...");
|
|
50
|
+
assert.strictEqual(await TDK.isHeadword("halı"), true);
|
|
51
|
+
assert.strictEqual(await TDK.isHeadword("kitap"), true);
|
|
52
|
+
assert.strictEqual(await TDK.isHeadword("okumak"), true);
|
|
53
|
+
assert.strictEqual(await TDK.isHeadword("gelmek"), true);
|
|
54
|
+
assert.strictEqual(await TDK.isHeadword("asdfqwertyzzz"), false);
|
|
55
|
+
console.log(" ✓ TDK.isHeadword passed.");
|
|
56
|
+
|
|
57
|
+
// 4. TDK.findRoot
|
|
58
|
+
console.log("4. Testing TDK.findRoot...");
|
|
59
|
+
assert.strictEqual(await TDK.findRoot("halılarımızın"), "halı");
|
|
60
|
+
assert.strictEqual(await TDK.findRoot("kitabımız"), "kitap");
|
|
61
|
+
assert.strictEqual(await TDK.findRoot("okuyoruz"), "okumak");
|
|
62
|
+
assert.strictEqual(await TDK.findRoot("çocukların"), "çocuk");
|
|
63
|
+
assert.strictEqual(await TDK.findRoot("kitap"), "kitap");
|
|
64
|
+
console.log(" ✓ TDK.findRoot passed.");
|
|
65
|
+
|
|
66
|
+
// 5. TDK.stem
|
|
67
|
+
console.log("5. Testing TDK.stem...");
|
|
68
|
+
const stem1 = await TDK.stem("halılarımızın");
|
|
69
|
+
assert(stem1 !== null);
|
|
70
|
+
assert.strictEqual(stem1.root, "halı");
|
|
71
|
+
assert.strictEqual(stem1.isInflected, true);
|
|
72
|
+
|
|
73
|
+
const stem2 = await TDK.stem("kitap");
|
|
74
|
+
assert(stem2 !== null);
|
|
75
|
+
assert.strictEqual(stem2.root, "kitap");
|
|
76
|
+
assert.strictEqual(stem2.isInflected, false);
|
|
77
|
+
console.log(" ✓ TDK.stem passed.");
|
|
78
|
+
|
|
79
|
+
// 6. TDK.checkSpelling with morphology fallback
|
|
80
|
+
console.log("6. Testing TDK.checkSpelling with morphology fallback...");
|
|
81
|
+
const sp1 = await TDK.checkSpelling("halılarımızın");
|
|
82
|
+
assert.strictEqual(sp1.isCorrect, true);
|
|
83
|
+
assert.strictEqual(sp1.isInflected, true);
|
|
84
|
+
assert.strictEqual(sp1.root, "halı");
|
|
85
|
+
|
|
86
|
+
const sp2 = await TDK.checkSpelling("kitabımız");
|
|
87
|
+
assert.strictEqual(sp2.isCorrect, true);
|
|
88
|
+
assert.strictEqual(sp2.isInflected, true);
|
|
89
|
+
assert.strictEqual(sp2.root, "kitap");
|
|
90
|
+
|
|
91
|
+
const sp3 = await TDK.checkSpelling("yanlız");
|
|
92
|
+
assert.strictEqual(sp3.isCorrect, false);
|
|
93
|
+
assert.strictEqual(sp3.suggestion, "yalnız");
|
|
94
|
+
|
|
95
|
+
const sp4 = await TDK.checkSpelling("asdfxyz12345");
|
|
96
|
+
assert.strictEqual(sp4.isCorrect, false);
|
|
97
|
+
console.log(" ✓ TDK.checkSpelling passed.");
|
|
98
|
+
|
|
99
|
+
console.log("\n All morphology tests passed successfully!");
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
runTests().catch((err) => {
|
|
103
|
+
console.error("Test failed:", err);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
});
|