henkan 0.3.2 → 0.3.3
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 +31 -29
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +31 -29
- package/dist/index.mjs.map +3 -3
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/functions/capitalizeString.md +1 -1
- package/docs/api/functions/convertJMdict.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/generateAnkiNote.md +1 -1
- package/docs/api/functions/generateAnkiNotesFile.md +1 -1
- package/docs/api/functions/getKanji.md +1 -1
- package/docs/api/functions/getKanjiExtended.md +1 -1
- package/docs/api/functions/getWord.md +1 -1
- package/docs/api/functions/isStringArray.md +1 -1
- package/docs/api/functions/isValidArray.md +1 -1
- package/docs/api/functions/isValidArrayWithFirstElement.md +1 -1
- package/docs/api/functions/makeSSML.md +1 -1
- package/docs/api/functions/shuffleArray.md +1 -1
- package/docs/api/functions/synthesizeSpeech.md +1 -1
- package/docs/api/interfaces/DictKanji.md +5 -5
- package/docs/api/interfaces/DictKanjiForm.md +4 -4
- package/docs/api/interfaces/DictKanjiMisc.md +5 -5
- package/docs/api/interfaces/DictKanjiReading.md +3 -3
- package/docs/api/interfaces/DictKanjiReadingMeaning.md +3 -3
- package/docs/api/interfaces/DictKanjiReadingMeaningGroup.md +3 -3
- package/docs/api/interfaces/DictKanjiWithRadicals.md +3 -3
- package/docs/api/interfaces/DictMeaning.md +11 -11
- package/docs/api/interfaces/DictRadical.md +4 -4
- package/docs/api/interfaces/DictReading.md +5 -5
- package/docs/api/interfaces/DictWord.md +7 -7
- package/docs/api/interfaces/ExamplePart.md +7 -7
- package/docs/api/interfaces/Grammar.md +15 -15
- package/docs/api/interfaces/GrammarMeaning.md +3 -3
- package/docs/api/interfaces/Kana.md +11 -11
- package/docs/api/interfaces/Kanji.md +22 -22
- 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/Phrase.md +4 -4
- 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/TanakaExample.md +5 -5
- package/docs/api/interfaces/Translation.md +3 -3
- package/docs/api/interfaces/UsefulRegExps.md +9 -9
- package/docs/api/interfaces/Word.md +14 -14
- package/docs/api/type-aliases/Dict.md +1 -1
- package/docs/api/type-aliases/DictName.md +1 -1
- package/docs/api/type-aliases/EntryType.md +1 -1
- package/docs/api/type-aliases/JLPT.md +1 -1
- package/docs/api/type-aliases/Result.md +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -14,7 +14,7 @@ var regexps = {
|
|
|
14
14
|
regExChars: /[-\/\\^$*+?.()|[\]{}]/,
|
|
15
15
|
tanakaID: /#ID=\d+_\d+$/,
|
|
16
16
|
tanakaPart: /(?<base>[^()\[\]\{\}\s]+)(?:\((?<reading>[\S]+)\))?(?:\[(?<glossnum>[\S]+)\])?(?:\{(?<inflection>[\S]+)\})?/,
|
|
17
|
-
tanakaReferenceID: /#([\d]+)/
|
|
17
|
+
tanakaReferenceID: /#(?<entryid>[\d]+)/
|
|
18
18
|
};
|
|
19
19
|
var romajiMap = {
|
|
20
20
|
A: "\u30A8\u30FC",
|
|
@@ -1408,9 +1408,9 @@ async function convertTanakaCorpus(tanakaString, generateFurigana) {
|
|
|
1408
1408
|
if (reading)
|
|
1409
1409
|
if (regexps.tanakaReferenceID.test(reading)) {
|
|
1410
1410
|
const referenceID = regexps.tanakaReferenceID.exec(reading);
|
|
1411
|
-
if (!referenceID)
|
|
1411
|
+
if (!referenceID || !referenceID.groups || !referenceID.groups["entryid"])
|
|
1412
1412
|
throw new Error(`Invalid reference ID: ${reading}`);
|
|
1413
|
-
examplePart.referenceID = referenceID[
|
|
1413
|
+
examplePart.referenceID = referenceID.groups["entryid"];
|
|
1414
1414
|
} else examplePart.reading = reading;
|
|
1415
1415
|
if (glossNumber)
|
|
1416
1416
|
examplePart.glossNumber = glossNumber.startsWith("0") ? Number.parseInt(glossNumber.substring(1)) : Number.parseInt(glossNumber);
|
|
@@ -1702,13 +1702,6 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1702
1702
|
if (word.kanji.length === 0) delete word.kanji;
|
|
1703
1703
|
}
|
|
1704
1704
|
if (examples && dictWord.hasPhrases === true) {
|
|
1705
|
-
let pushIfUnique2 = function(ex) {
|
|
1706
|
-
if (!seenPhrases.has(ex.phrase)) {
|
|
1707
|
-
wordExamples.push(ex);
|
|
1708
|
-
seenPhrases.add(ex.phrase);
|
|
1709
|
-
}
|
|
1710
|
-
};
|
|
1711
|
-
var pushIfUnique = pushIfUnique2;
|
|
1712
1705
|
const readings = new Set(
|
|
1713
1706
|
word.readings.filter(
|
|
1714
1707
|
(reading) => (!reading.notes || !reading.notes.some(
|
|
@@ -1726,46 +1719,55 @@ function getWord(dict, id, kanjiDic, examples, dictWord, noteTypeName, deckPath)
|
|
|
1726
1719
|
const kanjiFormExamples = [];
|
|
1727
1720
|
const readingMatchingKanjiFormExamples = [];
|
|
1728
1721
|
const readingExamples = [];
|
|
1722
|
+
const partParts = /* @__PURE__ */ new Set();
|
|
1729
1723
|
for (const example of examples)
|
|
1730
1724
|
for (const part of example.parts) {
|
|
1731
|
-
const
|
|
1725
|
+
const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
|
|
1732
1726
|
if (kanjiForms && kanjiForms.size > 0 && kanjiForms.has(part.baseForm)) {
|
|
1733
|
-
if (
|
|
1734
|
-
|
|
1727
|
+
if (readingAsReadingMatch) {
|
|
1728
|
+
readingMatchingKanjiFormExamples.push(example);
|
|
1729
|
+
partParts.add(part.baseForm).add(part.reading);
|
|
1730
|
+
} else {
|
|
1731
|
+
kanjiFormExamples.push(example);
|
|
1732
|
+
partParts.add(part.baseForm);
|
|
1733
|
+
}
|
|
1735
1734
|
break;
|
|
1736
1735
|
}
|
|
1737
|
-
|
|
1736
|
+
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
1737
|
+
const referenceIDMatch = part.referenceID !== void 0 && word.id !== void 0 && part.referenceID === word.id;
|
|
1738
|
+
if (readingAsReadingMatch || readingAsBaseFormMatch || referenceIDMatch) {
|
|
1738
1739
|
readingExamples.push(example);
|
|
1740
|
+
if (readingAsReadingMatch) partParts.add(part.reading);
|
|
1741
|
+
if (readingAsBaseFormMatch) partParts.add(part.baseForm);
|
|
1742
|
+
if (referenceIDMatch) partParts.add(part.referenceID);
|
|
1739
1743
|
break;
|
|
1740
1744
|
}
|
|
1741
1745
|
}
|
|
1742
|
-
const exampleSize =
|
|
1743
|
-
...readingMatchingKanjiFormExamples,
|
|
1744
|
-
...kanjiFormExamples,
|
|
1745
|
-
...readingExamples
|
|
1746
|
-
])).size;
|
|
1746
|
+
const exampleSize = readingMatchingKanjiFormExamples.length + kanjiFormExamples.length + readingExamples.length;
|
|
1747
1747
|
const includeKanjiFormExamples = readingMatchingKanjiFormExamples.length < Math.max(2, Math.round(exampleSize * 0.05));
|
|
1748
1748
|
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));
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
if (includeReadingExamples)
|
|
1755
|
-
for (const ex of readingExamples) pushIfUnique2(ex);
|
|
1749
|
+
let wordExamples = [
|
|
1750
|
+
...readingMatchingKanjiFormExamples,
|
|
1751
|
+
...includeKanjiFormExamples ? kanjiFormExamples : [],
|
|
1752
|
+
...includeReadingExamples ? readingExamples : []
|
|
1753
|
+
];
|
|
1756
1754
|
if (word.translations) {
|
|
1757
1755
|
const glossSpecificExamples = [];
|
|
1756
|
+
const seenPhrases = /* @__PURE__ */ new Set();
|
|
1758
1757
|
for (let i = 0; i < word.translations.length; i++) {
|
|
1759
|
-
outer: for (const example of wordExamples)
|
|
1758
|
+
outer: for (const example of wordExamples) {
|
|
1759
|
+
if (seenPhrases.has(example.phrase)) continue;
|
|
1760
1760
|
for (const part of example.parts)
|
|
1761
|
-
if (part.glossNumber === i + 1) {
|
|
1761
|
+
if (part.glossNumber === i + 1 && (partParts.has(part.baseForm) || part.reading && partParts.has(part.reading) || part.referenceID && partParts.has(part.referenceID))) {
|
|
1762
1762
|
glossSpecificExamples.push(example);
|
|
1763
|
+
seenPhrases.add(example.phrase);
|
|
1763
1764
|
break outer;
|
|
1764
1765
|
}
|
|
1766
|
+
}
|
|
1765
1767
|
if (glossSpecificExamples.length === 5) break;
|
|
1766
1768
|
}
|
|
1767
1769
|
if (glossSpecificExamples.length === 5)
|
|
1768
|
-
wordExamples = glossSpecificExamples;
|
|
1770
|
+
wordExamples = [...glossSpecificExamples];
|
|
1769
1771
|
else if (glossSpecificExamples.length > 0) {
|
|
1770
1772
|
const seenPhrases2 = new Set(
|
|
1771
1773
|
glossSpecificExamples.map((ex) => ex.phrase)
|