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/test/morphology.test.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
const assert = require("node:assert");
|
|
2
|
-
const {
|
|
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,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
|
+
});
|