henkan 2.3.0 → 2.4.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.
- package/LICENSE.md +1 -1
- package/dist/index.cjs.js +145 -147
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +128 -119
- package/dist/index.mjs.map +2 -2
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/types.d.ts +5 -5
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +7 -0
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/README.md +1 -0
- package/docs/api/functions/convertJMdict.md +1 -1
- package/docs/api/functions/convertJawiktionaryAsync.md +1 -1
- package/docs/api/functions/convertJawiktionarySync.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/convertTanakaCorpusWithFurigana.md +1 -1
- package/docs/api/functions/createEntryMaps.md +1 -1
- package/docs/api/functions/generateAnkiNote.md +1 -1
- package/docs/api/functions/generateAnkiNotesFile.md +1 -1
- package/docs/api/functions/generateFurigana.md +33 -0
- package/docs/api/functions/getKanji.md +1 -1
- package/docs/api/functions/getKanjiExtended.md +1 -1
- package/docs/api/functions/getValidForms.md +1 -1
- package/docs/api/functions/getWord.md +1 -1
- package/docs/api/functions/getWordDefinitions.md +1 -1
- package/docs/api/functions/getWordDefinitionsWithFurigana.md +1 -1
- package/docs/api/interfaces/DefaultNoteInfo.md +4 -4
- package/docs/api/interfaces/Definition.md +4 -4
- package/docs/api/interfaces/DictKanji.md +5 -5
- 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/DictWord.md +8 -8
- package/docs/api/interfaces/EntryMaps.md +7 -7
- package/docs/api/interfaces/ExamplePart.md +7 -7
- package/docs/api/interfaces/GlossSpecificNumber.md +3 -3
- package/docs/api/interfaces/Grammar.md +15 -15
- package/docs/api/interfaces/GrammarMeaning.md +3 -3
- package/docs/api/interfaces/JaWiktionaryEntry.md +9 -9
- package/docs/api/interfaces/Kana.md +11 -11
- package/docs/api/interfaces/Kanji.md +23 -23
- 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/NoteHeaderKeys.md +7 -7
- package/docs/api/interfaces/Phrase.md +5 -5
- 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 +7 -7
- package/docs/api/interfaces/Translation.md +3 -3
- package/docs/api/interfaces/UsefulRegExps.md +8 -8
- package/docs/api/interfaces/Word.md +15 -15
- package/docs/api/interfaces/WordDefinitionPair.md +4 -4
- package/docs/api/type-aliases/Dict.md +1 -1
- package/docs/api/type-aliases/DictTranslation.md +1 -1
- package/docs/api/type-aliases/EntryType.md +1 -1
- package/docs/api/type-aliases/KanjiEntryMap.md +1 -1
- package/docs/api/type-aliases/KanjiSVGMap.md +1 -1
- package/docs/api/type-aliases/KanjiWordsMap.md +1 -1
- package/docs/api/type-aliases/Result.md +1 -1
- package/docs/api/type-aliases/WordDefinitionsMap.md +1 -1
- package/docs/api/type-aliases/WordExamplesMap.md +1 -1
- package/docs/api/type-aliases/WordIDEntryMap.md +1 -1
- package/package.json +5 -3
- package/src/constants.ts +2 -1
- package/src/types.ts +5 -7
- package/src/utils.ts +127 -100
- package/tsconfig.json +60 -0
- package/tsconfig.types.json +9 -0
package/dist/index.mjs
CHANGED
|
@@ -92,8 +92,9 @@ var noteMap = /* @__PURE__ */ new Map([
|
|
|
92
92
|
["tsugaru-ben", ["dialect::tsugaru-ben", "Dialect: Tsugaru-ben"]],
|
|
93
93
|
["aichi dialect", ["dialect::aichi", "Dialect: Aichi"]],
|
|
94
94
|
["tochigi dialect", ["dialect::tochigi", "Dialect: Tochigi"]],
|
|
95
|
-
["lit", ["literal_meaning", "Literal meaning"]],
|
|
96
95
|
["expl", ["explanation", "Explanation"]],
|
|
96
|
+
["fig", ["figurative", "Figurative"]],
|
|
97
|
+
["lit", ["literal_meaning", "Literal meaning"]],
|
|
97
98
|
["tm", ["trademark", "Trademark"]],
|
|
98
99
|
["adjective (keiyoushi)", ["adjective::i", "\u3044-adjective", "\u5F62\u5BB9\u8A5E"]],
|
|
99
100
|
["'taru' adjective", ["adjective::taru", "\u305F\u308B-adjective", "\u5F62\u5BB9\u52D5\u8A5E"]],
|
|
@@ -1278,6 +1279,22 @@ function katakanaToHiragana(input) {
|
|
|
1278
1279
|
}
|
|
1279
1280
|
return output.join("").normalize("NFC");
|
|
1280
1281
|
}
|
|
1282
|
+
async function generateFurigana(text, bindedFunction) {
|
|
1283
|
+
if (!text.includes("\u30FB"))
|
|
1284
|
+
return String(
|
|
1285
|
+
await bindedFunction(text, {
|
|
1286
|
+
to: "hiragana",
|
|
1287
|
+
mode: "furigana"
|
|
1288
|
+
})
|
|
1289
|
+
);
|
|
1290
|
+
else
|
|
1291
|
+
return (await Promise.all(
|
|
1292
|
+
text.split("\u30FB").map(async (t) => {
|
|
1293
|
+
const tFurigana = await generateFurigana(t, bindedFunction);
|
|
1294
|
+
return tFurigana;
|
|
1295
|
+
})
|
|
1296
|
+
)).join("");
|
|
1297
|
+
}
|
|
1281
1298
|
function getValidForms(readings, kanjiForms, wordIsCommon) {
|
|
1282
1299
|
const kanjiFormRestrictions = /* @__PURE__ */ new Set();
|
|
1283
1300
|
const validReadings = readings.filter(
|
|
@@ -1295,10 +1312,10 @@ function getValidForms(readings, kanjiForms, wordIsCommon) {
|
|
|
1295
1312
|
return false;
|
|
1296
1313
|
}
|
|
1297
1314
|
);
|
|
1298
|
-
const existValidKf = kanjiForms
|
|
1315
|
+
const existValidKf = kanjiForms?.some(
|
|
1299
1316
|
(kf, index) => index !== 0 && (kf.notes === void 0 || !kf.notes.some((note) => notSearchedForms.has(note)) && (wordIsCommon === void 0 || kf.commonness !== void 0) || kanjiFormRestrictions.has(kf.form))
|
|
1300
1317
|
);
|
|
1301
|
-
const validKanjiForms = kanjiForms
|
|
1318
|
+
const validKanjiForms = kanjiForms?.filter(
|
|
1302
1319
|
(kanjiForm, index) => {
|
|
1303
1320
|
if (index === 0) return true;
|
|
1304
1321
|
if (existValidKf === true)
|
|
@@ -1373,13 +1390,16 @@ function convertJMdict(xmlString, examples) {
|
|
|
1373
1390
|
const meaningObj = { partOfSpeech: [], translations: [] };
|
|
1374
1391
|
meaningObj.partOfSpeech = meaning.pos;
|
|
1375
1392
|
meaningObj.translations = [];
|
|
1376
|
-
for (const gloss of meaning.gloss)
|
|
1377
|
-
|
|
1378
|
-
|
|
1393
|
+
for (const gloss of meaning.gloss) {
|
|
1394
|
+
const translation = String(gloss._ ?? gloss).trim();
|
|
1395
|
+
const type = typeof gloss.$ === "object" && typeof gloss.$.g_type === "string" ? gloss.$.g_type : void 0;
|
|
1396
|
+
if (translation.length > 0 && type !== void 0 && type.length > 0)
|
|
1379
1397
|
meaningObj.translations.push({
|
|
1380
|
-
translation
|
|
1381
|
-
type
|
|
1398
|
+
translation,
|
|
1399
|
+
type
|
|
1382
1400
|
});
|
|
1401
|
+
else meaningObj.translations.push(translation);
|
|
1402
|
+
}
|
|
1383
1403
|
if (isStringArray(meaning.xref)) meaningObj.references = meaning.xref;
|
|
1384
1404
|
if (isStringArray(meaning.stagk))
|
|
1385
1405
|
meaningObj.kanjiFormRestrictions = meaning.stagk;
|
|
@@ -1501,7 +1521,6 @@ function convertKanjiDic(xmlString) {
|
|
|
1501
1521
|
return dict;
|
|
1502
1522
|
}
|
|
1503
1523
|
function convertTanakaCorpus(tanakaString) {
|
|
1504
|
-
var _a, _b;
|
|
1505
1524
|
const tanakaArray = [];
|
|
1506
1525
|
const tanakaParsed = tanakaString.split("\n");
|
|
1507
1526
|
for (let i = 0; i <= tanakaParsed.length; i += 2) {
|
|
@@ -1510,7 +1529,7 @@ function convertTanakaCorpus(tanakaString) {
|
|
|
1510
1529
|
if (a !== void 0 && b !== void 0 && a.startsWith("A: ") && b.startsWith("B: ")) {
|
|
1511
1530
|
a = a.replace("A: ", "");
|
|
1512
1531
|
b = b.replace("B: ", "");
|
|
1513
|
-
const idMatch =
|
|
1532
|
+
const idMatch = regexps.tanakaID.exec(a)?.groups.id?.trim();
|
|
1514
1533
|
const idParts = String(idMatch).split("_");
|
|
1515
1534
|
const id = `${Number(idParts[0])}_${Number(idParts[1])}`;
|
|
1516
1535
|
const aParts = a.replace(regexps.tanakaID, "").split(" ");
|
|
@@ -1518,17 +1537,15 @@ function convertTanakaCorpus(tanakaString) {
|
|
|
1518
1537
|
const bParts = [];
|
|
1519
1538
|
for (const part of bRawParts) {
|
|
1520
1539
|
const partMatches = regexps.tanakaPart.exec(part);
|
|
1521
|
-
const baseForm = partMatches
|
|
1540
|
+
const baseForm = partMatches?.groups.base;
|
|
1522
1541
|
const examplePart = { baseForm };
|
|
1523
|
-
const reading = partMatches
|
|
1524
|
-
const glossNumber = partMatches
|
|
1525
|
-
const inflectedForm = partMatches
|
|
1542
|
+
const reading = partMatches?.groups.reading;
|
|
1543
|
+
const glossNumber = partMatches?.groups.glossnum;
|
|
1544
|
+
const inflectedForm = partMatches?.groups.inflection;
|
|
1526
1545
|
if (reading !== void 0)
|
|
1527
1546
|
if (regexps.tanakaReferenceID.test(reading)) {
|
|
1528
1547
|
const referenceID = regexps.tanakaReferenceID.exec(reading);
|
|
1529
|
-
examplePart.referenceID = `${Number(
|
|
1530
|
-
referenceID == null ? void 0 : referenceID.groups["entryid"]
|
|
1531
|
-
)}`;
|
|
1548
|
+
examplePart.referenceID = `${Number(referenceID?.groups.entryid)}`;
|
|
1532
1549
|
} else examplePart.reading = reading;
|
|
1533
1550
|
if (glossNumber !== void 0)
|
|
1534
1551
|
examplePart.glossNumber = glossNumber.startsWith("0") ? Number.parseInt(glossNumber.substring(1)) : Number.parseInt(glossNumber);
|
|
@@ -1558,13 +1575,10 @@ async function convertTanakaCorpusWithFurigana(tanakaString) {
|
|
|
1558
1575
|
await kuroshiro.init(new KuromojiAnalyzer());
|
|
1559
1576
|
const convert = kuroshiro.convert.bind(kuroshiro);
|
|
1560
1577
|
for (let i = 0; i < tanakaArray.length; i++)
|
|
1561
|
-
|
|
1562
|
-
tanakaArray[i].
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
mode: "furigana"
|
|
1566
|
-
})
|
|
1567
|
-
);
|
|
1578
|
+
tanakaArray[i].furigana = await generateFurigana(
|
|
1579
|
+
tanakaArray[i].phrase,
|
|
1580
|
+
convert
|
|
1581
|
+
);
|
|
1568
1582
|
return tanakaArray;
|
|
1569
1583
|
}
|
|
1570
1584
|
function convertRadkFile(radkBuffer, kanjiDic) {
|
|
@@ -1645,7 +1659,6 @@ function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
|
1645
1659
|
return kanjiWithRadicals;
|
|
1646
1660
|
}
|
|
1647
1661
|
function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs, svgList) {
|
|
1648
|
-
var _a;
|
|
1649
1662
|
const kanjiEntryMap = /* @__PURE__ */ new Map();
|
|
1650
1663
|
const wordIDEntryMap = /* @__PURE__ */ new Map();
|
|
1651
1664
|
const kanjiWordsMap = /* @__PURE__ */ new Map();
|
|
@@ -1746,7 +1759,7 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1746
1759
|
const seenEx = /* @__PURE__ */ new Set();
|
|
1747
1760
|
const validExamples = [];
|
|
1748
1761
|
for (const p of wordPartsMap.get(word.id)) {
|
|
1749
|
-
const examplesForPart =
|
|
1762
|
+
const examplesForPart = partExamplesMap.get(p)?.filter((ex) => !seenEx.has(ex.id));
|
|
1750
1763
|
if (examplesForPart === void 0) continue;
|
|
1751
1764
|
for (const ex of examplesForPart) {
|
|
1752
1765
|
seenEx.add(ex.id);
|
|
@@ -1768,26 +1781,30 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1768
1781
|
};
|
|
1769
1782
|
}
|
|
1770
1783
|
function mapEntry(entry) {
|
|
1784
|
+
const senses = Array.from(
|
|
1785
|
+
entry.senses.filter(
|
|
1786
|
+
(sense) => isObjectArray(sense.form_of) && sense.form_of.every((form) => typeof form.word === "string") === true || isStringArray(sense.glosses)
|
|
1787
|
+
)
|
|
1788
|
+
);
|
|
1771
1789
|
return {
|
|
1772
1790
|
word: entry.word,
|
|
1773
1791
|
pos_title: entry.pos_title,
|
|
1774
|
-
senses
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
}
|
|
1792
|
+
...senses.length > 0 ? {
|
|
1793
|
+
senses: entry.senses.map((sense) => ({
|
|
1794
|
+
...isObjectArray(sense.form_of) ? {
|
|
1795
|
+
form_of: sense.form_of.map((form) => String(form.word))
|
|
1796
|
+
} : {},
|
|
1797
|
+
glosses: sense.glosses
|
|
1798
|
+
}))
|
|
1799
|
+
} : {},
|
|
1782
1800
|
...isObjectArray(entry.forms) && entry.forms.every((form) => typeof form.form === "string") === true ? { forms: entry.forms.map((form) => String(form.form)) } : {}
|
|
1783
1801
|
};
|
|
1784
1802
|
}
|
|
1785
1803
|
function convertJawiktionarySync(buffer) {
|
|
1786
|
-
var _a;
|
|
1787
1804
|
const lines = buffer.toString("utf-8").split("\n");
|
|
1788
1805
|
const entries = [];
|
|
1789
1806
|
for (let i = 0; i < lines.length; i++) {
|
|
1790
|
-
const line =
|
|
1807
|
+
const line = lines[i]?.trim();
|
|
1791
1808
|
if (line === void 0 || line.length === 0) continue;
|
|
1792
1809
|
const obj = JSON.parse(line);
|
|
1793
1810
|
if (typeof obj === "object" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
@@ -1812,18 +1829,18 @@ async function convertJawiktionaryAsync(stream) {
|
|
|
1812
1829
|
return entries;
|
|
1813
1830
|
}
|
|
1814
1831
|
function parseEntry(entry, definitions, definitionMap) {
|
|
1815
|
-
|
|
1816
|
-
const
|
|
1817
|
-
|
|
1818
|
-
if (!
|
|
1819
|
-
definitionMap.
|
|
1820
|
-
|
|
1821
|
-
|
|
1832
|
+
if (entry.senses !== void 0)
|
|
1833
|
+
for (const sense of entry.senses) {
|
|
1834
|
+
const definition = sense.glosses.join("");
|
|
1835
|
+
if (!definitions.some((def) => def.definition === definition)) {
|
|
1836
|
+
if (!definitionMap.has(definition))
|
|
1837
|
+
definitionMap.set(definition, { count: 1 });
|
|
1838
|
+
else definitionMap.get(definition).count++;
|
|
1839
|
+
definitions.push({ definition });
|
|
1840
|
+
}
|
|
1822
1841
|
}
|
|
1823
|
-
}
|
|
1824
1842
|
}
|
|
1825
1843
|
function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
1826
|
-
var _a, _b, _c, _d, _e;
|
|
1827
1844
|
const entries = /* @__PURE__ */ new Map();
|
|
1828
1845
|
for (const entry of wiktionaryEntries) {
|
|
1829
1846
|
const ent = entries.get(entry.word);
|
|
@@ -1870,19 +1887,20 @@ function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
|
1870
1887
|
let valid = false;
|
|
1871
1888
|
if (validKanjiForms.has(entry.word)) {
|
|
1872
1889
|
valid = true;
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1890
|
+
if (entry.senses !== void 0)
|
|
1891
|
+
for (const sense of entry.senses) {
|
|
1892
|
+
if (sense.form_of !== void 0 && sense.form_of.some((form) => validForms.has(form)))
|
|
1893
|
+
validFormOfEntries.add(entry.word);
|
|
1894
|
+
for (const gloss of sense.glosses) {
|
|
1895
|
+
let hasForm = false;
|
|
1896
|
+
for (const r of validForms)
|
|
1897
|
+
if (gloss.includes(r)) {
|
|
1898
|
+
hasForm = true;
|
|
1899
|
+
break;
|
|
1900
|
+
}
|
|
1901
|
+
if (hasForm) validGlossesEntries.add(entry.word);
|
|
1902
|
+
}
|
|
1884
1903
|
}
|
|
1885
|
-
}
|
|
1886
1904
|
if (entry.forms !== void 0) {
|
|
1887
1905
|
for (const form of entry.forms)
|
|
1888
1906
|
if (validForms.has(form)) validFormsEntries.add(entry.word);
|
|
@@ -1961,7 +1979,7 @@ function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
|
1961
1979
|
for (const m of word.meanings)
|
|
1962
1980
|
for (const note of m.partOfSpeech) {
|
|
1963
1981
|
const noteEntry = noteMap.get(note);
|
|
1964
|
-
if (
|
|
1982
|
+
if (noteEntry?.length === 3) {
|
|
1965
1983
|
const notePos = noteEntry[2];
|
|
1966
1984
|
if (Array.isArray(notePos))
|
|
1967
1985
|
for (const pos of notePos) {
|
|
@@ -1980,8 +1998,8 @@ function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
|
1980
1998
|
const posEntries = posMap.get(pos);
|
|
1981
1999
|
if (rkf.kanjiForms !== void 0)
|
|
1982
2000
|
for (const kf of rkf.kanjiForms) {
|
|
1983
|
-
const te =
|
|
1984
|
-
const fe =
|
|
2001
|
+
const te = posEntries.title?.get(kf);
|
|
2002
|
+
const fe = posEntries.form?.get(kf);
|
|
1985
2003
|
if (te !== void 0)
|
|
1986
2004
|
entriesWithTitles.push(
|
|
1987
2005
|
...te.filter(
|
|
@@ -1998,9 +2016,9 @@ function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
|
1998
2016
|
);
|
|
1999
2017
|
}
|
|
2000
2018
|
for (const r of rkf.readings) {
|
|
2001
|
-
const te =
|
|
2002
|
-
const fe =
|
|
2003
|
-
const fte =
|
|
2019
|
+
const te = posEntries.title?.get(r);
|
|
2020
|
+
const fe = posEntries.form?.get(r);
|
|
2021
|
+
const fte = posEntries.formTitle?.get(r);
|
|
2004
2022
|
if (te !== void 0)
|
|
2005
2023
|
entriesWithTitles.push(
|
|
2006
2024
|
...te.filter(
|
|
@@ -2088,25 +2106,26 @@ function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
|
2088
2106
|
const hasForms = ent.forms !== void 0 && ent.forms.some((form) => pair.forms.has(form));
|
|
2089
2107
|
if (pair.kanjiForms !== void 0 && pair.kanjiForms.has(ent.word)) {
|
|
2090
2108
|
kanjiFormEntries.push(ent);
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2099
|
-
|
|
2109
|
+
if (ent.senses !== void 0)
|
|
2110
|
+
for (const sense of ent.senses) {
|
|
2111
|
+
if (hasValidFormOf && sense.form_of !== void 0) {
|
|
2112
|
+
for (const form of sense.form_of)
|
|
2113
|
+
if (pair.forms.has(form)) {
|
|
2114
|
+
const elem = titleFormMap.get(form);
|
|
2115
|
+
if (elem === void 0)
|
|
2116
|
+
titleFormMap.set(form, /* @__PURE__ */ new Set([ent.word]));
|
|
2117
|
+
else elem.add(ent.word);
|
|
2118
|
+
}
|
|
2119
|
+
}
|
|
2120
|
+
for (const gloss of sense.glosses)
|
|
2121
|
+
for (const f of pair.forms)
|
|
2122
|
+
if (gloss.includes(f)) {
|
|
2123
|
+
const elem = refsMap.get(f);
|
|
2124
|
+
if (elem === void 0)
|
|
2125
|
+
refsMap.set(f, /* @__PURE__ */ new Set([ent.word]));
|
|
2126
|
+
else elem.add(ent.word);
|
|
2127
|
+
}
|
|
2100
2128
|
}
|
|
2101
|
-
for (const gloss of sense.glosses)
|
|
2102
|
-
for (const f of pair.forms)
|
|
2103
|
-
if (gloss.includes(f)) {
|
|
2104
|
-
const elem = refsMap.get(f);
|
|
2105
|
-
if (elem === void 0)
|
|
2106
|
-
refsMap.set(f, /* @__PURE__ */ new Set([ent.word]));
|
|
2107
|
-
else elem.add(ent.word);
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
2129
|
if (hasValidForms && ent.forms !== void 0) {
|
|
2111
2130
|
for (const form of ent.forms)
|
|
2112
2131
|
if (pair.forms.has(form)) forms.add(form);
|
|
@@ -2187,13 +2206,10 @@ async function getWordDefinitionsWithFurigana(entryList, jmDict) {
|
|
|
2187
2206
|
for (let i = 0; i < japaneseDefinitions.length; i++) {
|
|
2188
2207
|
const pair = japaneseDefinitions[i];
|
|
2189
2208
|
for (let j = 0; j < pair.definitions.length; j++)
|
|
2190
|
-
|
|
2191
|
-
pair.definitions[j].
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
mode: "furigana"
|
|
2195
|
-
})
|
|
2196
|
-
);
|
|
2209
|
+
pair.definitions[j].furigana = await generateFurigana(
|
|
2210
|
+
pair.definitions[j].definition,
|
|
2211
|
+
convert
|
|
2212
|
+
);
|
|
2197
2213
|
japaneseDefinitions[i] = pair;
|
|
2198
2214
|
}
|
|
2199
2215
|
return japaneseDefinitions;
|
|
@@ -2214,7 +2230,6 @@ var wordAddNoteArray = (arr, cb) => {
|
|
|
2214
2230
|
for (const v of arr) cb(v);
|
|
2215
2231
|
};
|
|
2216
2232
|
function getKanji(searchedKanji, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
2217
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2218
2233
|
let dictKanji = void 0;
|
|
2219
2234
|
if (typeof searchedKanji === "string" && dict !== void 0)
|
|
2220
2235
|
dictKanji = dict instanceof Map ? dict.get(searchedKanji) : dict.find((entry) => entry.kanji === searchedKanji);
|
|
@@ -2223,9 +2238,9 @@ function getKanji(searchedKanji, dict, jmDict, svgList, noteTypeName, deckPath)
|
|
|
2223
2238
|
const kanji = {
|
|
2224
2239
|
kanji: dictKanji.kanji,
|
|
2225
2240
|
strokes: dictKanji.misc.strokeNumber,
|
|
2226
|
-
...
|
|
2227
|
-
...
|
|
2228
|
-
...
|
|
2241
|
+
...dictKanji.misc?.grade !== void 0 ? { grade: dictKanji.misc.grade } : {},
|
|
2242
|
+
...dictKanji.misc?.frequency !== void 0 ? { frequency: dictKanji.misc.frequency } : {},
|
|
2243
|
+
...dictKanji.misc?.jlpt !== void 0 ? { jlpt: dictKanji.misc.jlpt } : {},
|
|
2229
2244
|
noteID: `kanji_${dictKanji.kanji}`,
|
|
2230
2245
|
...noteTypeName !== void 0 ? { noteTypeName } : {},
|
|
2231
2246
|
...deckPath !== void 0 ? { deckPath } : {},
|
|
@@ -2261,7 +2276,7 @@ function getKanji(searchedKanji, dict, jmDict, svgList, noteTypeName, deckPath)
|
|
|
2261
2276
|
}
|
|
2262
2277
|
if (jmDict !== void 0) {
|
|
2263
2278
|
let kanjiWords = jmDict instanceof Map ? jmDict.get(kanji.kanji) : jmDict;
|
|
2264
|
-
const firstKfWords = kanjiWords
|
|
2279
|
+
const firstKfWords = kanjiWords?.filter(
|
|
2265
2280
|
(word) => word.kanjiForms !== void 0 && word.kanjiForms[0].form.includes(kanji.kanji)
|
|
2266
2281
|
);
|
|
2267
2282
|
if (firstKfWords !== void 0 && firstKfWords.length > 0)
|
|
@@ -2269,17 +2284,17 @@ function getKanji(searchedKanji, dict, jmDict, svgList, noteTypeName, deckPath)
|
|
|
2269
2284
|
if (kanjiWords !== void 0) {
|
|
2270
2285
|
const validWords = [];
|
|
2271
2286
|
for (const word of kanjiWords) {
|
|
2272
|
-
const kanjiForm = (
|
|
2287
|
+
const kanjiForm = (firstKfWords !== void 0 && firstKfWords.length > 0 ? word.kanjiForms[0] : word.kanjiForms.find(
|
|
2273
2288
|
(kf) => kf.form.includes(kanji.kanji)
|
|
2274
|
-
))
|
|
2289
|
+
))?.form;
|
|
2275
2290
|
if (kanjiForm !== void 0) {
|
|
2276
|
-
const reading = (
|
|
2291
|
+
const reading = (firstKfWords !== void 0 && firstKfWords.length > 0 ? word.readings[0] : word.readings.find(
|
|
2277
2292
|
(r) => r.kanjiFormRestrictions !== void 0 && r.kanjiFormRestrictions.includes(kanjiForm)
|
|
2278
|
-
))
|
|
2293
|
+
))?.reading;
|
|
2279
2294
|
if (reading === void 0) continue;
|
|
2280
|
-
const translation = (
|
|
2295
|
+
const translation = (firstKfWords !== void 0 && firstKfWords.length > 0 ? word.meanings[0] : word.meanings.find(
|
|
2281
2296
|
(m) => m.kanjiFormRestrictions !== void 0 && m.kanjiFormRestrictions.includes(kanjiForm)
|
|
2282
|
-
))
|
|
2297
|
+
))?.translations.map(
|
|
2283
2298
|
(t) => typeof t === "string" ? t : t.translation
|
|
2284
2299
|
)[0];
|
|
2285
2300
|
if (translation === void 0) continue;
|
|
@@ -2316,10 +2331,10 @@ function getKanji(searchedKanji, dict, jmDict, svgList, noteTypeName, deckPath)
|
|
|
2316
2331
|
...kanji.frequency !== void 0 ? [`kanji::frequency::${kanji.frequency}`] : [],
|
|
2317
2332
|
...kanji.grade !== void 0 ? [`kanji::grade::${kanji.grade}`] : [],
|
|
2318
2333
|
...kanji.jlpt !== void 0 ? [`kanji::pre-2010_jlpt::${kanji.jlpt.toLowerCase()}`] : [],
|
|
2319
|
-
`kanji::onyomi::${
|
|
2320
|
-
`kanji::kunyomi::${
|
|
2321
|
-
`kanji::nanori::${
|
|
2322
|
-
`kanji::words::${
|
|
2334
|
+
`kanji::onyomi::${kanji.onyomi?.length ?? 0}`,
|
|
2335
|
+
`kanji::kunyomi::${kanji.kunyomi?.length ?? 0}`,
|
|
2336
|
+
`kanji::nanori::${kanji.nanori?.length ?? 0}`,
|
|
2337
|
+
`kanji::words::${kanji.words?.length ?? 0}`,
|
|
2323
2338
|
...kanji.svg !== void 0 ? ["kanji::has_svg"] : []
|
|
2324
2339
|
);
|
|
2325
2340
|
return kanji;
|
|
@@ -2364,7 +2379,6 @@ function getKanjiExtended(info, kanji, dict, useWords, jmDict, svgList, noteType
|
|
|
2364
2379
|
} else return void 0;
|
|
2365
2380
|
}
|
|
2366
2381
|
function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeName, deckPath) {
|
|
2367
|
-
var _a;
|
|
2368
2382
|
let dictWord = void 0;
|
|
2369
2383
|
if (typeof searchedWord === "string" && dict !== void 0) {
|
|
2370
2384
|
if (Array.isArray(dict))
|
|
@@ -2607,9 +2621,9 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2607
2621
|
}
|
|
2608
2622
|
}
|
|
2609
2623
|
if (definitions !== void 0) {
|
|
2610
|
-
const defs = definitions instanceof Map ? definitions.get(word.id) :
|
|
2624
|
+
const defs = definitions instanceof Map ? definitions.get(word.id) : definitions.find(
|
|
2611
2625
|
(wdp) => wdp.wordID === word.id
|
|
2612
|
-
)
|
|
2626
|
+
)?.definitions;
|
|
2613
2627
|
if (defs !== void 0)
|
|
2614
2628
|
word.definitions = [
|
|
2615
2629
|
...defs.toSorted(
|
|
@@ -2621,29 +2635,23 @@ function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeNa
|
|
|
2621
2635
|
} else return void 0;
|
|
2622
2636
|
}
|
|
2623
2637
|
function isWord(entry) {
|
|
2624
|
-
|
|
2625
|
-
return isObjectArray((_a = Object.getOwnPropertyDescriptor(entry, "readings")) == null ? void 0 : _a.value) && isObjectArray((_b = Object.getOwnPropertyDescriptor(entry, "translations")) == null ? void 0 : _b.value);
|
|
2638
|
+
return isObjectArray(Object.getOwnPropertyDescriptor(entry, "readings")?.value) && isObjectArray(Object.getOwnPropertyDescriptor(entry, "translations")?.value);
|
|
2626
2639
|
}
|
|
2627
2640
|
function isRadical(entry) {
|
|
2628
|
-
|
|
2629
|
-
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "radical")) == null ? void 0 : _a.value) === "string";
|
|
2641
|
+
return typeof Object.getOwnPropertyDescriptor(entry, "radical")?.value === "string";
|
|
2630
2642
|
}
|
|
2631
2643
|
function isKanji(entry) {
|
|
2632
|
-
|
|
2633
|
-
return !Object.hasOwn(entry, "translations") && !Object.hasOwn(entry, "readings") && !Object.hasOwn(entry, "radical") && typeof ((_a = Object.getOwnPropertyDescriptor(entry, "kanji")) == null ? void 0 : _a.value) === "string";
|
|
2644
|
+
return !Object.hasOwn(entry, "translations") && !Object.hasOwn(entry, "readings") && !Object.hasOwn(entry, "radical") && typeof Object.getOwnPropertyDescriptor(entry, "kanji")?.value === "string";
|
|
2634
2645
|
}
|
|
2635
2646
|
function isKana(entry) {
|
|
2636
|
-
|
|
2637
|
-
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "kana")) == null ? void 0 : _a.value) === "string";
|
|
2647
|
+
return typeof Object.getOwnPropertyDescriptor(entry, "kana")?.value === "string";
|
|
2638
2648
|
}
|
|
2639
2649
|
function isGrammar(entry) {
|
|
2640
|
-
|
|
2641
|
-
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "point")) == null ? void 0 : _a.value) === "string";
|
|
2650
|
+
return typeof Object.getOwnPropertyDescriptor(entry, "point")?.value === "string";
|
|
2642
2651
|
}
|
|
2643
2652
|
var createNotes = (notes, phrase) => `${phrase === true ? "<details><summary>Show translation</summary>" : ""}<ul class="note-list">${notes.map((note) => `<li class="note">${note}</li>`).join("")}</ul>${phrase === true ? "</details>" : ""}`;
|
|
2644
2653
|
var createEntry = (entry, notes, phrase, glossSpecific) => `<div class="entry${glossSpecific === true ? " gloss-specific" : ""}">${entry}${notes !== void 0 && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
|
|
2645
2654
|
function generateAnkiNote(entry) {
|
|
2646
|
-
var _a, _b;
|
|
2647
2655
|
const fields = [];
|
|
2648
2656
|
if (isWord(entry)) {
|
|
2649
2657
|
const firstReading = createEntry(
|
|
@@ -2695,7 +2703,7 @@ function generateAnkiNote(entry) {
|
|
|
2695
2703
|
);
|
|
2696
2704
|
}).filter((translation) => translation !== "null").join("")}</details>` : "";
|
|
2697
2705
|
const translationsField = `${firstThreeTranslations}${otherTranslations}`;
|
|
2698
|
-
const firstFivePhrases =
|
|
2706
|
+
const firstFivePhrases = entry.phrases?.slice(0, 5).map(
|
|
2699
2707
|
(phraseEntry, index) => createEntry(
|
|
2700
2708
|
`<span class="word word-phrase"><span class="word word-phrase-original">${phraseEntry.originalPhrase}</span><span class="word word-phrase-furigana">${phraseEntry.phrase}</span></span>`,
|
|
2701
2709
|
[phraseEntry.translation],
|
|
@@ -2717,7 +2725,7 @@ function generateAnkiNote(entry) {
|
|
|
2717
2725
|
);
|
|
2718
2726
|
}).filter((phrase) => phrase !== "null").join("")}</details>` : "";
|
|
2719
2727
|
const phrasesField = firstFivePhrases !== void 0 ? `${firstFivePhrases}${otherPhrases}` : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>';
|
|
2720
|
-
const firstThreeDefinitions =
|
|
2728
|
+
const firstThreeDefinitions = entry.definitions?.slice(0, 3).map(
|
|
2721
2729
|
(definitionEntry) => createEntry(
|
|
2722
2730
|
`<span class="word word-definition${definitionEntry.mayNotBeAccurate === 2 ? " mnba2" : definitionEntry.mayNotBeAccurate === 1 ? " mnba1" : ""}"><span class="word word-definition-original">${definitionEntry.definition}</span><span class="word word-definition-furigana">${definitionEntry.furigana ?? definitionEntry.definition}</span></span>`
|
|
2723
2731
|
)
|
|
@@ -2945,6 +2953,7 @@ export {
|
|
|
2945
2953
|
createEntryMaps,
|
|
2946
2954
|
generateAnkiNote,
|
|
2947
2955
|
generateAnkiNotesFile,
|
|
2956
|
+
generateFurigana,
|
|
2948
2957
|
getKanji,
|
|
2949
2958
|
getKanjiExtended,
|
|
2950
2959
|
getValidForms,
|