henkan 0.2.1 → 0.3.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.
Files changed (58) hide show
  1. package/dist/index.cjs.js +72 -37
  2. package/dist/index.cjs.js.map +3 -3
  3. package/dist/index.mjs +72 -37
  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.mjs CHANGED
@@ -65,10 +65,21 @@ var symbolMap = {
65
65
  "&": "\u30A2\u30F3\u30C9"
66
66
  };
67
67
  var notSearchedForms = /* @__PURE__ */ new Set([
68
+ "search-only kana form",
68
69
  "Search-only kana form",
70
+ "rarely used kana form",
69
71
  "Rarely used kana form",
72
+ "out-dated or obsolete kana usage",
70
73
  "Out-dated or obsolete kana usage",
71
- "Word containing out-dated kanji or kanji usage"
74
+ "search-only kanji form",
75
+ "Search-only kanji form",
76
+ "rarely-used kanji form",
77
+ "Rarely-used kanji form",
78
+ "out-dated kanji",
79
+ "Out-dated kanji form",
80
+ "out-dated kanji or kanji usage",
81
+ "word containing out-dated kanji or kanji usage",
82
+ "Out-dated kanji or kanji usage"
72
83
  ]);
73
84
  var noteMap = /* @__PURE__ */ new Map([
74
85
  ["brazilian", ["dialect::brazilian", "Dialect: Brazilian"]],
@@ -1250,15 +1261,17 @@ function convertJMdict(xmlString, examples) {
1250
1261
  if (examples) {
1251
1262
  const readings2 = new Set(
1252
1263
  entryObj.readings.filter(
1253
- (reading) => !reading.notes || reading.notes && !reading.notes.some(
1264
+ (reading) => !reading.notes || !reading.notes.some(
1254
1265
  (note) => notSearchedForms.has(note)
1255
1266
  )
1256
1267
  ).map((reading) => reading.reading)
1257
1268
  );
1258
1269
  const kanjiForms2 = entryObj.kanjiForms ? new Set(
1259
- entryObj.kanjiForms.map(
1260
- (kanjiForm) => kanjiForm.form
1261
- )
1270
+ entryObj.kanjiForms.filter(
1271
+ (kanjiForm) => !kanjiForm.notes || !kanjiForm.notes.some(
1272
+ (note) => notSearchedForms.has(note)
1273
+ )
1274
+ ).map((kanjiForm) => kanjiForm.form)
1262
1275
  ) : void 0;
1263
1276
  let kanjiFormExamples = false;
1264
1277
  let readingExamples = false;
@@ -1269,7 +1282,7 @@ function convertJMdict(xmlString, examples) {
1269
1282
  break;
1270
1283
  }
1271
1284
  }
1272
- if (!kanjiFormExamples && readings2.size > 0 && tanakaBaseParts) {
1285
+ if ((!kanjiFormExamples || entryObj.isCommon === true) && readings2.size > 0 && tanakaBaseParts) {
1273
1286
  for (const r of readings2)
1274
1287
  if (tanakaBaseParts.has(r)) {
1275
1288
  readingExamples = true;
@@ -1570,7 +1583,8 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1570
1583
  );
1571
1584
  return capitalizeString(noteAndTag.note ?? note);
1572
1585
  })
1573
- } : {}
1586
+ } : {},
1587
+ ...dictKanjiForm.commonness && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
1574
1588
  })
1575
1589
  );
1576
1590
  word.readings = dictWord.readings.map((dictReading) => ({
@@ -1591,7 +1605,8 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1591
1605
  return capitalizeString(noteAndTag.note ?? note);
1592
1606
  }) : []
1593
1607
  ]
1594
- } : {}
1608
+ } : {},
1609
+ ...dictReading.commonness && dictReading.commonness.length > 0 ? { common: true } : {}
1595
1610
  }));
1596
1611
  let usuallyInKanaMeanings = 0;
1597
1612
  word.translations = dictWord.meanings.map((dictMeaning) => {
@@ -1684,36 +1699,61 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1684
1699
  if (word.kanji.length === 0) delete word.kanji;
1685
1700
  }
1686
1701
  if (examples && dictWord.hasPhrases === true) {
1702
+ let pushIfUnique2 = function(ex) {
1703
+ if (!seenPhrases.has(ex.phrase)) {
1704
+ wordExamples.push(ex);
1705
+ seenPhrases.add(ex.phrase);
1706
+ }
1707
+ };
1708
+ var pushIfUnique = pushIfUnique2;
1687
1709
  const readings = new Set(
1688
1710
  word.readings.filter(
1689
- (reading) => !reading.notes || reading.notes && !reading.notes.some(
1711
+ (reading) => (!reading.notes || !reading.notes.some(
1690
1712
  (note) => notSearchedForms.has(note)
1691
- )
1713
+ )) && (word.common === void 0 || reading.common === true)
1692
1714
  ).map((reading) => reading.reading)
1693
1715
  );
1694
1716
  const kanjiForms = word.kanjiForms ? new Set(
1695
- word.kanjiForms.map(
1696
- (kanjiForm) => kanjiForm.kanjiForm
1697
- )
1717
+ word.kanjiForms.filter(
1718
+ (kanjiForm) => (!kanjiForm.notes || !kanjiForm.notes.some(
1719
+ (note) => notSearchedForms.has(note)
1720
+ )) && (word.common === void 0 || kanjiForm.common === true)
1721
+ ).map((kanjiForm) => kanjiForm.kanjiForm)
1698
1722
  ) : void 0;
1699
1723
  const kanjiFormExamples = [];
1724
+ const readingMatchingKanjiFormExamples = [];
1700
1725
  const readingExamples = [];
1701
- if (kanjiForms) {
1702
- for (const example of examples)
1703
- for (const part of example.parts)
1704
- if (kanjiForms.has(part.baseForm))
1705
- kanjiFormExamples.push(example);
1706
- }
1707
- if (kanjiFormExamples.length === 0) {
1708
- for (const example of examples)
1709
- for (const part of example.parts)
1710
- if (readings.has(part.baseForm)) readingExamples.push(example);
1711
- }
1712
- examples = [...kanjiFormExamples, ...readingExamples];
1726
+ for (const example of examples)
1727
+ for (const part of example.parts) {
1728
+ const readingMatch = part.reading && readings.has(part.reading) || readings.has(part.baseForm);
1729
+ if (kanjiForms && kanjiForms.size > 0 && kanjiForms.has(part.baseForm)) {
1730
+ if (readingMatch) readingMatchingKanjiFormExamples.push(example);
1731
+ else kanjiFormExamples.push(example);
1732
+ break;
1733
+ }
1734
+ if (readingMatch || part.referenceID && word.id && part.referenceID === word.id) {
1735
+ readingExamples.push(example);
1736
+ break;
1737
+ }
1738
+ }
1739
+ const exampleSize = (/* @__PURE__ */ new Set([
1740
+ ...readingMatchingKanjiFormExamples,
1741
+ ...kanjiFormExamples,
1742
+ ...readingExamples
1743
+ ])).size;
1744
+ const includeKanjiFormExamples = readingMatchingKanjiFormExamples.length < Math.max(2, Math.round(exampleSize * 0.05));
1745
+ 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));
1746
+ const seenPhrases = /* @__PURE__ */ new Set();
1747
+ let wordExamples = [];
1748
+ for (const ex of readingMatchingKanjiFormExamples) pushIfUnique2(ex);
1749
+ if (includeKanjiFormExamples)
1750
+ for (const ex of kanjiFormExamples) pushIfUnique2(ex);
1751
+ if (includeReadingExamples)
1752
+ for (const ex of readingExamples) pushIfUnique2(ex);
1713
1753
  if (word.translations) {
1714
1754
  const glossSpecificExamples = [];
1715
1755
  for (let i = 0; i < word.translations.length; i++) {
1716
- outer: for (const example of examples)
1756
+ outer: for (const example of wordExamples)
1717
1757
  for (const part of example.parts)
1718
1758
  if (part.glossNumber === i + 1) {
1719
1759
  glossSpecificExamples.push(example);
@@ -1722,24 +1762,19 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
1722
1762
  if (glossSpecificExamples.length === 5) break;
1723
1763
  }
1724
1764
  if (glossSpecificExamples.length === 5)
1725
- examples = glossSpecificExamples;
1765
+ wordExamples = glossSpecificExamples;
1726
1766
  else if (glossSpecificExamples.length > 0) {
1727
- const seenPhrases = new Set(
1767
+ const seenPhrases2 = new Set(
1728
1768
  glossSpecificExamples.map((ex) => ex.phrase)
1729
1769
  );
1730
- examples = [
1770
+ wordExamples = [
1731
1771
  ...glossSpecificExamples,
1732
- ...examples.filter((ex) => !seenPhrases.has(ex.phrase)).slice(0, 5 - glossSpecificExamples.length)
1772
+ ...wordExamples.filter((ex) => !seenPhrases2.has(ex.phrase)).slice(0, 5 - glossSpecificExamples.length)
1733
1773
  ];
1734
1774
  }
1735
1775
  }
1736
- examples = examples.filter(
1737
- (example, index, arr) => arr.findIndex(
1738
- (ex) => ex.phrase === example.phrase
1739
- ) === index
1740
- );
1741
- if (examples.length > 0)
1742
- word.phrases = (examples.length > 5 ? examples.slice(0, 5) : examples).map((ex) => ({
1776
+ if (wordExamples.length > 0)
1777
+ word.phrases = (wordExamples.length > 5 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => ({
1743
1778
  phrase: ex.furigana ?? ex.phrase,
1744
1779
  translation: ex.translation,
1745
1780
  originalPhrase: ex.phrase