henkan 3.0.0 → 3.0.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/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
@@ -1430,7 +1430,6 @@ function convertJMdict(xmlString, examples) {
1430
1430
  (example) => example.parts.flatMap((part) => [
1431
1431
  part.baseForm,
1432
1432
  ...part.reading !== void 0 ? [part.reading] : [],
1433
- ...part.inflectedForm !== void 0 ? [part.inflectedForm] : [],
1434
1433
  ...part.referenceID !== void 0 ? [part.referenceID] : []
1435
1434
  ])
1436
1435
  )
@@ -1556,7 +1555,6 @@ function convertJMnedict(xmlString, examples) {
1556
1555
  (example) => example.parts.flatMap((part) => [
1557
1556
  part.baseForm,
1558
1557
  ...part.reading !== void 0 ? [part.reading] : [],
1559
- ...part.inflectedForm !== void 0 ? [part.inflectedForm] : [],
1560
1558
  ...part.referenceID !== void 0 ? [part.referenceID] : []
1561
1559
  ])
1562
1560
  )
@@ -1900,14 +1898,6 @@ function createEntryMaps(jmDict, jmNedict, kanjiDic, tanakaExamples, wordDefinit
1900
1898
  if (exList === void 0) partExamplesMap.set(part.reading, [ex]);
1901
1899
  else exList.push(ex);
1902
1900
  }
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
1901
  if (part.referenceID !== void 0 && entryParts.has(part.referenceID)) {
1912
1902
  const exList = partExamplesMap.get(
1913
1903
  part.referenceID
@@ -1977,14 +1967,6 @@ function createEntryMaps(jmDict, jmNedict, kanjiDic, tanakaExamples, wordDefinit
1977
1967
  if (exList === void 0) partExamplesMap.set(part.reading, [ex]);
1978
1968
  else exList.push(ex);
1979
1969
  }
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
1970
  }
1989
1971
  for (const name of jmNedict) {
1990
1972
  const seenEx = /* @__PURE__ */ new Set();
@@ -2788,37 +2770,42 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
2788
2770
  const readingMatchingKanjiFormExamples = [];
2789
2771
  let kanjiFormExamples = [];
2790
2772
  let readingExamples = [];
2773
+ let hasKanjiFormExamplesWithTranslation = false;
2774
+ let hasReadingExamplesWithTranslation = false;
2791
2775
  for (const example of exampleList)
2792
2776
  for (let i = 0; i < example.parts.length; i++) {
2793
2777
  if (seenPhrases.has(example.phrase)) break;
2794
- const includesTranslation = meanings.some(
2795
- (m) => example.translation.includes(m)
2796
- );
2797
2778
  const part = example.parts[i];
2798
2779
  const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
2799
- const readingAsInflectedFormMatch = part.inflectedForm !== void 0 && readings.has(part.inflectedForm);
2800
2780
  const referenceIDMatch = part.referenceID === dictWord.id;
2801
2781
  if (kanjiForms !== void 0 && kanjiForms.has(part.baseForm)) {
2802
- if (readingAsReadingMatch || readingAsInflectedFormMatch || referenceIDMatch)
2782
+ if (readingAsReadingMatch || referenceIDMatch)
2803
2783
  readingMatchingKanjiFormExamples.push({
2804
2784
  ex: example,
2805
- partIndex: i,
2806
- form: part.baseForm,
2807
- ...referenceIDMatch ? { referenceIDMatch: true } : {},
2808
- ...includesTranslation ? { includesTranslation: true } : {}
2785
+ partIndex: i
2809
2786
  });
2810
- else
2787
+ else {
2788
+ const includesTranslation = meanings.some(
2789
+ (m) => example.translation.includes(m)
2790
+ );
2791
+ if (!hasKanjiFormExamplesWithTranslation && includesTranslation)
2792
+ hasKanjiFormExamplesWithTranslation = true;
2811
2793
  kanjiFormExamples.push({
2812
2794
  ex: example,
2813
2795
  partIndex: i,
2814
- form: part.baseForm,
2815
2796
  ...includesTranslation ? { includesTranslation: true } : {}
2816
2797
  });
2798
+ }
2817
2799
  seenPhrases.add(example.phrase);
2818
2800
  break;
2819
2801
  }
2820
2802
  const readingAsBaseFormMatch = readings.has(part.baseForm);
2821
2803
  if ((readingAsBaseFormMatch || referenceIDMatch) && kanjiForms === void 0) {
2804
+ const includesTranslation = meanings.some(
2805
+ (m) => example.translation.includes(m)
2806
+ );
2807
+ if (!hasReadingExamplesWithTranslation && includesTranslation)
2808
+ hasReadingExamplesWithTranslation = true;
2822
2809
  readingExamples.push({
2823
2810
  ex: example,
2824
2811
  partIndex: i,
@@ -2829,21 +2816,13 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
2829
2816
  break;
2830
2817
  }
2831
2818
  }
2832
- if (kanjiFormExamples.length > 0 && kanjiFormExamples.some(
2833
- (ex) => ex.includesTranslation === true || ex.ex.parts.some(
2834
- (part) => ex.form === part.baseForm && part.glossNumber !== void 0
2835
- )
2836
- ))
2819
+ if (kanjiFormExamples.length > 0 && hasKanjiFormExamplesWithTranslation)
2837
2820
  kanjiFormExamples = kanjiFormExamples.filter(
2838
- (ex) => ex.includesTranslation === true || ex.ex.parts.some(
2839
- (part) => ex.form === part.baseForm && part.glossNumber !== void 0
2840
- )
2821
+ (ex) => ex.includesTranslation === true
2841
2822
  );
2842
2823
  else if (kanjiFormExamples.length > 0 && readingMatchingKanjiFormExamples.length > 0)
2843
2824
  kanjiFormExamples.length = 0;
2844
- if (readingExamples.length > 0 && readingExamples.some(
2845
- (ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
2846
- ))
2825
+ if (readingExamples.length > 0 && hasReadingExamplesWithTranslation)
2847
2826
  readingExamples = readingExamples.filter(
2848
2827
  (ex) => ex.includesTranslation === true || ex.referenceIDMatch === true
2849
2828
  );
@@ -3020,29 +2999,32 @@ function getName(searchedName, dict, kanjiDic, examples, noteTypeName, deckPath)
3020
2999
  for (const example of exampleList)
3021
3000
  for (let i = 0; i < example.parts.length; i++) {
3022
3001
  if (seenPhrases.has(example.phrase)) break;
3023
- const includesTranslation = meanings.some(
3024
- (m) => example.translation.includes(m)
3025
- );
3026
3002
  const part = example.parts[i];
3027
3003
  const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
3028
3004
  if (kanjiForms !== void 0 && kanjiForms.has(part.baseForm) && readingAsReadingMatch) {
3005
+ const includesTranslation = meanings.some(
3006
+ (m) => example.translation.includes(m)
3007
+ );
3008
+ if (!hasReadingMatchingKanjiFormWithTranslation && includesTranslation)
3009
+ hasReadingMatchingKanjiFormWithTranslation = true;
3029
3010
  readingMatchingKanjiFormExamples.push({
3030
3011
  ex: example,
3031
3012
  ...includesTranslation ? { includesTranslation: true } : {}
3032
3013
  });
3033
- if (!hasReadingMatchingKanjiFormWithTranslation && includesTranslation)
3034
- hasReadingMatchingKanjiFormWithTranslation = true;
3035
3014
  seenPhrases.add(example.phrase);
3036
3015
  break;
3037
3016
  }
3038
3017
  const readingAsBaseFormMatch = readings.has(part.baseForm);
3039
3018
  if (readingAsBaseFormMatch && kanjiForms === void 0) {
3019
+ const includesTranslation = meanings.some(
3020
+ (m) => example.translation.includes(m)
3021
+ );
3022
+ if (!hasReadingWithTranslation && includesTranslation)
3023
+ hasReadingWithTranslation = true;
3040
3024
  readingExamples.push({
3041
3025
  ex: example,
3042
3026
  ...includesTranslation ? { includesTranslation: true } : {}
3043
3027
  });
3044
- if (!hasReadingWithTranslation && includesTranslation)
3045
- hasReadingWithTranslation = true;
3046
3028
  seenPhrases.add(example.phrase);
3047
3029
  break;
3048
3030
  }