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.
Files changed (61) hide show
  1. package/dist/index.cjs.js +224 -98
  2. package/dist/index.cjs.js.map +3 -3
  3. package/dist/index.mjs +223 -98
  4. package/dist/index.mjs.map +3 -3
  5. package/dist/types/types.d.ts +53 -0
  6. package/dist/types/types.d.ts.map +1 -1
  7. package/dist/types/utils.d.ts +37 -18
  8. package/dist/types/utils.d.ts.map +1 -1
  9. package/docs/api/README.md +8 -0
  10. package/docs/api/functions/capitalizeString.md +1 -1
  11. package/docs/api/functions/convertJMdict.md +1 -1
  12. package/docs/api/functions/convertJawiktionaryAsync.md +1 -1
  13. package/docs/api/functions/convertJawiktionarySync.md +1 -1
  14. package/docs/api/functions/convertKanjiDic.md +1 -1
  15. package/docs/api/functions/convertKradFile.md +1 -1
  16. package/docs/api/functions/convertRadkFile.md +1 -1
  17. package/docs/api/functions/convertTanakaCorpus.md +1 -1
  18. package/docs/api/functions/convertTanakaCorpusWithFurigana.md +1 -1
  19. package/docs/api/functions/createEntryMaps.md +59 -0
  20. package/docs/api/functions/generateAnkiNote.md +1 -1
  21. package/docs/api/functions/generateAnkiNotesFile.md +1 -1
  22. package/docs/api/functions/getKanji.md +9 -9
  23. package/docs/api/functions/getKanjiExtended.md +7 -7
  24. package/docs/api/functions/getValidForms.md +1 -1
  25. package/docs/api/functions/getWord.md +11 -11
  26. package/docs/api/functions/getWordDefinitions.md +1 -1
  27. package/docs/api/functions/getWordDefinitionsWithFurigana.md +1 -1
  28. package/docs/api/functions/isObjectArray.md +1 -1
  29. package/docs/api/functions/isStringArray.md +1 -1
  30. package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
  31. package/docs/api/functions/shuffleArray.md +1 -1
  32. package/docs/api/interfaces/DefaultNoteInfo.md +4 -4
  33. package/docs/api/interfaces/Definition.md +4 -4
  34. package/docs/api/interfaces/EntryMaps.md +83 -0
  35. package/docs/api/interfaces/Grammar.md +15 -15
  36. package/docs/api/interfaces/GrammarMeaning.md +3 -3
  37. package/docs/api/interfaces/JaWiktionaryEntry.md +5 -5
  38. package/docs/api/interfaces/Kana.md +11 -11
  39. package/docs/api/interfaces/Kanji.md +23 -23
  40. package/docs/api/interfaces/KanjiComponent.md +3 -3
  41. package/docs/api/interfaces/KanjiForm.md +4 -4
  42. package/docs/api/interfaces/NoteAndTag.md +3 -3
  43. package/docs/api/interfaces/NoteHeaderKeys.md +7 -7
  44. package/docs/api/interfaces/Phrase.md +5 -5
  45. package/docs/api/interfaces/Radical.md +16 -16
  46. package/docs/api/interfaces/Reading.md +5 -5
  47. package/docs/api/interfaces/ResultEntry.md +7 -7
  48. package/docs/api/interfaces/Translation.md +3 -3
  49. package/docs/api/interfaces/UsefulRegExps.md +8 -8
  50. package/docs/api/interfaces/Word.md +15 -15
  51. package/docs/api/interfaces/WordDefinitionPair.md +3 -3
  52. package/docs/api/type-aliases/Dict.md +1 -1
  53. package/docs/api/type-aliases/EntryType.md +1 -1
  54. package/docs/api/type-aliases/KanjiEntryMap.md +13 -0
  55. package/docs/api/type-aliases/KanjiSVGMap.md +13 -0
  56. package/docs/api/type-aliases/KanjiWordsMap.md +13 -0
  57. package/docs/api/type-aliases/Result.md +1 -1
  58. package/docs/api/type-aliases/WordDefinitionsMap.md +13 -0
  59. package/docs/api/type-aliases/WordExamplesMap.md +13 -0
  60. package/docs/api/type-aliases/WordIDEntryMap.md +13 -0
  61. package/package.json +3 -3
package/dist/index.cjs.js CHANGED
@@ -39,6 +39,7 @@ __export(index_exports, {
39
39
  convertRadkFile: () => convertRadkFile,
40
40
  convertTanakaCorpus: () => convertTanakaCorpus,
41
41
  convertTanakaCorpusWithFurigana: () => convertTanakaCorpusWithFurigana,
42
+ createEntryMaps: () => createEntryMaps,
42
43
  generateAnkiNote: () => generateAnkiNote,
43
44
  generateAnkiNotesFile: () => generateAnkiNotesFile,
44
45
  getKanji: () => getKanji,
@@ -1634,6 +1635,133 @@ function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
1634
1635
  }
1635
1636
  return kanjiWithRadicals;
1636
1637
  }
1638
+ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs, svgList) {
1639
+ var _a;
1640
+ const kanjiEntryMap = /* @__PURE__ */ new Map();
1641
+ const wordIDEntryMap = /* @__PURE__ */ new Map();
1642
+ const kanjiWordsMap = /* @__PURE__ */ new Map();
1643
+ const wordExamplesMap = /* @__PURE__ */ new Map();
1644
+ const wordDefinitionsMap = /* @__PURE__ */ new Map();
1645
+ const kanjiSVGMap = /* @__PURE__ */ new Map();
1646
+ const wordPartsMap = /* @__PURE__ */ new Map();
1647
+ const partExamplesMap = /* @__PURE__ */ new Map();
1648
+ const entryParts = /* @__PURE__ */ new Set();
1649
+ if (kanjiDic)
1650
+ for (const kanji of kanjiDic) kanjiEntryMap.set(kanji.kanji, kanji);
1651
+ if (wordDefinitionPairs)
1652
+ for (const pair of wordDefinitionPairs)
1653
+ wordDefinitionsMap.set(pair.wordID, pair.definitions);
1654
+ if (kanjiDic && svgList)
1655
+ for (const kanji of kanjiDic) {
1656
+ const codePoint = kanji.kanji.codePointAt(0).toString(16).toLowerCase();
1657
+ const svg = svgList.find((file) => {
1658
+ const baseName = file.split(".")[0].toLowerCase();
1659
+ return baseName === codePoint || baseName === `0${codePoint}`;
1660
+ });
1661
+ if (svg) kanjiSVGMap.set(kanji.kanji, svg);
1662
+ }
1663
+ if (jmDict) {
1664
+ for (const word of jmDict) {
1665
+ wordIDEntryMap.set(word.id, word);
1666
+ if (word.kanjiForms)
1667
+ for (const kf of word.kanjiForms)
1668
+ for (const char of kf.form.split("").filter((c) => regexps.kanji.test(c))) {
1669
+ if (!kanjiWordsMap.has(char)) kanjiWordsMap.set(char, [word]);
1670
+ else kanjiWordsMap.get(char).push(word);
1671
+ }
1672
+ if (tanakaExamples) {
1673
+ const rkf = getValidForms(
1674
+ word.readings,
1675
+ word.kanjiForms,
1676
+ word.isCommon
1677
+ );
1678
+ const localPartParts = /* @__PURE__ */ new Set();
1679
+ if (rkf.readings.length > 0)
1680
+ for (const reading of rkf.readings) {
1681
+ entryParts.add(reading.reading);
1682
+ localPartParts.add(reading.reading);
1683
+ }
1684
+ if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
1685
+ for (const kanjiForm of rkf.kanjiForms) {
1686
+ entryParts.add(kanjiForm.form);
1687
+ localPartParts.add(kanjiForm.form);
1688
+ }
1689
+ entryParts.add(word.id);
1690
+ localPartParts.add(word.id);
1691
+ wordPartsMap.set(word.id, localPartParts);
1692
+ }
1693
+ }
1694
+ if (tanakaExamples) {
1695
+ for (const ex of tanakaExamples) {
1696
+ for (const part of ex.parts) {
1697
+ if (entryParts.has(part.baseForm)) {
1698
+ let exList = partExamplesMap.get(
1699
+ part.baseForm
1700
+ );
1701
+ if (!exList) {
1702
+ exList = [];
1703
+ partExamplesMap.set(part.baseForm, exList);
1704
+ }
1705
+ exList.push(ex);
1706
+ }
1707
+ if (part.reading && entryParts.has(part.reading)) {
1708
+ let exList = partExamplesMap.get(
1709
+ part.reading
1710
+ );
1711
+ if (!exList) {
1712
+ exList = [];
1713
+ partExamplesMap.set(part.reading, exList);
1714
+ }
1715
+ exList.push(ex);
1716
+ }
1717
+ if (part.inflectedForm && entryParts.has(part.inflectedForm)) {
1718
+ let exList = partExamplesMap.get(
1719
+ part.inflectedForm
1720
+ );
1721
+ if (!exList) {
1722
+ exList = [];
1723
+ partExamplesMap.set(part.inflectedForm, exList);
1724
+ }
1725
+ exList.push(ex);
1726
+ }
1727
+ if (part.referenceID && entryParts.has(part.referenceID)) {
1728
+ let exList = partExamplesMap.get(
1729
+ part.referenceID
1730
+ );
1731
+ if (!exList) {
1732
+ exList = [];
1733
+ partExamplesMap.set(part.referenceID, exList);
1734
+ }
1735
+ exList.push(ex);
1736
+ }
1737
+ }
1738
+ }
1739
+ for (const word of jmDict) {
1740
+ const entryParts2 = wordPartsMap.get(word.id);
1741
+ const seenEx = /* @__PURE__ */ new Set();
1742
+ const validExamples = [];
1743
+ for (const p of entryParts2) {
1744
+ const examplesForPart = (_a = partExamplesMap.get(p)) == null ? void 0 : _a.filter((ex) => !seenEx.has(ex.id));
1745
+ if (!examplesForPart) continue;
1746
+ for (const ex of examplesForPart) {
1747
+ seenEx.add(ex.id);
1748
+ validExamples.push(ex);
1749
+ }
1750
+ }
1751
+ if (validExamples.length > 0)
1752
+ wordExamplesMap.set(word.id, validExamples);
1753
+ }
1754
+ }
1755
+ }
1756
+ return {
1757
+ ...wordIDEntryMap.size > 0 ? { wordIDEntryMap } : {},
1758
+ ...kanjiWordsMap.size > 0 ? { kanjiWordsMap } : {},
1759
+ ...kanjiEntryMap.size > 0 ? { kanjiEntryMap } : {},
1760
+ ...wordExamplesMap.size > 0 ? { wordExamplesMap } : {},
1761
+ ...wordDefinitionsMap.size > 0 ? { wordDefinitionsMap } : {},
1762
+ ...kanjiSVGMap.size > 0 ? { kanjiSVGMap } : {}
1763
+ };
1764
+ }
1637
1765
  function mapEntry(entry) {
1638
1766
  return {
1639
1767
  word: entry.word,
@@ -1658,7 +1786,7 @@ function convertJawiktionarySync(buffer) {
1658
1786
  const line = lines[i];
1659
1787
  if (!line) continue;
1660
1788
  const obj = JSON.parse(line);
1661
- if (obj && typeof obj === "object" && obj.lang_code === "ja" && obj.lang === "\u65E5\u672C\u8A9E")
1789
+ if (obj && typeof obj === "object" && typeof obj.lang === "string" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
1662
1790
  entries.push(mapEntry(obj));
1663
1791
  }
1664
1792
  return entries;
@@ -1673,7 +1801,7 @@ async function convertJawiktionaryAsync(stream) {
1673
1801
  const entries = [];
1674
1802
  for await (const line of rl) {
1675
1803
  const obj = JSON.parse(line.trim());
1676
- if (obj && typeof obj === "object" && obj.lang_code === "ja" && obj.lang === "\u65E5\u672C\u8A9E")
1804
+ if (obj && typeof obj === "object" && typeof obj.lang === "string" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
1677
1805
  entries.push(mapEntry(obj));
1678
1806
  }
1679
1807
  rl.close();
@@ -1704,20 +1832,34 @@ function getWordDefinitions(entryList, jmDict) {
1704
1832
  }
1705
1833
  const japaneseDefinitions = [];
1706
1834
  const definitionMap = /* @__PURE__ */ new Map();
1707
- const validWords = [];
1835
+ const wordFormsMap = /* @__PURE__ */ new Map();
1708
1836
  const validReadings = /* @__PURE__ */ new Set();
1709
1837
  const validKanjiForms = /* @__PURE__ */ new Set();
1838
+ const validForms = /* @__PURE__ */ new Set();
1710
1839
  for (const word of jmDict) {
1840
+ const wordReadings = /* @__PURE__ */ new Set();
1841
+ const wordKanjiForms = /* @__PURE__ */ new Set();
1711
1842
  const rkf = getValidForms(
1712
1843
  word.readings,
1713
1844
  word.kanjiForms,
1714
1845
  word.isCommon
1715
1846
  );
1716
1847
  if (rkf.readings.length > 0)
1717
- for (const r of rkf.readings) validReadings.add(r.reading);
1848
+ for (const r of rkf.readings) {
1849
+ validReadings.add(r.reading);
1850
+ wordReadings.add(r.reading);
1851
+ validForms.add(r.reading);
1852
+ }
1718
1853
  if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
1719
- for (const kf of rkf.kanjiForms) validKanjiForms.add(kf.form);
1720
- validWords.push(word);
1854
+ for (const kf of rkf.kanjiForms) {
1855
+ validKanjiForms.add(kf.form);
1856
+ wordKanjiForms.add(kf.form);
1857
+ validForms.add(kf.form);
1858
+ }
1859
+ wordFormsMap.set(word.id, {
1860
+ readings: wordReadings,
1861
+ ...wordKanjiForms.size > 0 ? { kanjiForms: wordKanjiForms } : {}
1862
+ });
1721
1863
  }
1722
1864
  const validTitleEntries = /* @__PURE__ */ new Map();
1723
1865
  const entriesWithFormTitlesGlobal = /* @__PURE__ */ new Map();
@@ -1734,15 +1876,15 @@ function getWordDefinitions(entryList, jmDict) {
1734
1876
  if (sense.form_of && sense.form_of.some((form) => validReadings.has(form)))
1735
1877
  validFormOfEntries.add(entry.word);
1736
1878
  for (const gloss of sense.glosses) {
1737
- let reading = void 0;
1738
- if (gloss.trim().includes("\u6F22\u5B57\u8868\u8A18") || gloss.trim().includes("\u53C2\u7167")) {
1739
- for (const r of validReadings)
1740
- if (gloss.trim().includes(r)) {
1741
- reading = r;
1879
+ let hasForm = false;
1880
+ if (gloss.includes("\u8868\u8A18") || gloss.includes("\u53C2\u7167")) {
1881
+ for (const r of validForms)
1882
+ if (gloss.includes(r)) {
1883
+ hasForm = true;
1742
1884
  break;
1743
1885
  }
1744
1886
  }
1745
- if (reading) validGlossesEntries.add(entry.word);
1887
+ if (hasForm) validGlossesEntries.add(entry.word);
1746
1888
  }
1747
1889
  }
1748
1890
  if (entry.forms) {
@@ -1854,7 +1996,7 @@ function getWordDefinitions(entryList, jmDict) {
1854
1996
  fge.length = 0;
1855
1997
  wfe.length = 0;
1856
1998
  const wordEntriesPairs = [];
1857
- for (const word of validWords) {
1999
+ for (const word of jmDict) {
1858
2000
  const poses = /* @__PURE__ */ new Set();
1859
2001
  for (const m of word.meanings)
1860
2002
  for (const note of m.partOfSpeech) {
@@ -1869,23 +2011,15 @@ function getWordDefinitions(entryList, jmDict) {
1869
2011
  poses.add(notePos);
1870
2012
  }
1871
2013
  }
1872
- const rkf = getValidForms(
1873
- word.readings,
1874
- word.kanjiForms,
1875
- word.isCommon
1876
- );
1877
- const validWordReadings = new Set(
1878
- rkf.readings.map((r) => r.reading)
1879
- );
1880
- const validWordKanjiForms = rkf.kanjiForms ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
2014
+ const rkf = wordFormsMap.get(word.id);
1881
2015
  const entriesWithTitles = [];
1882
2016
  const entriesWithFormTitles = [];
1883
2017
  const entriesWithForms = [];
1884
2018
  if (poses.size > 0)
1885
2019
  for (const pos of poses) {
1886
2020
  const posEntries = posMap.get(pos);
1887
- if (validWordKanjiForms)
1888
- for (const kf of validWordKanjiForms) {
2021
+ if (rkf.kanjiForms)
2022
+ for (const kf of rkf.kanjiForms) {
1889
2023
  const te = (_a = posEntries.title) == null ? void 0 : _a.get(kf);
1890
2024
  const fe = (_b = posEntries.form) == null ? void 0 : _b.get(kf);
1891
2025
  if (te)
@@ -1898,28 +2032,28 @@ function getWordDefinitions(entryList, jmDict) {
1898
2032
  entriesWithForms.push(
1899
2033
  ...fe.filter(
1900
2034
  (ent) => ent.forms && ent.forms.some(
1901
- (form) => validWordKanjiForms.has(form) || validWordReadings.has(form)
2035
+ (form) => rkf.kanjiForms.has(form) || rkf.readings.has(form)
1902
2036
  )
1903
2037
  )
1904
2038
  );
1905
2039
  }
1906
- for (const r of validWordReadings) {
2040
+ for (const r of rkf.readings) {
1907
2041
  const te = (_c = posEntries.title) == null ? void 0 : _c.get(r);
1908
2042
  const fe = (_d = posEntries.form) == null ? void 0 : _d.get(r);
1909
2043
  const fte = (_e = posEntries.formTitle) == null ? void 0 : _e.get(r);
1910
2044
  if (te)
1911
2045
  entriesWithTitles.push(
1912
2046
  ...te.filter(
1913
- (ent) => ent.forms && validWordKanjiForms && ent.forms.some(
1914
- (form) => validWordKanjiForms.has(form)
1915
- ) || validWordKanjiForms === void 0
2047
+ (ent) => ent.forms && rkf.kanjiForms && ent.forms.some(
2048
+ (form) => rkf.kanjiForms.has(form)
2049
+ ) || rkf.kanjiForms === void 0
1916
2050
  )
1917
2051
  );
1918
2052
  if (fe)
1919
2053
  entriesWithForms.push(
1920
2054
  ...fe.filter(
1921
2055
  (ent) => ent.forms && ent.forms.some(
1922
- (form) => validWordKanjiForms && validWordKanjiForms.has(form) || validWordReadings.has(form)
2056
+ (form) => rkf.kanjiForms && rkf.kanjiForms.has(form) || rkf.readings.has(form)
1923
2057
  )
1924
2058
  )
1925
2059
  );
@@ -1927,8 +2061,8 @@ function getWordDefinitions(entryList, jmDict) {
1927
2061
  }
1928
2062
  }
1929
2063
  if (entriesWithTitles.length === 0 && entriesWithFormTitles.length === 0 && entriesWithForms.length === 0) {
1930
- if (validWordKanjiForms)
1931
- for (const kf of validWordKanjiForms) {
2064
+ if (rkf.kanjiForms)
2065
+ for (const kf of rkf.kanjiForms) {
1932
2066
  const te = validTitleEntries.get(kf);
1933
2067
  const fe = entriesWithFormsGlobal.get(kf);
1934
2068
  if (te)
@@ -1941,28 +2075,28 @@ function getWordDefinitions(entryList, jmDict) {
1941
2075
  entriesWithForms.push(
1942
2076
  ...fe.filter(
1943
2077
  (ent) => ent.forms && ent.forms.some(
1944
- (form) => validWordKanjiForms.has(form) || validWordReadings.has(form)
2078
+ (form) => rkf.kanjiForms.has(form) || rkf.readings.has(form)
1945
2079
  )
1946
2080
  )
1947
2081
  );
1948
2082
  }
1949
- for (const r of validWordReadings) {
2083
+ for (const r of rkf.readings) {
1950
2084
  const te = validTitleEntries.get(r);
1951
2085
  const fe = entriesWithFormsGlobal.get(r);
1952
2086
  const fte = entriesWithFormTitlesGlobal.get(r);
1953
2087
  if (te)
1954
2088
  entriesWithTitles.push(
1955
2089
  ...te.filter(
1956
- (ent) => ent.forms && validWordKanjiForms && ent.forms.some(
1957
- (form) => validWordKanjiForms.has(form)
1958
- ) || validWordKanjiForms === void 0
2090
+ (ent) => ent.forms && rkf.kanjiForms && ent.forms.some(
2091
+ (form) => rkf.kanjiForms.has(form)
2092
+ ) || rkf.kanjiForms === void 0
1959
2093
  )
1960
2094
  );
1961
2095
  if (fe)
1962
2096
  entriesWithForms.push(
1963
2097
  ...fe.filter(
1964
2098
  (ent) => ent.forms && ent.forms.some(
1965
- (form) => validWordKanjiForms && validWordKanjiForms.has(form) || validWordReadings.has(form)
2099
+ (form) => rkf.kanjiForms && rkf.kanjiForms.has(form) || rkf.readings.has(form)
1966
2100
  )
1967
2101
  )
1968
2102
  );
@@ -1972,8 +2106,9 @@ function getWordDefinitions(entryList, jmDict) {
1972
2106
  if (entriesWithTitles.length > 0 && (entriesWithFormTitles.length > 0 || entriesWithForms.length > 0))
1973
2107
  wordEntriesPairs.push({
1974
2108
  word,
1975
- readings: validWordReadings,
1976
- ...validWordKanjiForms ? { kanjiForms: validWordKanjiForms } : {},
2109
+ readings: rkf.readings,
2110
+ ...rkf.kanjiForms ? { kanjiForms: rkf.kanjiForms } : {},
2111
+ forms: rkf.kanjiForms ? rkf.readings.union(rkf.kanjiForms) : rkf.readings,
1977
2112
  entriesWithTitles,
1978
2113
  entriesWithFormTitles,
1979
2114
  entriesWithForms
@@ -1982,7 +2117,7 @@ function getWordDefinitions(entryList, jmDict) {
1982
2117
  for (const pair of wordEntriesPairs) {
1983
2118
  const definitions = [];
1984
2119
  const kanjiFormEntries = [];
1985
- const readingWithFormsEntries = [];
2120
+ const entriesWithForms = [];
1986
2121
  const readingEntries = [];
1987
2122
  const titleFormMap = /* @__PURE__ */ new Map();
1988
2123
  const refsMap = /* @__PURE__ */ new Map();
@@ -1990,9 +2125,9 @@ function getWordDefinitions(entryList, jmDict) {
1990
2125
  for (const ent of pair.entriesWithTitles) {
1991
2126
  const validFormOf = validFormOfEntries.has(ent.word);
1992
2127
  const validGlosses = validGlossesEntries.has(ent.word);
1993
- const validForms = validFormsEntries.has(ent.word);
2128
+ const validForms2 = validFormsEntries.has(ent.word);
1994
2129
  const hasKanjiForms = ent.forms !== void 0 && pair.kanjiForms !== void 0 && ent.forms.some((form) => pair.kanjiForms.has(form));
1995
- if (pair.kanjiForms && pair.kanjiForms.has(ent.word) && (validFormOf || validGlosses || validForms)) {
2130
+ if (pair.kanjiForms && pair.kanjiForms.has(ent.word) && (validFormOf || validGlosses || validForms2)) {
1996
2131
  kanjiFormEntries.push(ent);
1997
2132
  if ((validFormOf || validGlosses) && ent.senses)
1998
2133
  for (const sense of ent.senses) {
@@ -2006,62 +2141,48 @@ function getWordDefinitions(entryList, jmDict) {
2006
2141
  }
2007
2142
  }
2008
2143
  if (validGlosses) {
2009
- for (const gloss of sense.glosses) {
2010
- let reading = void 0;
2011
- if (gloss.trim().includes("\u6F22\u5B57\u8868\u8A18") || gloss.trim().includes("\u53C2\u7167")) {
2012
- for (const r of pair.readings)
2013
- if (gloss.trim().includes(r)) {
2014
- reading = r;
2015
- break;
2144
+ for (const gloss of sense.glosses)
2145
+ if (gloss.includes("\u8868\u8A18") || gloss.includes("\u53C2\u7167")) {
2146
+ for (const f of pair.forms)
2147
+ if (gloss.includes(f)) {
2148
+ const elem = refsMap.get(f);
2149
+ if (!elem) refsMap.set(f, /* @__PURE__ */ new Set([ent.word]));
2150
+ else elem.add(ent.word);
2016
2151
  }
2017
2152
  }
2018
- if (reading) {
2019
- const elem = refsMap.get(reading);
2020
- if (!elem) refsMap.set(reading, /* @__PURE__ */ new Set([ent.word]));
2021
- else elem.add(ent.word);
2022
- }
2023
- }
2024
2153
  }
2025
2154
  }
2026
- if (validForms && ent.forms) {
2155
+ if (validForms2 && ent.forms) {
2027
2156
  for (const form of ent.forms)
2028
2157
  if (pair.readings.has(form)) readingForms.add(form);
2029
2158
  }
2030
2159
  }
2031
2160
  if (pair.readings.has(ent.word) && hasKanjiForms)
2032
- readingWithFormsEntries.push(ent);
2161
+ entriesWithForms.push(ent);
2033
2162
  if (pair.kanjiForms === void 0 && pair.readings.has(ent.word))
2034
2163
  readingEntries.push(ent);
2035
2164
  }
2036
2165
  for (const entry of pair.entriesWithForms) {
2037
2166
  const elem = titleFormMap.get(entry.word);
2038
2167
  if (elem && entry.forms && entry.forms.some((form) => elem.has(form)))
2039
- readingWithFormsEntries.push(entry);
2168
+ entriesWithForms.push(entry);
2040
2169
  }
2041
2170
  for (const entry of pair.entriesWithFormTitles) {
2042
2171
  if (readingForms.has(entry.word)) {
2043
- readingWithFormsEntries.push(entry);
2172
+ entriesWithForms.push(entry);
2044
2173
  continue;
2045
2174
  }
2046
- if (pair.kanjiForms) {
2047
- const ft = refsMap.get(entry.word);
2048
- if (ft && !ft.isDisjointFrom(pair.kanjiForms))
2049
- readingWithFormsEntries.push(entry);
2050
- }
2175
+ const ft = refsMap.get(entry.word);
2176
+ if (ft && !ft.isDisjointFrom(pair.forms)) entriesWithForms.push(entry);
2051
2177
  }
2052
- let parsedReadingWithFormsEntries = false;
2053
- for (const entry of kanjiFormEntries)
2054
- if (entry.pos_title === "\u548C\u8A9E\u306E\u6F22\u5B57\u8868\u8A18" && readingWithFormsEntries.length > 0) {
2055
- if (!parsedReadingWithFormsEntries)
2056
- parsedReadingWithFormsEntries = true;
2057
- for (const ref of readingWithFormsEntries)
2058
- parseEntry(ref, definitions, definitionMap);
2059
- } else parseEntry(entry, definitions, definitionMap);
2060
- if (!parsedReadingWithFormsEntries && readingWithFormsEntries.length > 0) {
2061
- parsedReadingWithFormsEntries = true;
2062
- for (const ref of readingWithFormsEntries)
2063
- parseEntry(ref, definitions, definitionMap);
2178
+ if (kanjiFormEntries.length > 0) {
2179
+ for (const entry of kanjiFormEntries)
2180
+ if (entry.pos_title !== "\u548C\u8A9E\u306E\u6F22\u5B57\u8868\u8A18")
2181
+ parseEntry(entry, definitions, definitionMap);
2064
2182
  }
2183
+ if (entriesWithForms.length > 0)
2184
+ for (const ref of entriesWithForms)
2185
+ parseEntry(ref, definitions, definitionMap);
2065
2186
  if (readingEntries.length > 0)
2066
2187
  for (const readingEntry of readingEntries)
2067
2188
  parseEntry(readingEntry, definitions, definitionMap);
@@ -2077,7 +2198,7 @@ function getWordDefinitions(entryList, jmDict) {
2077
2198
  const defCount = definitionMap.get(
2078
2199
  pair.definitions[j].definition
2079
2200
  );
2080
- if (defCount && defCount.count > 1)
2201
+ if (defCount && defCount.count > 0)
2081
2202
  pair.definitions[j].mayNotBeAccurate = true;
2082
2203
  }
2083
2204
  japaneseDefinitions[i] = pair;
@@ -2252,13 +2373,15 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
2252
2373
  }
2253
2374
  if (kanjiDic && word2.kanjiForms) {
2254
2375
  const kanji = [];
2376
+ const seenChars = /* @__PURE__ */ new Set();
2255
2377
  for (const kanjiForm of word2.kanjiForms)
2256
- for (const char of kanjiForm.kanjiForm) {
2257
- if (!regexps.kanji.test(char) || kanji.some((kanji2) => kanji2.kanji === char))
2258
- continue;
2378
+ for (const char of kanjiForm.kanjiForm.split("").filter((c) => regexps.kanji.test(c))) {
2379
+ if (seenChars.has(char)) continue;
2380
+ seenChars.add(char);
2381
+ const kanjiEntry = kanjiDic instanceof Map ? kanjiDic.get(char) : void 0;
2259
2382
  const kanjiObj = getKanji(
2260
- char,
2261
- Array.isArray(kanjiDic) ? kanjiDic : kanjiDic.get(char)
2383
+ kanjiEntry != null ? kanjiEntry : char,
2384
+ Array.isArray(kanjiDic) ? kanjiDic : void 0
2262
2385
  );
2263
2386
  if (kanjiObj)
2264
2387
  kanji.push({
@@ -2269,9 +2392,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
2269
2392
  if (kanji.length > 0) word2.kanji = kanji;
2270
2393
  }
2271
2394
  if (dictWord.hasPhrases !== void 0 && examples) {
2272
- const exampleList = Array.isArray(examples) ? examples : (_a = examples.get(
2273
- dictWord.id
2274
- )) != null ? _a : [];
2395
+ const exampleList = Array.isArray(examples) ? examples : (_a = examples.get(dictWord.id)) != null ? _a : [];
2275
2396
  const rkf = getValidForms(
2276
2397
  dictWord.readings,
2277
2398
  dictWord.kanjiForms,
@@ -2339,17 +2460,23 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
2339
2460
  }
2340
2461
  }
2341
2462
  }
2342
- if (glossSpecificExamples.length === 5) break;
2343
2463
  }
2344
- if (glossSpecificExamples.length === 5)
2345
- wordExamples = [...glossSpecificExamples];
2346
- else if (glossSpecificExamples.length > 0)
2347
- wordExamples = [
2348
- ...glossSpecificExamples,
2349
- ...wordExamples.filter(
2464
+ if (glossSpecificExamples.length === word2.translations.length)
2465
+ wordExamples = glossSpecificExamples;
2466
+ else if (glossSpecificExamples.length > 0) {
2467
+ const exes = glossSpecificExamples;
2468
+ if (exes.length < 5) {
2469
+ wordExamples = wordExamples.filter(
2350
2470
  (ex) => !seenPhrases.has(ex.ex.phrase)
2351
- ).slice(0, 5 - glossSpecificExamples.length)
2352
- ];
2471
+ );
2472
+ if (wordExamples.length > 0)
2473
+ for (const ex of wordExamples) {
2474
+ exes.push(ex);
2475
+ if (exes.length === 5) break;
2476
+ }
2477
+ }
2478
+ wordExamples = exes;
2479
+ }
2353
2480
  if (wordExamples.length > 0) {
2354
2481
  word2.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => {
2355
2482
  var _a2;
@@ -2366,9 +2493,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
2366
2493
  }
2367
2494
  }
2368
2495
  if (definitions) {
2369
- const defs = Array.isArray(definitions) ? (_b = definitions.find((wdp) => wdp.wordID === word2.id)) == null ? void 0 : _b.definitions : definitions.get(
2370
- word2.id
2371
- );
2496
+ const defs = Array.isArray(definitions) ? (_b = definitions.find((wdp) => wdp.wordID === word2.id)) == null ? void 0 : _b.definitions : definitions.get(word2.id);
2372
2497
  if (defs) word2.definitions = [...defs];
2373
2498
  }
2374
2499
  return word2;
@@ -2816,6 +2941,7 @@ ${ankiNotes}`;
2816
2941
  convertRadkFile,
2817
2942
  convertTanakaCorpus,
2818
2943
  convertTanakaCorpusWithFurigana,
2944
+ createEntryMaps,
2819
2945
  generateAnkiNote,
2820
2946
  generateAnkiNotesFile,
2821
2947
  getKanji,