henkan 0.2.1 → 0.3.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 (58) hide show
  1. package/dist/index.cjs.js +91 -54
  2. package/dist/index.cjs.js.map +3 -3
  3. package/dist/index.mjs +91 -54
  4. package/dist/index.mjs.map +3 -3
  5. package/dist/types/constants.d.ts.map +1 -1
  6. package/dist/types/types.d.ts +8 -0
  7. package/dist/types/types.d.ts.map +1 -1
  8. package/dist/types/utils.d.ts.map +1 -1
  9. package/docs/api/functions/capitalizeString.md +1 -1
  10. package/docs/api/functions/convertJMdict.md +1 -1
  11. package/docs/api/functions/convertKanjiDic.md +1 -1
  12. package/docs/api/functions/convertKradFile.md +1 -1
  13. package/docs/api/functions/convertRadkFile.md +1 -1
  14. package/docs/api/functions/convertTanakaCorpus.md +1 -1
  15. package/docs/api/functions/generateAnkiNote.md +1 -1
  16. package/docs/api/functions/generateAnkiNotesFile.md +1 -1
  17. package/docs/api/functions/getKanji.md +1 -1
  18. package/docs/api/functions/getKanjiExtended.md +1 -1
  19. package/docs/api/functions/getWord.md +1 -1
  20. package/docs/api/functions/isStringArray.md +1 -1
  21. package/docs/api/functions/isValidArray.md +1 -1
  22. package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
  23. package/docs/api/functions/makeSSML.md +1 -1
  24. package/docs/api/functions/shuffleArray.md +1 -1
  25. package/docs/api/functions/synthesizeSpeech.md +1 -1
  26. package/docs/api/interfaces/DictKanji.md +5 -5
  27. package/docs/api/interfaces/DictKanjiForm.md +4 -4
  28. package/docs/api/interfaces/DictKanjiMisc.md +5 -5
  29. package/docs/api/interfaces/DictKanjiReading.md +3 -3
  30. package/docs/api/interfaces/DictKanjiReadingMeaning.md +3 -3
  31. package/docs/api/interfaces/DictKanjiReadingMeaningGroup.md +3 -3
  32. package/docs/api/interfaces/DictKanjiWithRadicals.md +3 -3
  33. package/docs/api/interfaces/DictMeaning.md +11 -11
  34. package/docs/api/interfaces/DictRadical.md +4 -4
  35. package/docs/api/interfaces/DictReading.md +5 -5
  36. package/docs/api/interfaces/DictWord.md +7 -7
  37. package/docs/api/interfaces/ExamplePart.md +7 -7
  38. package/docs/api/interfaces/Grammar.md +15 -15
  39. package/docs/api/interfaces/GrammarMeaning.md +3 -3
  40. package/docs/api/interfaces/Kana.md +11 -11
  41. package/docs/api/interfaces/Kanji.md +22 -22
  42. package/docs/api/interfaces/KanjiComponent.md +3 -3
  43. package/docs/api/interfaces/KanjiForm.md +13 -3
  44. package/docs/api/interfaces/NoteAndTag.md +3 -3
  45. package/docs/api/interfaces/Phrase.md +4 -4
  46. package/docs/api/interfaces/Radical.md +16 -16
  47. package/docs/api/interfaces/Reading.md +14 -4
  48. package/docs/api/interfaces/ResultEntry.md +7 -7
  49. package/docs/api/interfaces/TanakaExample.md +5 -5
  50. package/docs/api/interfaces/Translation.md +3 -3
  51. package/docs/api/interfaces/UsefulRegExps.md +9 -9
  52. package/docs/api/interfaces/Word.md +14 -14
  53. package/docs/api/type-aliases/Dict.md +1 -1
  54. package/docs/api/type-aliases/DictName.md +1 -1
  55. package/docs/api/type-aliases/EntryType.md +1 -1
  56. package/docs/api/type-aliases/JLPT.md +1 -1
  57. package/docs/api/type-aliases/Result.md +1 -1
  58. package/package.json +8 -8
package/dist/index.cjs.js CHANGED
@@ -121,10 +121,21 @@ var symbolMap = {
121
121
  "&": "\u30A2\u30F3\u30C9"
122
122
  };
123
123
  var notSearchedForms = /* @__PURE__ */ new Set([
124
+ "search-only kana form",
124
125
  "Search-only kana form",
126
+ "rarely used kana form",
125
127
  "Rarely used kana form",
128
+ "out-dated or obsolete kana usage",
126
129
  "Out-dated or obsolete kana usage",
127
- "Word containing out-dated kanji or kanji usage"
130
+ "search-only kanji form",
131
+ "Search-only kanji form",
132
+ "rarely-used kanji form",
133
+ "Rarely-used kanji form",
134
+ "out-dated kanji",
135
+ "Out-dated kanji form",
136
+ "out-dated kanji or kanji usage",
137
+ "word containing out-dated kanji or kanji usage",
138
+ "Out-dated kanji or kanji usage"
128
139
  ]);
129
140
  var noteMap = /* @__PURE__ */ new Map([
130
141
  ["brazilian", ["dialect::brazilian", "Dialect: Brazilian"]],
@@ -1214,13 +1225,15 @@ function convertJMdict(xmlString, examples) {
1214
1225
  const dict = [];
1215
1226
  import_xml2js.default.parseString(dictParsed, (err, result) => {
1216
1227
  if (err) throw err;
1217
- let tanakaBaseParts = void 0;
1218
- if (examples)
1219
- tanakaBaseParts = new Set(
1220
- examples.map(
1221
- (example) => example.parts.map((part) => part.baseForm)
1222
- ).flat()
1223
- );
1228
+ const tanakaParts = examples && examples.length > 0 ? new Set(
1229
+ examples.map(
1230
+ (example) => example.parts.map((part) => [
1231
+ part.baseForm,
1232
+ ...part.reading ? [part.reading] : [],
1233
+ ...part.referenceID ? [part.referenceID] : []
1234
+ ])
1235
+ ).flat(2)
1236
+ ) : void 0;
1224
1237
  if (result.JMdict && typeof result.JMdict === "object" && isValidArray(result.JMdict.entry))
1225
1238
  for (const entry of result.JMdict.entry) {
1226
1239
  const entryObj = {
@@ -1304,34 +1317,36 @@ function convertJMdict(xmlString, examples) {
1304
1317
  if (examples) {
1305
1318
  const readings2 = new Set(
1306
1319
  entryObj.readings.filter(
1307
- (reading) => !reading.notes || reading.notes && !reading.notes.some(
1320
+ (reading) => (!reading.notes || !reading.notes.some(
1308
1321
  (note) => notSearchedForms.has(note)
1309
- )
1322
+ )) && (entryObj.isCommon === void 0 || reading.commonness && reading.commonness.length > 0)
1310
1323
  ).map((reading) => reading.reading)
1311
1324
  );
1312
1325
  const kanjiForms2 = entryObj.kanjiForms ? new Set(
1313
- entryObj.kanjiForms.map(
1314
- (kanjiForm) => kanjiForm.form
1315
- )
1326
+ entryObj.kanjiForms.filter(
1327
+ (kanjiForm) => (!kanjiForm.notes || !kanjiForm.notes.some(
1328
+ (note) => notSearchedForms.has(note)
1329
+ )) && (entryObj.isCommon === void 0 || kanjiForm.commonness && kanjiForm.commonness.length > 0)
1330
+ ).map((kanjiForm) => kanjiForm.form)
1316
1331
  ) : void 0;
1317
- let kanjiFormExamples = false;
1318
- let readingExamples = false;
1319
- if (kanjiForms2 && kanjiForms2.size > 0 && tanakaBaseParts) {
1332
+ let existsExample = false;
1333
+ if (kanjiForms2 && kanjiForms2.size > 0 && tanakaParts) {
1320
1334
  for (const kf of kanjiForms2)
1321
- if (tanakaBaseParts.has(kf)) {
1322
- kanjiFormExamples = true;
1335
+ if (tanakaParts.has(kf)) {
1336
+ existsExample = true;
1323
1337
  break;
1324
1338
  }
1325
1339
  }
1326
- if (!kanjiFormExamples && readings2.size > 0 && tanakaBaseParts) {
1340
+ if (!existsExample && readings2.size > 0 && tanakaParts) {
1327
1341
  for (const r of readings2)
1328
- if (tanakaBaseParts.has(r)) {
1329
- readingExamples = true;
1342
+ if (tanakaParts.has(r)) {
1343
+ existsExample = true;
1330
1344
  break;
1331
1345
  }
1332
1346
  }
1333
- if (kanjiFormExamples || readingExamples)
1334
- entryObj.hasPhrases = true;
1347
+ if (!existsExample && tanakaParts && tanakaParts.has(entryObj.id))
1348
+ existsExample = true;
1349
+ if (existsExample) entryObj.hasPhrases = true;
1335
1350
  }
1336
1351
  if (entryObj.id.length > 0 && entryObj.readings.length > 0 && entryObj.meanings.length > 0)
1337
1352
  dict.push(entryObj);
@@ -1625,7 +1640,8 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1625
1640
  );
1626
1641
  return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
1627
1642
  })
1628
- } : {}
1643
+ } : {},
1644
+ ...dictKanjiForm.commonness && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
1629
1645
  })
1630
1646
  );
1631
1647
  word.readings = dictWord.readings.map((dictReading) => ({
@@ -1647,7 +1663,8 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1647
1663
  return capitalizeString((_a = noteAndTag.note) != null ? _a : note);
1648
1664
  }) : []
1649
1665
  ]
1650
- } : {}
1666
+ } : {},
1667
+ ...dictReading.commonness && dictReading.commonness.length > 0 ? { common: true } : {}
1651
1668
  }));
1652
1669
  let usuallyInKanaMeanings = 0;
1653
1670
  word.translations = dictWord.meanings.map((dictMeaning) => {
@@ -1740,36 +1757,61 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1740
1757
  if (word.kanji.length === 0) delete word.kanji;
1741
1758
  }
1742
1759
  if (examples && dictWord.hasPhrases === true) {
1760
+ let pushIfUnique2 = function(ex) {
1761
+ if (!seenPhrases.has(ex.phrase)) {
1762
+ wordExamples.push(ex);
1763
+ seenPhrases.add(ex.phrase);
1764
+ }
1765
+ };
1766
+ var pushIfUnique = pushIfUnique2;
1743
1767
  const readings = new Set(
1744
1768
  word.readings.filter(
1745
- (reading) => !reading.notes || reading.notes && !reading.notes.some(
1769
+ (reading) => (!reading.notes || !reading.notes.some(
1746
1770
  (note) => notSearchedForms.has(note)
1747
- )
1771
+ )) && (word.common === void 0 || reading.common === true)
1748
1772
  ).map((reading) => reading.reading)
1749
1773
  );
1750
1774
  const kanjiForms = word.kanjiForms ? new Set(
1751
- word.kanjiForms.map(
1752
- (kanjiForm) => kanjiForm.kanjiForm
1753
- )
1775
+ word.kanjiForms.filter(
1776
+ (kanjiForm) => (!kanjiForm.notes || !kanjiForm.notes.some(
1777
+ (note) => notSearchedForms.has(note)
1778
+ )) && (word.common === void 0 || kanjiForm.common === true)
1779
+ ).map((kanjiForm) => kanjiForm.kanjiForm)
1754
1780
  ) : void 0;
1755
1781
  const kanjiFormExamples = [];
1782
+ const readingMatchingKanjiFormExamples = [];
1756
1783
  const readingExamples = [];
1757
- if (kanjiForms) {
1758
- for (const example of examples)
1759
- for (const part of example.parts)
1760
- if (kanjiForms.has(part.baseForm))
1761
- kanjiFormExamples.push(example);
1762
- }
1763
- if (kanjiFormExamples.length === 0) {
1764
- for (const example of examples)
1765
- for (const part of example.parts)
1766
- if (readings.has(part.baseForm)) readingExamples.push(example);
1767
- }
1768
- examples = [...kanjiFormExamples, ...readingExamples];
1784
+ for (const example of examples)
1785
+ for (const part of example.parts) {
1786
+ const readingMatch = part.reading && readings.has(part.reading) || readings.has(part.baseForm);
1787
+ if (kanjiForms && kanjiForms.size > 0 && kanjiForms.has(part.baseForm)) {
1788
+ if (readingMatch) readingMatchingKanjiFormExamples.push(example);
1789
+ else kanjiFormExamples.push(example);
1790
+ break;
1791
+ }
1792
+ if (readingMatch || part.referenceID && word.id && part.referenceID === word.id) {
1793
+ readingExamples.push(example);
1794
+ break;
1795
+ }
1796
+ }
1797
+ const exampleSize = (/* @__PURE__ */ new Set([
1798
+ ...readingMatchingKanjiFormExamples,
1799
+ ...kanjiFormExamples,
1800
+ ...readingExamples
1801
+ ])).size;
1802
+ const includeKanjiFormExamples = readingMatchingKanjiFormExamples.length < Math.max(2, Math.round(exampleSize * 0.05));
1803
+ const includeReadingExamples = word.usuallyInKana === void 0 && includeKanjiFormExamples && readingExamples.length >= Math.max(10, Math.round(exampleSize * 0.15)) || word.usuallyInKana === true && readingExamples.length >= Math.max(2, Math.round(exampleSize * 0.5));
1804
+ const seenPhrases = /* @__PURE__ */ new Set();
1805
+ let wordExamples = [];
1806
+ for (const ex of readingMatchingKanjiFormExamples) pushIfUnique2(ex);
1807
+ if (includeKanjiFormExamples)
1808
+ for (const ex of kanjiFormExamples) pushIfUnique2(ex);
1809
+ if (includeReadingExamples)
1810
+ for (const ex of readingExamples) pushIfUnique2(ex);
1769
1811
  if (word.translations) {
1770
1812
  const glossSpecificExamples = [];
1771
1813
  for (let i = 0; i < word.translations.length; i++) {
1772
- outer: for (const example of examples)
1814
+ outer: for (const example of wordExamples)
1773
1815
  for (const part of example.parts)
1774
1816
  if (part.glossNumber === i + 1) {
1775
1817
  glossSpecificExamples.push(example);
@@ -1778,24 +1820,19 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1778
1820
  if (glossSpecificExamples.length === 5) break;
1779
1821
  }
1780
1822
  if (glossSpecificExamples.length === 5)
1781
- examples = glossSpecificExamples;
1823
+ wordExamples = glossSpecificExamples;
1782
1824
  else if (glossSpecificExamples.length > 0) {
1783
- const seenPhrases = new Set(
1825
+ const seenPhrases2 = new Set(
1784
1826
  glossSpecificExamples.map((ex) => ex.phrase)
1785
1827
  );
1786
- examples = [
1828
+ wordExamples = [
1787
1829
  ...glossSpecificExamples,
1788
- ...examples.filter((ex) => !seenPhrases.has(ex.phrase)).slice(0, 5 - glossSpecificExamples.length)
1830
+ ...wordExamples.filter((ex) => !seenPhrases2.has(ex.phrase)).slice(0, 5 - glossSpecificExamples.length)
1789
1831
  ];
1790
1832
  }
1791
1833
  }
1792
- examples = examples.filter(
1793
- (example, index, arr) => arr.findIndex(
1794
- (ex) => ex.phrase === example.phrase
1795
- ) === index
1796
- );
1797
- if (examples.length > 0)
1798
- word.phrases = (examples.length > 5 ? examples.slice(0, 5) : examples).map((ex) => {
1834
+ if (wordExamples.length > 0)
1835
+ word.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => {
1799
1836
  var _a;
1800
1837
  return {
1801
1838
  phrase: (_a = ex.furigana) != null ? _a : ex.phrase,