henkan 3.0.0 → 3.0.2
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 +1 -1
- package/dist/index.cjs.js +45 -69
- package/dist/index.cjs.js.map +2 -2
- package/dist/index.mjs +45 -69
- package/dist/index.mjs.map +2 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/functions/convertJMdict.md +1 -1
- package/docs/api/functions/convertJMnedict.md +1 -1
- package/docs/api/functions/convertJawiktionaryAsync.md +1 -1
- package/docs/api/functions/convertJawiktionarySync.md +1 -1
- package/docs/api/functions/generateAnkiNote.md +1 -1
- package/docs/api/functions/generateAnkiNotesFile.md +1 -1
- package/docs/api/functions/getKanji.md +1 -1
- package/docs/api/functions/getKanjiExtended.md +1 -1
- package/docs/api/functions/getName.md +1 -1
- package/docs/api/functions/getWord.md +1 -1
- package/docs/api/functions/getWordDefinitions.md +1 -1
- package/docs/api/functions/getWordDefinitionsWithFurigana.md +1 -1
- package/package.json +4 -4
- package/src/utils.ts +101 -179
package/README.md
CHANGED
|
@@ -33,7 +33,7 @@ pnpm add henkan
|
|
|
33
33
|
```
|
|
34
34
|
|
|
35
35
|
# Features
|
|
36
|
-
- JMdict, KANJIDIC, Tanaka Corpus, RADK and KRAD conversion
|
|
36
|
+
- JMdict, JMnedict, KANJIDIC, Tanaka Corpus, RADK and KRAD conversion
|
|
37
37
|
- User-friendly schemas for dictionary entries
|
|
38
38
|
- Anki note generation
|
|
39
39
|
- "Japanese definition"-"JMdict entry" pairing (using `ja.wiktionary.org` dumps)
|
package/dist/index.cjs.js
CHANGED
|
@@ -1383,33 +1383,27 @@ async function generateFurigana(text, bindedFunction) {
|
|
|
1383
1383
|
}
|
|
1384
1384
|
function getValidForms(readings, kanjiForms, wordIsCommon) {
|
|
1385
1385
|
const kanjiFormRestrictions = /* @__PURE__ */ new Set();
|
|
1386
|
-
const
|
|
1387
|
-
(
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
if (wordIsCommon === void 0 || reading.commonness !== void 0)
|
|
1386
|
+
const existValidReadings = readings.some(
|
|
1387
|
+
(r) => r.commonness !== void 0 || (r.notes === void 0 || !r.notes.some((note) => notSearchedForms.has(note))) && (r.kanjiFormRestrictions !== void 0 || wordIsCommon === void 0)
|
|
1388
|
+
);
|
|
1389
|
+
const validReadings = readings.filter((r) => {
|
|
1390
|
+
if (!existValidReadings || r.commonness !== void 0 || r.notes === void 0 || !r.notes.some((note) => notSearchedForms.has(note))) {
|
|
1391
|
+
if (r.kanjiFormRestrictions !== void 0) {
|
|
1392
|
+
for (const kfr of r.kanjiFormRestrictions)
|
|
1393
|
+
kanjiFormRestrictions.add(kfr);
|
|
1394
|
+
if (r.notes === void 0 || !r.notes.some((note) => notSearchedForms.has(note)))
|
|
1396
1395
|
return true;
|
|
1397
1396
|
}
|
|
1398
|
-
|
|
1397
|
+
if (!existValidReadings || wordIsCommon === void 0 || r.commonness !== void 0)
|
|
1398
|
+
return true;
|
|
1399
1399
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1400
|
+
return false;
|
|
1401
|
+
});
|
|
1402
|
+
const existValidKanjiForms = kanjiForms?.some(
|
|
1403
|
+
(kf) => kanjiFormRestrictions.has(kf.form) || kf.commonness !== void 0 || (kf.notes === void 0 || !kf.notes.some((note) => notSearchedForms.has(note))) && wordIsCommon === void 0
|
|
1403
1404
|
);
|
|
1404
1405
|
const validKanjiForms = kanjiForms?.filter(
|
|
1405
|
-
(
|
|
1406
|
-
if (index === 0) return true;
|
|
1407
|
-
if (existValidKf === true)
|
|
1408
|
-
return kanjiForm.notes === void 0 || !kanjiForm.notes.some(
|
|
1409
|
-
(note) => notSearchedForms.has(note)
|
|
1410
|
-
) && (wordIsCommon === void 0 || kanjiForm.commonness !== void 0) || kanjiFormRestrictions.has(kanjiForm.form);
|
|
1411
|
-
else return true;
|
|
1412
|
-
}
|
|
1406
|
+
(kf) => existValidKanjiForms === false || kanjiFormRestrictions.has(kf.form) || kf.commonness !== void 0 || (kf.notes === void 0 || !kf.notes.some((note) => notSearchedForms.has(note))) && wordIsCommon === void 0
|
|
1413
1407
|
);
|
|
1414
1408
|
return {
|
|
1415
1409
|
readings: validReadings,
|
|
@@ -1430,7 +1424,6 @@ function convertJMdict(xmlString, examples) {
|
|
|
1430
1424
|
(example) => example.parts.flatMap((part) => [
|
|
1431
1425
|
part.baseForm,
|
|
1432
1426
|
...part.reading !== void 0 ? [part.reading] : [],
|
|
1433
|
-
...part.inflectedForm !== void 0 ? [part.inflectedForm] : [],
|
|
1434
1427
|
...part.referenceID !== void 0 ? [part.referenceID] : []
|
|
1435
1428
|
])
|
|
1436
1429
|
)
|
|
@@ -1556,7 +1549,6 @@ function convertJMnedict(xmlString, examples) {
|
|
|
1556
1549
|
(example) => example.parts.flatMap((part) => [
|
|
1557
1550
|
part.baseForm,
|
|
1558
1551
|
...part.reading !== void 0 ? [part.reading] : [],
|
|
1559
|
-
...part.inflectedForm !== void 0 ? [part.inflectedForm] : [],
|
|
1560
1552
|
...part.referenceID !== void 0 ? [part.referenceID] : []
|
|
1561
1553
|
])
|
|
1562
1554
|
)
|
|
@@ -1900,14 +1892,6 @@ function createEntryMaps(jmDict, jmNedict, kanjiDic, tanakaExamples, wordDefinit
|
|
|
1900
1892
|
if (exList === void 0) partExamplesMap.set(part.reading, [ex]);
|
|
1901
1893
|
else exList.push(ex);
|
|
1902
1894
|
}
|
|
1903
|
-
if (part.inflectedForm !== void 0 && entryParts.has(part.inflectedForm)) {
|
|
1904
|
-
const exList = partExamplesMap.get(
|
|
1905
|
-
part.inflectedForm
|
|
1906
|
-
);
|
|
1907
|
-
if (exList === void 0)
|
|
1908
|
-
partExamplesMap.set(part.inflectedForm, [ex]);
|
|
1909
|
-
else exList.push(ex);
|
|
1910
|
-
}
|
|
1911
1895
|
if (part.referenceID !== void 0 && entryParts.has(part.referenceID)) {
|
|
1912
1896
|
const exList = partExamplesMap.get(
|
|
1913
1897
|
part.referenceID
|
|
@@ -1977,14 +1961,6 @@ function createEntryMaps(jmDict, jmNedict, kanjiDic, tanakaExamples, wordDefinit
|
|
|
1977
1961
|
if (exList === void 0) partExamplesMap.set(part.reading, [ex]);
|
|
1978
1962
|
else exList.push(ex);
|
|
1979
1963
|
}
|
|
1980
|
-
if (part.inflectedForm !== void 0 && entryParts.has(part.inflectedForm)) {
|
|
1981
|
-
const exList = partExamplesMap.get(
|
|
1982
|
-
part.inflectedForm
|
|
1983
|
-
);
|
|
1984
|
-
if (exList === void 0)
|
|
1985
|
-
partExamplesMap.set(part.inflectedForm, [ex]);
|
|
1986
|
-
else exList.push(ex);
|
|
1987
|
-
}
|
|
1988
1964
|
}
|
|
1989
1965
|
for (const name of jmNedict) {
|
|
1990
1966
|
const seenEx = /* @__PURE__ */ new Set();
|
|
@@ -2788,37 +2764,42 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2788
2764
|
const readingMatchingKanjiFormExamples = [];
|
|
2789
2765
|
let kanjiFormExamples = [];
|
|
2790
2766
|
let readingExamples = [];
|
|
2767
|
+
let hasKanjiFormExamplesWithTranslation = false;
|
|
2768
|
+
let hasReadingExamplesWithTranslation = false;
|
|
2791
2769
|
for (const example of exampleList)
|
|
2792
2770
|
for (let i = 0; i < example.parts.length; i++) {
|
|
2793
2771
|
if (seenPhrases.has(example.phrase)) break;
|
|
2794
|
-
const includesTranslation = meanings.some(
|
|
2795
|
-
(m) => example.translation.includes(m)
|
|
2796
|
-
);
|
|
2797
2772
|
const part = example.parts[i];
|
|
2798
2773
|
const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
|
|
2799
|
-
const readingAsInflectedFormMatch = part.inflectedForm !== void 0 && readings.has(part.inflectedForm);
|
|
2800
2774
|
const referenceIDMatch = part.referenceID === dictWord.id;
|
|
2801
2775
|
if (kanjiForms !== void 0 && kanjiForms.has(part.baseForm)) {
|
|
2802
|
-
if (readingAsReadingMatch ||
|
|
2776
|
+
if (readingAsReadingMatch || referenceIDMatch)
|
|
2803
2777
|
readingMatchingKanjiFormExamples.push({
|
|
2804
2778
|
ex: example,
|
|
2805
|
-
partIndex: i
|
|
2806
|
-
form: part.baseForm,
|
|
2807
|
-
...referenceIDMatch ? { referenceIDMatch: true } : {},
|
|
2808
|
-
...includesTranslation ? { includesTranslation: true } : {}
|
|
2779
|
+
partIndex: i
|
|
2809
2780
|
});
|
|
2810
|
-
else
|
|
2781
|
+
else {
|
|
2782
|
+
const includesTranslation = meanings.some(
|
|
2783
|
+
(m) => example.translation.includes(m)
|
|
2784
|
+
);
|
|
2785
|
+
if (!hasKanjiFormExamplesWithTranslation && includesTranslation)
|
|
2786
|
+
hasKanjiFormExamplesWithTranslation = true;
|
|
2811
2787
|
kanjiFormExamples.push({
|
|
2812
2788
|
ex: example,
|
|
2813
2789
|
partIndex: i,
|
|
2814
|
-
form: part.baseForm,
|
|
2815
2790
|
...includesTranslation ? { includesTranslation: true } : {}
|
|
2816
2791
|
});
|
|
2792
|
+
}
|
|
2817
2793
|
seenPhrases.add(example.phrase);
|
|
2818
2794
|
break;
|
|
2819
2795
|
}
|
|
2820
2796
|
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
2821
2797
|
if ((readingAsBaseFormMatch || referenceIDMatch) && kanjiForms === void 0) {
|
|
2798
|
+
const includesTranslation = meanings.some(
|
|
2799
|
+
(m) => example.translation.includes(m)
|
|
2800
|
+
);
|
|
2801
|
+
if (!hasReadingExamplesWithTranslation && includesTranslation)
|
|
2802
|
+
hasReadingExamplesWithTranslation = true;
|
|
2822
2803
|
readingExamples.push({
|
|
2823
2804
|
ex: example,
|
|
2824
2805
|
partIndex: i,
|
|
@@ -2829,21 +2810,13 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2829
2810
|
break;
|
|
2830
2811
|
}
|
|
2831
2812
|
}
|
|
2832
|
-
if (kanjiFormExamples.length > 0 &&
|
|
2833
|
-
(ex) => ex.includesTranslation === true || ex.ex.parts.some(
|
|
2834
|
-
(part) => ex.form === part.baseForm && part.glossNumber !== void 0
|
|
2835
|
-
)
|
|
2836
|
-
))
|
|
2813
|
+
if (kanjiFormExamples.length > 0 && hasKanjiFormExamplesWithTranslation)
|
|
2837
2814
|
kanjiFormExamples = kanjiFormExamples.filter(
|
|
2838
|
-
(ex) => ex.includesTranslation === true
|
|
2839
|
-
(part) => ex.form === part.baseForm && part.glossNumber !== void 0
|
|
2840
|
-
)
|
|
2815
|
+
(ex) => ex.includesTranslation === true
|
|
2841
2816
|
);
|
|
2842
2817
|
else if (kanjiFormExamples.length > 0 && readingMatchingKanjiFormExamples.length > 0)
|
|
2843
2818
|
kanjiFormExamples.length = 0;
|
|
2844
|
-
if (readingExamples.length > 0 &&
|
|
2845
|
-
(ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
|
|
2846
|
-
))
|
|
2819
|
+
if (readingExamples.length > 0 && hasReadingExamplesWithTranslation)
|
|
2847
2820
|
readingExamples = readingExamples.filter(
|
|
2848
2821
|
(ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
|
|
2849
2822
|
);
|
|
@@ -3020,29 +2993,32 @@ function getName(searchedName, dict, kanjiDic, examples, noteTypeName, deckPath)
|
|
|
3020
2993
|
for (const example of exampleList)
|
|
3021
2994
|
for (let i = 0; i < example.parts.length; i++) {
|
|
3022
2995
|
if (seenPhrases.has(example.phrase)) break;
|
|
3023
|
-
const includesTranslation = meanings.some(
|
|
3024
|
-
(m) => example.translation.includes(m)
|
|
3025
|
-
);
|
|
3026
2996
|
const part = example.parts[i];
|
|
3027
2997
|
const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
|
|
3028
2998
|
if (kanjiForms !== void 0 && kanjiForms.has(part.baseForm) && readingAsReadingMatch) {
|
|
2999
|
+
const includesTranslation = meanings.some(
|
|
3000
|
+
(m) => example.translation.includes(m)
|
|
3001
|
+
);
|
|
3002
|
+
if (!hasReadingMatchingKanjiFormWithTranslation && includesTranslation)
|
|
3003
|
+
hasReadingMatchingKanjiFormWithTranslation = true;
|
|
3029
3004
|
readingMatchingKanjiFormExamples.push({
|
|
3030
3005
|
ex: example,
|
|
3031
3006
|
...includesTranslation ? { includesTranslation: true } : {}
|
|
3032
3007
|
});
|
|
3033
|
-
if (!hasReadingMatchingKanjiFormWithTranslation && includesTranslation)
|
|
3034
|
-
hasReadingMatchingKanjiFormWithTranslation = true;
|
|
3035
3008
|
seenPhrases.add(example.phrase);
|
|
3036
3009
|
break;
|
|
3037
3010
|
}
|
|
3038
3011
|
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
3039
3012
|
if (readingAsBaseFormMatch && kanjiForms === void 0) {
|
|
3013
|
+
const includesTranslation = meanings.some(
|
|
3014
|
+
(m) => example.translation.includes(m)
|
|
3015
|
+
);
|
|
3016
|
+
if (!hasReadingWithTranslation && includesTranslation)
|
|
3017
|
+
hasReadingWithTranslation = true;
|
|
3040
3018
|
readingExamples.push({
|
|
3041
3019
|
ex: example,
|
|
3042
3020
|
...includesTranslation ? { includesTranslation: true } : {}
|
|
3043
3021
|
});
|
|
3044
|
-
if (!hasReadingWithTranslation && includesTranslation)
|
|
3045
|
-
hasReadingWithTranslation = true;
|
|
3046
3022
|
seenPhrases.add(example.phrase);
|
|
3047
3023
|
break;
|
|
3048
3024
|
}
|