henkan 2.1.0 → 2.2.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/dist/index.cjs.js +224 -98
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +223 -98
- package/dist/index.mjs.map +3 -3
- package/dist/types/types.d.ts +53 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +37 -18
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/README.md +8 -0
- package/docs/api/functions/capitalizeString.md +1 -1
- package/docs/api/functions/convertJMdict.md +1 -1
- package/docs/api/functions/convertJawiktionaryAsync.md +1 -1
- package/docs/api/functions/convertJawiktionarySync.md +1 -1
- package/docs/api/functions/convertKanjiDic.md +1 -1
- package/docs/api/functions/convertKradFile.md +1 -1
- package/docs/api/functions/convertRadkFile.md +1 -1
- package/docs/api/functions/convertTanakaCorpus.md +1 -1
- package/docs/api/functions/convertTanakaCorpusWithFurigana.md +1 -1
- package/docs/api/functions/createEntryMaps.md +59 -0
- package/docs/api/functions/generateAnkiNote.md +1 -1
- package/docs/api/functions/generateAnkiNotesFile.md +1 -1
- package/docs/api/functions/getKanji.md +9 -9
- package/docs/api/functions/getKanjiExtended.md +7 -7
- package/docs/api/functions/getValidForms.md +1 -1
- package/docs/api/functions/getWord.md +11 -11
- package/docs/api/functions/getWordDefinitions.md +1 -1
- package/docs/api/functions/getWordDefinitionsWithFurigana.md +1 -1
- package/docs/api/functions/isObjectArray.md +1 -1
- package/docs/api/functions/isStringArray.md +1 -1
- package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
- package/docs/api/functions/shuffleArray.md +1 -1
- package/docs/api/interfaces/DefaultNoteInfo.md +4 -4
- package/docs/api/interfaces/Definition.md +4 -4
- package/docs/api/interfaces/EntryMaps.md +83 -0
- package/docs/api/interfaces/Grammar.md +15 -15
- package/docs/api/interfaces/GrammarMeaning.md +3 -3
- package/docs/api/interfaces/JaWiktionaryEntry.md +5 -5
- package/docs/api/interfaces/Kana.md +11 -11
- package/docs/api/interfaces/Kanji.md +23 -23
- package/docs/api/interfaces/KanjiComponent.md +3 -3
- package/docs/api/interfaces/KanjiForm.md +4 -4
- package/docs/api/interfaces/NoteAndTag.md +3 -3
- package/docs/api/interfaces/NoteHeaderKeys.md +7 -7
- package/docs/api/interfaces/Phrase.md +5 -5
- package/docs/api/interfaces/Radical.md +16 -16
- package/docs/api/interfaces/Reading.md +5 -5
- package/docs/api/interfaces/ResultEntry.md +7 -7
- package/docs/api/interfaces/Translation.md +3 -3
- package/docs/api/interfaces/UsefulRegExps.md +8 -8
- package/docs/api/interfaces/Word.md +15 -15
- package/docs/api/interfaces/WordDefinitionPair.md +3 -3
- package/docs/api/type-aliases/Dict.md +1 -1
- package/docs/api/type-aliases/EntryType.md +1 -1
- package/docs/api/type-aliases/KanjiEntryMap.md +13 -0
- package/docs/api/type-aliases/KanjiSVGMap.md +13 -0
- package/docs/api/type-aliases/KanjiWordsMap.md +13 -0
- package/docs/api/type-aliases/Result.md +1 -1
- package/docs/api/type-aliases/WordDefinitionsMap.md +13 -0
- package/docs/api/type-aliases/WordExamplesMap.md +13 -0
- package/docs/api/type-aliases/WordIDEntryMap.md +13 -0
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -1576,6 +1576,133 @@ function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
|
1576
1576
|
}
|
|
1577
1577
|
return kanjiWithRadicals;
|
|
1578
1578
|
}
|
|
1579
|
+
function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs, svgList) {
|
|
1580
|
+
var _a;
|
|
1581
|
+
const kanjiEntryMap = /* @__PURE__ */ new Map();
|
|
1582
|
+
const wordIDEntryMap = /* @__PURE__ */ new Map();
|
|
1583
|
+
const kanjiWordsMap = /* @__PURE__ */ new Map();
|
|
1584
|
+
const wordExamplesMap = /* @__PURE__ */ new Map();
|
|
1585
|
+
const wordDefinitionsMap = /* @__PURE__ */ new Map();
|
|
1586
|
+
const kanjiSVGMap = /* @__PURE__ */ new Map();
|
|
1587
|
+
const wordPartsMap = /* @__PURE__ */ new Map();
|
|
1588
|
+
const partExamplesMap = /* @__PURE__ */ new Map();
|
|
1589
|
+
const entryParts = /* @__PURE__ */ new Set();
|
|
1590
|
+
if (kanjiDic)
|
|
1591
|
+
for (const kanji of kanjiDic) kanjiEntryMap.set(kanji.kanji, kanji);
|
|
1592
|
+
if (wordDefinitionPairs)
|
|
1593
|
+
for (const pair of wordDefinitionPairs)
|
|
1594
|
+
wordDefinitionsMap.set(pair.wordID, pair.definitions);
|
|
1595
|
+
if (kanjiDic && svgList)
|
|
1596
|
+
for (const kanji of kanjiDic) {
|
|
1597
|
+
const codePoint = kanji.kanji.codePointAt(0).toString(16).toLowerCase();
|
|
1598
|
+
const svg = svgList.find((file) => {
|
|
1599
|
+
const baseName = file.split(".")[0].toLowerCase();
|
|
1600
|
+
return baseName === codePoint || baseName === `0${codePoint}`;
|
|
1601
|
+
});
|
|
1602
|
+
if (svg) kanjiSVGMap.set(kanji.kanji, svg);
|
|
1603
|
+
}
|
|
1604
|
+
if (jmDict) {
|
|
1605
|
+
for (const word of jmDict) {
|
|
1606
|
+
wordIDEntryMap.set(word.id, word);
|
|
1607
|
+
if (word.kanjiForms)
|
|
1608
|
+
for (const kf of word.kanjiForms)
|
|
1609
|
+
for (const char of kf.form.split("").filter((c) => regexps.kanji.test(c))) {
|
|
1610
|
+
if (!kanjiWordsMap.has(char)) kanjiWordsMap.set(char, [word]);
|
|
1611
|
+
else kanjiWordsMap.get(char).push(word);
|
|
1612
|
+
}
|
|
1613
|
+
if (tanakaExamples) {
|
|
1614
|
+
const rkf = getValidForms(
|
|
1615
|
+
word.readings,
|
|
1616
|
+
word.kanjiForms,
|
|
1617
|
+
word.isCommon
|
|
1618
|
+
);
|
|
1619
|
+
const localPartParts = /* @__PURE__ */ new Set();
|
|
1620
|
+
if (rkf.readings.length > 0)
|
|
1621
|
+
for (const reading of rkf.readings) {
|
|
1622
|
+
entryParts.add(reading.reading);
|
|
1623
|
+
localPartParts.add(reading.reading);
|
|
1624
|
+
}
|
|
1625
|
+
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1626
|
+
for (const kanjiForm of rkf.kanjiForms) {
|
|
1627
|
+
entryParts.add(kanjiForm.form);
|
|
1628
|
+
localPartParts.add(kanjiForm.form);
|
|
1629
|
+
}
|
|
1630
|
+
entryParts.add(word.id);
|
|
1631
|
+
localPartParts.add(word.id);
|
|
1632
|
+
wordPartsMap.set(word.id, localPartParts);
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
if (tanakaExamples) {
|
|
1636
|
+
for (const ex of tanakaExamples) {
|
|
1637
|
+
for (const part of ex.parts) {
|
|
1638
|
+
if (entryParts.has(part.baseForm)) {
|
|
1639
|
+
let exList = partExamplesMap.get(
|
|
1640
|
+
part.baseForm
|
|
1641
|
+
);
|
|
1642
|
+
if (!exList) {
|
|
1643
|
+
exList = [];
|
|
1644
|
+
partExamplesMap.set(part.baseForm, exList);
|
|
1645
|
+
}
|
|
1646
|
+
exList.push(ex);
|
|
1647
|
+
}
|
|
1648
|
+
if (part.reading && entryParts.has(part.reading)) {
|
|
1649
|
+
let exList = partExamplesMap.get(
|
|
1650
|
+
part.reading
|
|
1651
|
+
);
|
|
1652
|
+
if (!exList) {
|
|
1653
|
+
exList = [];
|
|
1654
|
+
partExamplesMap.set(part.reading, exList);
|
|
1655
|
+
}
|
|
1656
|
+
exList.push(ex);
|
|
1657
|
+
}
|
|
1658
|
+
if (part.inflectedForm && entryParts.has(part.inflectedForm)) {
|
|
1659
|
+
let exList = partExamplesMap.get(
|
|
1660
|
+
part.inflectedForm
|
|
1661
|
+
);
|
|
1662
|
+
if (!exList) {
|
|
1663
|
+
exList = [];
|
|
1664
|
+
partExamplesMap.set(part.inflectedForm, exList);
|
|
1665
|
+
}
|
|
1666
|
+
exList.push(ex);
|
|
1667
|
+
}
|
|
1668
|
+
if (part.referenceID && entryParts.has(part.referenceID)) {
|
|
1669
|
+
let exList = partExamplesMap.get(
|
|
1670
|
+
part.referenceID
|
|
1671
|
+
);
|
|
1672
|
+
if (!exList) {
|
|
1673
|
+
exList = [];
|
|
1674
|
+
partExamplesMap.set(part.referenceID, exList);
|
|
1675
|
+
}
|
|
1676
|
+
exList.push(ex);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
for (const word of jmDict) {
|
|
1681
|
+
const entryParts2 = wordPartsMap.get(word.id);
|
|
1682
|
+
const seenEx = /* @__PURE__ */ new Set();
|
|
1683
|
+
const validExamples = [];
|
|
1684
|
+
for (const p of entryParts2) {
|
|
1685
|
+
const examplesForPart = (_a = partExamplesMap.get(p)) == null ? void 0 : _a.filter((ex) => !seenEx.has(ex.id));
|
|
1686
|
+
if (!examplesForPart) continue;
|
|
1687
|
+
for (const ex of examplesForPart) {
|
|
1688
|
+
seenEx.add(ex.id);
|
|
1689
|
+
validExamples.push(ex);
|
|
1690
|
+
}
|
|
1691
|
+
}
|
|
1692
|
+
if (validExamples.length > 0)
|
|
1693
|
+
wordExamplesMap.set(word.id, validExamples);
|
|
1694
|
+
}
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
return {
|
|
1698
|
+
...wordIDEntryMap.size > 0 ? { wordIDEntryMap } : {},
|
|
1699
|
+
...kanjiWordsMap.size > 0 ? { kanjiWordsMap } : {},
|
|
1700
|
+
...kanjiEntryMap.size > 0 ? { kanjiEntryMap } : {},
|
|
1701
|
+
...wordExamplesMap.size > 0 ? { wordExamplesMap } : {},
|
|
1702
|
+
...wordDefinitionsMap.size > 0 ? { wordDefinitionsMap } : {},
|
|
1703
|
+
...kanjiSVGMap.size > 0 ? { kanjiSVGMap } : {}
|
|
1704
|
+
};
|
|
1705
|
+
}
|
|
1579
1706
|
function mapEntry(entry) {
|
|
1580
1707
|
return {
|
|
1581
1708
|
word: entry.word,
|
|
@@ -1600,7 +1727,7 @@ function convertJawiktionarySync(buffer) {
|
|
|
1600
1727
|
const line = lines[i];
|
|
1601
1728
|
if (!line) continue;
|
|
1602
1729
|
const obj = JSON.parse(line);
|
|
1603
|
-
if (obj && typeof obj === "object" && obj.
|
|
1730
|
+
if (obj && typeof obj === "object" && typeof obj.lang === "string" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
1604
1731
|
entries.push(mapEntry(obj));
|
|
1605
1732
|
}
|
|
1606
1733
|
return entries;
|
|
@@ -1615,7 +1742,7 @@ async function convertJawiktionaryAsync(stream) {
|
|
|
1615
1742
|
const entries = [];
|
|
1616
1743
|
for await (const line of rl) {
|
|
1617
1744
|
const obj = JSON.parse(line.trim());
|
|
1618
|
-
if (obj && typeof obj === "object" && obj.
|
|
1745
|
+
if (obj && typeof obj === "object" && typeof obj.lang === "string" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
1619
1746
|
entries.push(mapEntry(obj));
|
|
1620
1747
|
}
|
|
1621
1748
|
rl.close();
|
|
@@ -1646,20 +1773,34 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1646
1773
|
}
|
|
1647
1774
|
const japaneseDefinitions = [];
|
|
1648
1775
|
const definitionMap = /* @__PURE__ */ new Map();
|
|
1649
|
-
const
|
|
1776
|
+
const wordFormsMap = /* @__PURE__ */ new Map();
|
|
1650
1777
|
const validReadings = /* @__PURE__ */ new Set();
|
|
1651
1778
|
const validKanjiForms = /* @__PURE__ */ new Set();
|
|
1779
|
+
const validForms = /* @__PURE__ */ new Set();
|
|
1652
1780
|
for (const word of jmDict) {
|
|
1781
|
+
const wordReadings = /* @__PURE__ */ new Set();
|
|
1782
|
+
const wordKanjiForms = /* @__PURE__ */ new Set();
|
|
1653
1783
|
const rkf = getValidForms(
|
|
1654
1784
|
word.readings,
|
|
1655
1785
|
word.kanjiForms,
|
|
1656
1786
|
word.isCommon
|
|
1657
1787
|
);
|
|
1658
1788
|
if (rkf.readings.length > 0)
|
|
1659
|
-
for (const r of rkf.readings)
|
|
1789
|
+
for (const r of rkf.readings) {
|
|
1790
|
+
validReadings.add(r.reading);
|
|
1791
|
+
wordReadings.add(r.reading);
|
|
1792
|
+
validForms.add(r.reading);
|
|
1793
|
+
}
|
|
1660
1794
|
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1661
|
-
for (const kf of rkf.kanjiForms)
|
|
1662
|
-
|
|
1795
|
+
for (const kf of rkf.kanjiForms) {
|
|
1796
|
+
validKanjiForms.add(kf.form);
|
|
1797
|
+
wordKanjiForms.add(kf.form);
|
|
1798
|
+
validForms.add(kf.form);
|
|
1799
|
+
}
|
|
1800
|
+
wordFormsMap.set(word.id, {
|
|
1801
|
+
readings: wordReadings,
|
|
1802
|
+
...wordKanjiForms.size > 0 ? { kanjiForms: wordKanjiForms } : {}
|
|
1803
|
+
});
|
|
1663
1804
|
}
|
|
1664
1805
|
const validTitleEntries = /* @__PURE__ */ new Map();
|
|
1665
1806
|
const entriesWithFormTitlesGlobal = /* @__PURE__ */ new Map();
|
|
@@ -1676,15 +1817,15 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1676
1817
|
if (sense.form_of && sense.form_of.some((form) => validReadings.has(form)))
|
|
1677
1818
|
validFormOfEntries.add(entry.word);
|
|
1678
1819
|
for (const gloss of sense.glosses) {
|
|
1679
|
-
let
|
|
1680
|
-
if (gloss.
|
|
1681
|
-
for (const r of
|
|
1682
|
-
if (gloss.
|
|
1683
|
-
|
|
1820
|
+
let hasForm = false;
|
|
1821
|
+
if (gloss.includes("\u8868\u8A18") || gloss.includes("\u53C2\u7167")) {
|
|
1822
|
+
for (const r of validForms)
|
|
1823
|
+
if (gloss.includes(r)) {
|
|
1824
|
+
hasForm = true;
|
|
1684
1825
|
break;
|
|
1685
1826
|
}
|
|
1686
1827
|
}
|
|
1687
|
-
if (
|
|
1828
|
+
if (hasForm) validGlossesEntries.add(entry.word);
|
|
1688
1829
|
}
|
|
1689
1830
|
}
|
|
1690
1831
|
if (entry.forms) {
|
|
@@ -1796,7 +1937,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1796
1937
|
fge.length = 0;
|
|
1797
1938
|
wfe.length = 0;
|
|
1798
1939
|
const wordEntriesPairs = [];
|
|
1799
|
-
for (const word of
|
|
1940
|
+
for (const word of jmDict) {
|
|
1800
1941
|
const poses = /* @__PURE__ */ new Set();
|
|
1801
1942
|
for (const m of word.meanings)
|
|
1802
1943
|
for (const note of m.partOfSpeech) {
|
|
@@ -1811,23 +1952,15 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1811
1952
|
poses.add(notePos);
|
|
1812
1953
|
}
|
|
1813
1954
|
}
|
|
1814
|
-
const rkf =
|
|
1815
|
-
word.readings,
|
|
1816
|
-
word.kanjiForms,
|
|
1817
|
-
word.isCommon
|
|
1818
|
-
);
|
|
1819
|
-
const validWordReadings = new Set(
|
|
1820
|
-
rkf.readings.map((r) => r.reading)
|
|
1821
|
-
);
|
|
1822
|
-
const validWordKanjiForms = rkf.kanjiForms ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
|
|
1955
|
+
const rkf = wordFormsMap.get(word.id);
|
|
1823
1956
|
const entriesWithTitles = [];
|
|
1824
1957
|
const entriesWithFormTitles = [];
|
|
1825
1958
|
const entriesWithForms = [];
|
|
1826
1959
|
if (poses.size > 0)
|
|
1827
1960
|
for (const pos of poses) {
|
|
1828
1961
|
const posEntries = posMap.get(pos);
|
|
1829
|
-
if (
|
|
1830
|
-
for (const kf of
|
|
1962
|
+
if (rkf.kanjiForms)
|
|
1963
|
+
for (const kf of rkf.kanjiForms) {
|
|
1831
1964
|
const te = (_a = posEntries.title) == null ? void 0 : _a.get(kf);
|
|
1832
1965
|
const fe = (_b = posEntries.form) == null ? void 0 : _b.get(kf);
|
|
1833
1966
|
if (te)
|
|
@@ -1840,28 +1973,28 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1840
1973
|
entriesWithForms.push(
|
|
1841
1974
|
...fe.filter(
|
|
1842
1975
|
(ent) => ent.forms && ent.forms.some(
|
|
1843
|
-
(form) =>
|
|
1976
|
+
(form) => rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1844
1977
|
)
|
|
1845
1978
|
)
|
|
1846
1979
|
);
|
|
1847
1980
|
}
|
|
1848
|
-
for (const r of
|
|
1981
|
+
for (const r of rkf.readings) {
|
|
1849
1982
|
const te = (_c = posEntries.title) == null ? void 0 : _c.get(r);
|
|
1850
1983
|
const fe = (_d = posEntries.form) == null ? void 0 : _d.get(r);
|
|
1851
1984
|
const fte = (_e = posEntries.formTitle) == null ? void 0 : _e.get(r);
|
|
1852
1985
|
if (te)
|
|
1853
1986
|
entriesWithTitles.push(
|
|
1854
1987
|
...te.filter(
|
|
1855
|
-
(ent) => ent.forms &&
|
|
1856
|
-
(form) =>
|
|
1857
|
-
) ||
|
|
1988
|
+
(ent) => ent.forms && rkf.kanjiForms && ent.forms.some(
|
|
1989
|
+
(form) => rkf.kanjiForms.has(form)
|
|
1990
|
+
) || rkf.kanjiForms === void 0
|
|
1858
1991
|
)
|
|
1859
1992
|
);
|
|
1860
1993
|
if (fe)
|
|
1861
1994
|
entriesWithForms.push(
|
|
1862
1995
|
...fe.filter(
|
|
1863
1996
|
(ent) => ent.forms && ent.forms.some(
|
|
1864
|
-
(form) =>
|
|
1997
|
+
(form) => rkf.kanjiForms && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1865
1998
|
)
|
|
1866
1999
|
)
|
|
1867
2000
|
);
|
|
@@ -1869,8 +2002,8 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1869
2002
|
}
|
|
1870
2003
|
}
|
|
1871
2004
|
if (entriesWithTitles.length === 0 && entriesWithFormTitles.length === 0 && entriesWithForms.length === 0) {
|
|
1872
|
-
if (
|
|
1873
|
-
for (const kf of
|
|
2005
|
+
if (rkf.kanjiForms)
|
|
2006
|
+
for (const kf of rkf.kanjiForms) {
|
|
1874
2007
|
const te = validTitleEntries.get(kf);
|
|
1875
2008
|
const fe = entriesWithFormsGlobal.get(kf);
|
|
1876
2009
|
if (te)
|
|
@@ -1883,28 +2016,28 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1883
2016
|
entriesWithForms.push(
|
|
1884
2017
|
...fe.filter(
|
|
1885
2018
|
(ent) => ent.forms && ent.forms.some(
|
|
1886
|
-
(form) =>
|
|
2019
|
+
(form) => rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1887
2020
|
)
|
|
1888
2021
|
)
|
|
1889
2022
|
);
|
|
1890
2023
|
}
|
|
1891
|
-
for (const r of
|
|
2024
|
+
for (const r of rkf.readings) {
|
|
1892
2025
|
const te = validTitleEntries.get(r);
|
|
1893
2026
|
const fe = entriesWithFormsGlobal.get(r);
|
|
1894
2027
|
const fte = entriesWithFormTitlesGlobal.get(r);
|
|
1895
2028
|
if (te)
|
|
1896
2029
|
entriesWithTitles.push(
|
|
1897
2030
|
...te.filter(
|
|
1898
|
-
(ent) => ent.forms &&
|
|
1899
|
-
(form) =>
|
|
1900
|
-
) ||
|
|
2031
|
+
(ent) => ent.forms && rkf.kanjiForms && ent.forms.some(
|
|
2032
|
+
(form) => rkf.kanjiForms.has(form)
|
|
2033
|
+
) || rkf.kanjiForms === void 0
|
|
1901
2034
|
)
|
|
1902
2035
|
);
|
|
1903
2036
|
if (fe)
|
|
1904
2037
|
entriesWithForms.push(
|
|
1905
2038
|
...fe.filter(
|
|
1906
2039
|
(ent) => ent.forms && ent.forms.some(
|
|
1907
|
-
(form) =>
|
|
2040
|
+
(form) => rkf.kanjiForms && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1908
2041
|
)
|
|
1909
2042
|
)
|
|
1910
2043
|
);
|
|
@@ -1914,8 +2047,9 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1914
2047
|
if (entriesWithTitles.length > 0 && (entriesWithFormTitles.length > 0 || entriesWithForms.length > 0))
|
|
1915
2048
|
wordEntriesPairs.push({
|
|
1916
2049
|
word,
|
|
1917
|
-
readings:
|
|
1918
|
-
...
|
|
2050
|
+
readings: rkf.readings,
|
|
2051
|
+
...rkf.kanjiForms ? { kanjiForms: rkf.kanjiForms } : {},
|
|
2052
|
+
forms: rkf.kanjiForms ? rkf.readings.union(rkf.kanjiForms) : rkf.readings,
|
|
1919
2053
|
entriesWithTitles,
|
|
1920
2054
|
entriesWithFormTitles,
|
|
1921
2055
|
entriesWithForms
|
|
@@ -1924,7 +2058,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1924
2058
|
for (const pair of wordEntriesPairs) {
|
|
1925
2059
|
const definitions = [];
|
|
1926
2060
|
const kanjiFormEntries = [];
|
|
1927
|
-
const
|
|
2061
|
+
const entriesWithForms = [];
|
|
1928
2062
|
const readingEntries = [];
|
|
1929
2063
|
const titleFormMap = /* @__PURE__ */ new Map();
|
|
1930
2064
|
const refsMap = /* @__PURE__ */ new Map();
|
|
@@ -1932,9 +2066,9 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1932
2066
|
for (const ent of pair.entriesWithTitles) {
|
|
1933
2067
|
const validFormOf = validFormOfEntries.has(ent.word);
|
|
1934
2068
|
const validGlosses = validGlossesEntries.has(ent.word);
|
|
1935
|
-
const
|
|
2069
|
+
const validForms2 = validFormsEntries.has(ent.word);
|
|
1936
2070
|
const hasKanjiForms = ent.forms !== void 0 && pair.kanjiForms !== void 0 && ent.forms.some((form) => pair.kanjiForms.has(form));
|
|
1937
|
-
if (pair.kanjiForms && pair.kanjiForms.has(ent.word) && (validFormOf || validGlosses ||
|
|
2071
|
+
if (pair.kanjiForms && pair.kanjiForms.has(ent.word) && (validFormOf || validGlosses || validForms2)) {
|
|
1938
2072
|
kanjiFormEntries.push(ent);
|
|
1939
2073
|
if ((validFormOf || validGlosses) && ent.senses)
|
|
1940
2074
|
for (const sense of ent.senses) {
|
|
@@ -1948,62 +2082,48 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1948
2082
|
}
|
|
1949
2083
|
}
|
|
1950
2084
|
if (validGlosses) {
|
|
1951
|
-
for (const gloss of sense.glosses)
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
2085
|
+
for (const gloss of sense.glosses)
|
|
2086
|
+
if (gloss.includes("\u8868\u8A18") || gloss.includes("\u53C2\u7167")) {
|
|
2087
|
+
for (const f of pair.forms)
|
|
2088
|
+
if (gloss.includes(f)) {
|
|
2089
|
+
const elem = refsMap.get(f);
|
|
2090
|
+
if (!elem) refsMap.set(f, /* @__PURE__ */ new Set([ent.word]));
|
|
2091
|
+
else elem.add(ent.word);
|
|
1958
2092
|
}
|
|
1959
2093
|
}
|
|
1960
|
-
if (reading) {
|
|
1961
|
-
const elem = refsMap.get(reading);
|
|
1962
|
-
if (!elem) refsMap.set(reading, /* @__PURE__ */ new Set([ent.word]));
|
|
1963
|
-
else elem.add(ent.word);
|
|
1964
|
-
}
|
|
1965
|
-
}
|
|
1966
2094
|
}
|
|
1967
2095
|
}
|
|
1968
|
-
if (
|
|
2096
|
+
if (validForms2 && ent.forms) {
|
|
1969
2097
|
for (const form of ent.forms)
|
|
1970
2098
|
if (pair.readings.has(form)) readingForms.add(form);
|
|
1971
2099
|
}
|
|
1972
2100
|
}
|
|
1973
2101
|
if (pair.readings.has(ent.word) && hasKanjiForms)
|
|
1974
|
-
|
|
2102
|
+
entriesWithForms.push(ent);
|
|
1975
2103
|
if (pair.kanjiForms === void 0 && pair.readings.has(ent.word))
|
|
1976
2104
|
readingEntries.push(ent);
|
|
1977
2105
|
}
|
|
1978
2106
|
for (const entry of pair.entriesWithForms) {
|
|
1979
2107
|
const elem = titleFormMap.get(entry.word);
|
|
1980
2108
|
if (elem && entry.forms && entry.forms.some((form) => elem.has(form)))
|
|
1981
|
-
|
|
2109
|
+
entriesWithForms.push(entry);
|
|
1982
2110
|
}
|
|
1983
2111
|
for (const entry of pair.entriesWithFormTitles) {
|
|
1984
2112
|
if (readingForms.has(entry.word)) {
|
|
1985
|
-
|
|
2113
|
+
entriesWithForms.push(entry);
|
|
1986
2114
|
continue;
|
|
1987
2115
|
}
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
if (ft && !ft.isDisjointFrom(pair.kanjiForms))
|
|
1991
|
-
readingWithFormsEntries.push(entry);
|
|
1992
|
-
}
|
|
2116
|
+
const ft = refsMap.get(entry.word);
|
|
2117
|
+
if (ft && !ft.isDisjointFrom(pair.forms)) entriesWithForms.push(entry);
|
|
1993
2118
|
}
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
parsedReadingWithFormsEntries = true;
|
|
1999
|
-
for (const ref of readingWithFormsEntries)
|
|
2000
|
-
parseEntry(ref, definitions, definitionMap);
|
|
2001
|
-
} else parseEntry(entry, definitions, definitionMap);
|
|
2002
|
-
if (!parsedReadingWithFormsEntries && readingWithFormsEntries.length > 0) {
|
|
2003
|
-
parsedReadingWithFormsEntries = true;
|
|
2004
|
-
for (const ref of readingWithFormsEntries)
|
|
2005
|
-
parseEntry(ref, definitions, definitionMap);
|
|
2119
|
+
if (kanjiFormEntries.length > 0) {
|
|
2120
|
+
for (const entry of kanjiFormEntries)
|
|
2121
|
+
if (entry.pos_title !== "\u548C\u8A9E\u306E\u6F22\u5B57\u8868\u8A18")
|
|
2122
|
+
parseEntry(entry, definitions, definitionMap);
|
|
2006
2123
|
}
|
|
2124
|
+
if (entriesWithForms.length > 0)
|
|
2125
|
+
for (const ref of entriesWithForms)
|
|
2126
|
+
parseEntry(ref, definitions, definitionMap);
|
|
2007
2127
|
if (readingEntries.length > 0)
|
|
2008
2128
|
for (const readingEntry of readingEntries)
|
|
2009
2129
|
parseEntry(readingEntry, definitions, definitionMap);
|
|
@@ -2019,7 +2139,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2019
2139
|
const defCount = definitionMap.get(
|
|
2020
2140
|
pair.definitions[j].definition
|
|
2021
2141
|
);
|
|
2022
|
-
if (defCount && defCount.count >
|
|
2142
|
+
if (defCount && defCount.count > 0)
|
|
2023
2143
|
pair.definitions[j].mayNotBeAccurate = true;
|
|
2024
2144
|
}
|
|
2025
2145
|
japaneseDefinitions[i] = pair;
|
|
@@ -2194,13 +2314,15 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2194
2314
|
}
|
|
2195
2315
|
if (kanjiDic && word2.kanjiForms) {
|
|
2196
2316
|
const kanji = [];
|
|
2317
|
+
const seenChars = /* @__PURE__ */ new Set();
|
|
2197
2318
|
for (const kanjiForm of word2.kanjiForms)
|
|
2198
|
-
for (const char of kanjiForm.kanjiForm) {
|
|
2199
|
-
if (
|
|
2200
|
-
|
|
2319
|
+
for (const char of kanjiForm.kanjiForm.split("").filter((c) => regexps.kanji.test(c))) {
|
|
2320
|
+
if (seenChars.has(char)) continue;
|
|
2321
|
+
seenChars.add(char);
|
|
2322
|
+
const kanjiEntry = kanjiDic instanceof Map ? kanjiDic.get(char) : void 0;
|
|
2201
2323
|
const kanjiObj = getKanji(
|
|
2202
|
-
char,
|
|
2203
|
-
Array.isArray(kanjiDic) ? kanjiDic :
|
|
2324
|
+
kanjiEntry ?? char,
|
|
2325
|
+
Array.isArray(kanjiDic) ? kanjiDic : void 0
|
|
2204
2326
|
);
|
|
2205
2327
|
if (kanjiObj)
|
|
2206
2328
|
kanji.push({
|
|
@@ -2211,9 +2333,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2211
2333
|
if (kanji.length > 0) word2.kanji = kanji;
|
|
2212
2334
|
}
|
|
2213
2335
|
if (dictWord.hasPhrases !== void 0 && examples) {
|
|
2214
|
-
const exampleList = Array.isArray(examples) ? examples : examples.get(
|
|
2215
|
-
dictWord.id
|
|
2216
|
-
) ?? [];
|
|
2336
|
+
const exampleList = Array.isArray(examples) ? examples : examples.get(dictWord.id) ?? [];
|
|
2217
2337
|
const rkf = getValidForms(
|
|
2218
2338
|
dictWord.readings,
|
|
2219
2339
|
dictWord.kanjiForms,
|
|
@@ -2281,17 +2401,23 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2281
2401
|
}
|
|
2282
2402
|
}
|
|
2283
2403
|
}
|
|
2284
|
-
if (glossSpecificExamples.length === 5) break;
|
|
2285
2404
|
}
|
|
2286
|
-
if (glossSpecificExamples.length ===
|
|
2287
|
-
wordExamples =
|
|
2288
|
-
else if (glossSpecificExamples.length > 0)
|
|
2289
|
-
|
|
2290
|
-
|
|
2291
|
-
|
|
2405
|
+
if (glossSpecificExamples.length === word2.translations.length)
|
|
2406
|
+
wordExamples = glossSpecificExamples;
|
|
2407
|
+
else if (glossSpecificExamples.length > 0) {
|
|
2408
|
+
const exes = glossSpecificExamples;
|
|
2409
|
+
if (exes.length < 5) {
|
|
2410
|
+
wordExamples = wordExamples.filter(
|
|
2292
2411
|
(ex) => !seenPhrases.has(ex.ex.phrase)
|
|
2293
|
-
)
|
|
2294
|
-
|
|
2412
|
+
);
|
|
2413
|
+
if (wordExamples.length > 0)
|
|
2414
|
+
for (const ex of wordExamples) {
|
|
2415
|
+
exes.push(ex);
|
|
2416
|
+
if (exes.length === 5) break;
|
|
2417
|
+
}
|
|
2418
|
+
}
|
|
2419
|
+
wordExamples = exes;
|
|
2420
|
+
}
|
|
2295
2421
|
if (wordExamples.length > 0) {
|
|
2296
2422
|
word2.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => ({
|
|
2297
2423
|
phrase: ex.ex.furigana ?? ex.ex.phrase,
|
|
@@ -2305,9 +2431,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2305
2431
|
}
|
|
2306
2432
|
}
|
|
2307
2433
|
if (definitions) {
|
|
2308
|
-
const defs = Array.isArray(definitions) ? (_a = definitions.find((wdp) => wdp.wordID === word2.id)) == null ? void 0 : _a.definitions : definitions.get(
|
|
2309
|
-
word2.id
|
|
2310
|
-
);
|
|
2434
|
+
const defs = Array.isArray(definitions) ? (_a = definitions.find((wdp) => wdp.wordID === word2.id)) == null ? void 0 : _a.definitions : definitions.get(word2.id);
|
|
2311
2435
|
if (defs) word2.definitions = [...defs];
|
|
2312
2436
|
}
|
|
2313
2437
|
return word2;
|
|
@@ -2751,6 +2875,7 @@ export {
|
|
|
2751
2875
|
convertRadkFile,
|
|
2752
2876
|
convertTanakaCorpus,
|
|
2753
2877
|
convertTanakaCorpusWithFurigana,
|
|
2878
|
+
createEntryMaps,
|
|
2754
2879
|
generateAnkiNote,
|
|
2755
2880
|
generateAnkiNotesFile,
|
|
2756
2881
|
getKanji,
|