henkan 2.2.4 → 2.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.
- package/dist/index.cjs.js +671 -592
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +659 -589
- package/dist/index.mjs.map +3 -3
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/constants.d.ts.map +1 -1
- package/dist/types/types.d.ts +22 -12
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +34 -22
- package/dist/types/utils.d.ts.map +1 -1
- package/docs/api/README.md +2 -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/getKanji.md +4 -4
- package/docs/api/functions/getKanjiExtended.md +1 -1
- package/docs/api/functions/getValidForms.md +1 -1
- package/docs/api/functions/getWord.md +4 -4
- package/docs/api/functions/getWordDefinitions.md +4 -4
- package/docs/api/functions/getWordDefinitionsWithFurigana.md +1 -1
- package/docs/api/functions/hiraganaToKatakana.md +27 -0
- package/docs/api/functions/katakanaToHiragana.md +27 -0
- package/docs/api/interfaces/DefaultNoteInfo.md +4 -4
- package/docs/api/interfaces/Definition.md +6 -2
- package/docs/api/interfaces/DictKanjiMisc.md +1 -1
- package/docs/api/interfaces/DictWord.md +3 -3
- package/docs/api/interfaces/Grammar.md +16 -16
- package/docs/api/interfaces/GrammarMeaning.md +3 -3
- package/docs/api/interfaces/JaWiktionaryEntry.md +2 -2
- package/docs/api/interfaces/Kana.md +11 -11
- package/docs/api/interfaces/Kanji.md +24 -24
- 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 +10 -10
- 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 +15 -3
- package/docs/api/type-aliases/Dict.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 +7 -4
- package/src/constants.ts +1225 -0
- package/src/index.ts +3 -0
- package/src/types.ts +1056 -0
- package/src/utils.ts +3018 -0
package/dist/index.mjs
CHANGED
|
@@ -40,6 +40,43 @@ var notSearchedForms = /* @__PURE__ */ new Set([
|
|
|
40
40
|
"word containing out-dated kanji or kanji usage",
|
|
41
41
|
"Out-dated kanji or kanji usage"
|
|
42
42
|
]);
|
|
43
|
+
var posList = [
|
|
44
|
+
"\u540D\u8A5E",
|
|
45
|
+
"\u52D5\u8A5E",
|
|
46
|
+
"\u6210\u53E5",
|
|
47
|
+
"\u526F\u8A5E",
|
|
48
|
+
"\u5F62\u5BB9\u52D5\u8A5E",
|
|
49
|
+
"\u52A9\u8A5E",
|
|
50
|
+
"\u611F\u52D5\u8A5E",
|
|
51
|
+
"\u4EE3\u540D\u8A5E",
|
|
52
|
+
"\u63A5\u5C3E\u8F9E",
|
|
53
|
+
"\u63A5\u982D\u8A9E",
|
|
54
|
+
"\u9020\u8A9E\u6210\u5206",
|
|
55
|
+
"\u7565\u8A9E",
|
|
56
|
+
"\u56FA\u6709\u540D\u8A5E",
|
|
57
|
+
"\u4EBA\u79F0\u4EE3\u540D\u8A5E",
|
|
58
|
+
"\u63A5\u982D\u8F9E",
|
|
59
|
+
"\u63A5\u7D9A\u52A9\u8A5E",
|
|
60
|
+
"\u9593\u6295\u8A5E",
|
|
61
|
+
"\u52A9\u52D5\u8A5E",
|
|
62
|
+
"\u5F62\u5BB9\u8A5E",
|
|
63
|
+
"\u7E2E\u7D04\u5F62",
|
|
64
|
+
"\u63A5\u8F9E",
|
|
65
|
+
"\u63A5\u7D9A\u8A5E",
|
|
66
|
+
"\u9023\u4F53\u8A5E",
|
|
67
|
+
"\u4EBA\u540D",
|
|
68
|
+
"\u8A18\u53F7",
|
|
69
|
+
"\u6570\u8A5E",
|
|
70
|
+
"\u6163\u7528\u53E5",
|
|
71
|
+
"\u3053\u3068\u308F\u3056",
|
|
72
|
+
"\u52A9\u6570\u8A5E",
|
|
73
|
+
"\u82F1\u6570\u5B57\u6DF7\u5408\u8868\u8A18",
|
|
74
|
+
"\u52D5\u8A5E\u53E5",
|
|
75
|
+
"\u6210\u8A9E",
|
|
76
|
+
"\u610F\u7FA9",
|
|
77
|
+
"\u982D\u5B57\u8A9E",
|
|
78
|
+
"\u63A5\u5C3E\u8A9E"
|
|
79
|
+
];
|
|
43
80
|
var noteMap = /* @__PURE__ */ new Map([
|
|
44
81
|
["brazilian", ["dialect::brazilian", "Dialect: Brazilian"]],
|
|
45
82
|
["hokkaido-ben", ["dialect::hokkaido-ben", "Dialect: Hokkaid\u014D-ben"]],
|
|
@@ -1183,10 +1220,10 @@ var noteMap = /* @__PURE__ */ new Map([
|
|
|
1183
1220
|
]);
|
|
1184
1221
|
|
|
1185
1222
|
// src/utils.ts
|
|
1223
|
+
import { createInterface } from "readline";
|
|
1186
1224
|
import libxml from "libxmljs2";
|
|
1187
1225
|
import xml from "xml2js";
|
|
1188
1226
|
import iconv from "iconv-lite";
|
|
1189
|
-
import { createInterface } from "readline";
|
|
1190
1227
|
var Kuroshiro = __require("kuroshiro");
|
|
1191
1228
|
var KuromojiAnalyzer = __require("kuroshiro-analyzer-kuromoji");
|
|
1192
1229
|
function capitalizeString(value) {
|
|
@@ -1202,7 +1239,7 @@ function isObjectArray(arg) {
|
|
|
1202
1239
|
return isValidArrayWithFirstElement(arg) && arg.every((element) => typeof element === "object");
|
|
1203
1240
|
}
|
|
1204
1241
|
function shuffleArray(arr) {
|
|
1205
|
-
const a =
|
|
1242
|
+
const a = Array.from(arr);
|
|
1206
1243
|
for (let i = a.length - 1; i > 0; i--) {
|
|
1207
1244
|
const j = Math.floor(Math.random() * (i + 1));
|
|
1208
1245
|
const tmp = a[i];
|
|
@@ -1211,13 +1248,43 @@ function shuffleArray(arr) {
|
|
|
1211
1248
|
}
|
|
1212
1249
|
return a;
|
|
1213
1250
|
}
|
|
1251
|
+
function hiraganaToKatakana(input) {
|
|
1252
|
+
const decomposed = input.normalize("NFD");
|
|
1253
|
+
const output = [];
|
|
1254
|
+
for (const ch of decomposed.split("")) {
|
|
1255
|
+
const cp = ch.codePointAt(0);
|
|
1256
|
+
if (cp === 12441 || cp === 12442) {
|
|
1257
|
+
output.push(ch);
|
|
1258
|
+
continue;
|
|
1259
|
+
}
|
|
1260
|
+
if (cp >= 12352 && cp <= 12447)
|
|
1261
|
+
output.push(String.fromCodePoint(cp + 96));
|
|
1262
|
+
else output.push(ch);
|
|
1263
|
+
}
|
|
1264
|
+
return output.join("").normalize("NFC");
|
|
1265
|
+
}
|
|
1266
|
+
function katakanaToHiragana(input) {
|
|
1267
|
+
const decomposed = input.normalize("NFD");
|
|
1268
|
+
const output = [];
|
|
1269
|
+
for (const ch of decomposed.split("")) {
|
|
1270
|
+
const cp = ch.codePointAt(0);
|
|
1271
|
+
if (cp === 12441 || cp === 12442) {
|
|
1272
|
+
output.push(ch);
|
|
1273
|
+
continue;
|
|
1274
|
+
}
|
|
1275
|
+
if (cp >= 12448 && cp <= 12543)
|
|
1276
|
+
output.push(String.fromCodePoint(cp - 96));
|
|
1277
|
+
else output.push(ch);
|
|
1278
|
+
}
|
|
1279
|
+
return output.join("").normalize("NFC");
|
|
1280
|
+
}
|
|
1214
1281
|
function getValidForms(readings, kanjiForms, wordIsCommon) {
|
|
1215
1282
|
const kanjiFormRestrictions = /* @__PURE__ */ new Set();
|
|
1216
1283
|
const validReadings = readings.filter(
|
|
1217
1284
|
(reading, index) => {
|
|
1218
1285
|
if (index === 0) return true;
|
|
1219
1286
|
if (reading.notes === void 0 || !reading.notes.some((note) => notSearchedForms.has(note))) {
|
|
1220
|
-
if (reading.kanjiFormRestrictions) {
|
|
1287
|
+
if (reading.kanjiFormRestrictions !== void 0) {
|
|
1221
1288
|
for (const kfr of reading.kanjiFormRestrictions)
|
|
1222
1289
|
kanjiFormRestrictions.add(kfr);
|
|
1223
1290
|
return true;
|
|
@@ -1228,20 +1295,22 @@ function getValidForms(readings, kanjiForms, wordIsCommon) {
|
|
|
1228
1295
|
return false;
|
|
1229
1296
|
}
|
|
1230
1297
|
);
|
|
1231
|
-
const existValidKf = kanjiForms
|
|
1232
|
-
(kf, index) => index !== 0 && (
|
|
1233
|
-
)
|
|
1234
|
-
const validKanjiForms = kanjiForms
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1298
|
+
const existValidKf = kanjiForms == null ? void 0 : kanjiForms.some(
|
|
1299
|
+
(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
|
+
);
|
|
1301
|
+
const validKanjiForms = kanjiForms == null ? void 0 : kanjiForms.filter(
|
|
1302
|
+
(kanjiForm, index) => {
|
|
1303
|
+
if (index === 0) return true;
|
|
1304
|
+
if (existValidKf === true)
|
|
1305
|
+
return kanjiForm.notes === void 0 || !kanjiForm.notes.some(
|
|
1306
|
+
(note) => notSearchedForms.has(note)
|
|
1307
|
+
) && (wordIsCommon === void 0 || kanjiForm.commonness !== void 0) || kanjiFormRestrictions.has(kanjiForm.form);
|
|
1308
|
+
else return true;
|
|
1309
|
+
}
|
|
1310
|
+
);
|
|
1242
1311
|
return {
|
|
1243
1312
|
readings: validReadings,
|
|
1244
|
-
...validKanjiForms ? { kanjiForms: validKanjiForms } : {}
|
|
1313
|
+
...validKanjiForms !== void 0 ? { kanjiForms: validKanjiForms } : {}
|
|
1245
1314
|
};
|
|
1246
1315
|
}
|
|
1247
1316
|
function convertJMdict(xmlString, examples) {
|
|
@@ -1253,13 +1322,13 @@ function convertJMdict(xmlString, examples) {
|
|
|
1253
1322
|
});
|
|
1254
1323
|
const dict = [];
|
|
1255
1324
|
xml.parseString(dictParsed, (_err, result) => {
|
|
1256
|
-
const tanakaParts = examples && examples.length > 0 ? new Set(
|
|
1325
|
+
const tanakaParts = examples !== void 0 && examples.length > 0 ? new Set(
|
|
1257
1326
|
examples.flatMap(
|
|
1258
1327
|
(example) => example.parts.flatMap((part) => [
|
|
1259
1328
|
part.baseForm,
|
|
1260
|
-
...part.reading ? [part.reading] : [],
|
|
1261
|
-
...part.inflectedForm ? [part.inflectedForm] : [],
|
|
1262
|
-
...part.referenceID ? [part.referenceID] : []
|
|
1329
|
+
...part.reading !== void 0 ? [part.reading] : [],
|
|
1330
|
+
...part.inflectedForm !== void 0 ? [part.inflectedForm] : [],
|
|
1331
|
+
...part.referenceID !== void 0 ? [part.referenceID] : []
|
|
1263
1332
|
])
|
|
1264
1333
|
)
|
|
1265
1334
|
) : void 0;
|
|
@@ -1306,7 +1375,7 @@ function convertJMdict(xmlString, examples) {
|
|
|
1306
1375
|
meaningObj.translations = [];
|
|
1307
1376
|
for (const gloss of meaning.gloss)
|
|
1308
1377
|
if (typeof gloss === "string") meaningObj.translations.push(gloss);
|
|
1309
|
-
else if (typeof gloss === "object" &&
|
|
1378
|
+
else if (typeof gloss === "object" && typeof gloss._ === "string" && typeof gloss.$ === "object" && (gloss.$.g_type === "lit" || gloss.$.g_type === "expl" || gloss.$.g_type === "tm"))
|
|
1310
1379
|
meaningObj.translations.push({
|
|
1311
1380
|
translation: gloss._,
|
|
1312
1381
|
type: gloss.$.g_type
|
|
@@ -1321,7 +1390,7 @@ function convertJMdict(xmlString, examples) {
|
|
|
1321
1390
|
if (isStringArray(meaning.s_inf)) meaningObj.info = meaning.s_inf;
|
|
1322
1391
|
if (isStringArray(meaning.misc)) {
|
|
1323
1392
|
meaningObj.misc = meaning.misc;
|
|
1324
|
-
if (meaningObj.misc && meaningObj.misc.includes("word usually written using kana alone"))
|
|
1393
|
+
if (meaningObj.misc !== void 0 && meaningObj.misc.includes("word usually written using kana alone"))
|
|
1325
1394
|
usuallyInKanaMeanings++;
|
|
1326
1395
|
}
|
|
1327
1396
|
if (isStringArray(meaning.dial)) meaningObj.dialects = meaning.dial;
|
|
@@ -1329,30 +1398,31 @@ function convertJMdict(xmlString, examples) {
|
|
|
1329
1398
|
}
|
|
1330
1399
|
if (entryObj.meanings.length === usuallyInKanaMeanings)
|
|
1331
1400
|
entryObj.usuallyInKana = true;
|
|
1332
|
-
if (examples) {
|
|
1401
|
+
if (examples !== void 0) {
|
|
1333
1402
|
let existsExample = false;
|
|
1334
|
-
if (tanakaParts && tanakaParts.has(entryObj.id))
|
|
1403
|
+
if (tanakaParts !== void 0 && tanakaParts.has(entryObj.id))
|
|
1404
|
+
existsExample = true;
|
|
1335
1405
|
if (!existsExample) {
|
|
1336
1406
|
const rkf = getValidForms(
|
|
1337
1407
|
entryObj.readings,
|
|
1338
1408
|
entryObj.kanjiForms,
|
|
1339
1409
|
entryObj.isCommon
|
|
1340
1410
|
);
|
|
1341
|
-
const
|
|
1411
|
+
const validReadings = new Set(
|
|
1342
1412
|
rkf.readings.map((r) => r.reading)
|
|
1343
1413
|
);
|
|
1344
|
-
const
|
|
1414
|
+
const validKanjiForms = rkf.kanjiForms !== void 0 ? new Set(
|
|
1345
1415
|
rkf.kanjiForms.map((kf) => kf.form)
|
|
1346
1416
|
) : void 0;
|
|
1347
|
-
if (
|
|
1348
|
-
for (const kf of
|
|
1417
|
+
if (validKanjiForms !== void 0 && validKanjiForms.size > 0 && tanakaParts !== void 0) {
|
|
1418
|
+
for (const kf of validKanjiForms)
|
|
1349
1419
|
if (tanakaParts.has(kf)) {
|
|
1350
1420
|
existsExample = true;
|
|
1351
1421
|
break;
|
|
1352
1422
|
}
|
|
1353
1423
|
}
|
|
1354
|
-
if (entryObj.kanjiForms === void 0 &&
|
|
1355
|
-
for (const r of
|
|
1424
|
+
if (entryObj.kanjiForms === void 0 && validReadings.size > 0 && tanakaParts !== void 0) {
|
|
1425
|
+
for (const r of validReadings)
|
|
1356
1426
|
if (tanakaParts.has(r)) {
|
|
1357
1427
|
existsExample = true;
|
|
1358
1428
|
break;
|
|
@@ -1386,7 +1456,7 @@ function convertKanjiDic(xmlString) {
|
|
|
1386
1456
|
if (isStringArray(misc.grade)) kanjiObj.misc.grade = misc.grade[0];
|
|
1387
1457
|
if (isStringArray(misc.freq)) kanjiObj.misc.frequency = misc.freq[0];
|
|
1388
1458
|
if (isStringArray(misc.jlpt) && ["5", "4", "3", "2", "1"].includes(misc.jlpt[0]))
|
|
1389
|
-
kanjiObj.misc.jlpt = `N${misc.jlpt[0]}`;
|
|
1459
|
+
kanjiObj.misc.jlpt = `N${Number(String(misc.jlpt[0]))}`;
|
|
1390
1460
|
if (isObjectArray(entry.reading_meaning))
|
|
1391
1461
|
for (const rm of entry.reading_meaning) {
|
|
1392
1462
|
const rmObj = { groups: [] };
|
|
@@ -1397,7 +1467,7 @@ function convertKanjiDic(xmlString) {
|
|
|
1397
1467
|
};
|
|
1398
1468
|
if (isObjectArray(group.reading)) {
|
|
1399
1469
|
for (const reading of group.reading)
|
|
1400
|
-
if (
|
|
1470
|
+
if (typeof reading._ === "string" && typeof reading.$ === "object" && (reading.$.r_type === "ja_on" || reading.$.r_type === "ja_kun"))
|
|
1401
1471
|
groupObj.readings.push({
|
|
1402
1472
|
reading: reading._,
|
|
1403
1473
|
type: reading.$.r_type
|
|
@@ -1421,7 +1491,7 @@ function convertKanjiDic(xmlString) {
|
|
|
1421
1491
|
}
|
|
1422
1492
|
if (isStringArray(rm.nanori) && rm.nanori.length > 0)
|
|
1423
1493
|
rmObj.nanori = rm.nanori;
|
|
1424
|
-
if (rmObj.groups.length > 0 || rmObj.nanori)
|
|
1494
|
+
if (rmObj.groups.length > 0 || rmObj.nanori !== void 0)
|
|
1425
1495
|
kanjiObj.readingMeaning.push(rmObj);
|
|
1426
1496
|
}
|
|
1427
1497
|
dict.push(kanjiObj);
|
|
@@ -1431,16 +1501,18 @@ function convertKanjiDic(xmlString) {
|
|
|
1431
1501
|
return dict;
|
|
1432
1502
|
}
|
|
1433
1503
|
function convertTanakaCorpus(tanakaString) {
|
|
1434
|
-
var _a;
|
|
1504
|
+
var _a, _b;
|
|
1435
1505
|
const tanakaArray = [];
|
|
1436
1506
|
const tanakaParsed = tanakaString.split("\n");
|
|
1437
1507
|
for (let i = 0; i <= tanakaParsed.length; i += 2) {
|
|
1438
1508
|
let a = tanakaParsed[i];
|
|
1439
1509
|
let b = tanakaParsed[i + 1];
|
|
1440
|
-
if (a && b && a.startsWith("A: ") && b.startsWith("B: ")) {
|
|
1510
|
+
if (a !== void 0 && b !== void 0 && a.startsWith("A: ") && b.startsWith("B: ")) {
|
|
1441
1511
|
a = a.replace("A: ", "");
|
|
1442
1512
|
b = b.replace("B: ", "");
|
|
1443
|
-
const idMatch = regexps.tanakaID.exec(a);
|
|
1513
|
+
const idMatch = (_b = (_a = regexps.tanakaID.exec(a)) == null ? void 0 : _a.groups["id"]) == null ? void 0 : _b.trim();
|
|
1514
|
+
const idParts = String(idMatch).split("_");
|
|
1515
|
+
const id = `${Number(idParts[0])}_${Number(idParts[1])}`;
|
|
1444
1516
|
const aParts = a.replace(regexps.tanakaID, "").split(" ");
|
|
1445
1517
|
const bRawParts = b.split(" ").filter((part) => part.trim().length !== 0);
|
|
1446
1518
|
const bParts = [];
|
|
@@ -1451,14 +1523,17 @@ function convertTanakaCorpus(tanakaString) {
|
|
|
1451
1523
|
const reading = partMatches == null ? void 0 : partMatches.groups["reading"];
|
|
1452
1524
|
const glossNumber = partMatches == null ? void 0 : partMatches.groups["glossnum"];
|
|
1453
1525
|
const inflectedForm = partMatches == null ? void 0 : partMatches.groups["inflection"];
|
|
1454
|
-
if (reading)
|
|
1526
|
+
if (reading !== void 0)
|
|
1455
1527
|
if (regexps.tanakaReferenceID.test(reading)) {
|
|
1456
1528
|
const referenceID = regexps.tanakaReferenceID.exec(reading);
|
|
1457
|
-
examplePart.referenceID =
|
|
1529
|
+
examplePart.referenceID = `${Number(
|
|
1530
|
+
referenceID == null ? void 0 : referenceID.groups["entryid"]
|
|
1531
|
+
)}`;
|
|
1458
1532
|
} else examplePart.reading = reading;
|
|
1459
|
-
if (glossNumber)
|
|
1533
|
+
if (glossNumber !== void 0)
|
|
1460
1534
|
examplePart.glossNumber = glossNumber.startsWith("0") ? Number.parseInt(glossNumber.substring(1)) : Number.parseInt(glossNumber);
|
|
1461
|
-
if (inflectedForm
|
|
1535
|
+
if (inflectedForm !== void 0)
|
|
1536
|
+
examplePart.inflectedForm = inflectedForm;
|
|
1462
1537
|
if (baseForm.endsWith("~")) {
|
|
1463
1538
|
examplePart.edited = true;
|
|
1464
1539
|
examplePart.baseForm = examplePart.baseForm.replace("~", "");
|
|
@@ -1468,7 +1543,7 @@ function convertTanakaCorpus(tanakaString) {
|
|
|
1468
1543
|
const phrase = aParts[0];
|
|
1469
1544
|
const translation = aParts[1];
|
|
1470
1545
|
tanakaArray.push({
|
|
1471
|
-
id
|
|
1546
|
+
id,
|
|
1472
1547
|
phrase: phrase.trim(),
|
|
1473
1548
|
translation: translation.trim(),
|
|
1474
1549
|
parts: bParts
|
|
@@ -1478,34 +1553,26 @@ function convertTanakaCorpus(tanakaString) {
|
|
|
1478
1553
|
return tanakaArray;
|
|
1479
1554
|
}
|
|
1480
1555
|
async function convertTanakaCorpusWithFurigana(tanakaString) {
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
tanakaArray =
|
|
1488
|
-
tanakaArray.
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
furigana = await convert(ex.phrase, {
|
|
1492
|
-
to: "hiragana",
|
|
1493
|
-
mode: "furigana"
|
|
1494
|
-
});
|
|
1495
|
-
if (furigana) ex.furigana = furigana;
|
|
1496
|
-
return ex;
|
|
1556
|
+
const tanakaArray = convertTanakaCorpus(tanakaString);
|
|
1557
|
+
const kuroshiro = new Kuroshiro.default();
|
|
1558
|
+
await kuroshiro.init(new KuromojiAnalyzer());
|
|
1559
|
+
const convert = kuroshiro.convert.bind(kuroshiro);
|
|
1560
|
+
for (let i = 0; i < tanakaArray.length; i++)
|
|
1561
|
+
if (!tanakaArray[i].phrase.includes("\u30FB"))
|
|
1562
|
+
tanakaArray[i].furigana = String(
|
|
1563
|
+
await convert(tanakaArray[i].phrase, {
|
|
1564
|
+
to: "hiragana",
|
|
1565
|
+
mode: "furigana"
|
|
1497
1566
|
})
|
|
1498
1567
|
);
|
|
1499
|
-
|
|
1500
|
-
}
|
|
1501
|
-
);
|
|
1568
|
+
return tanakaArray;
|
|
1502
1569
|
}
|
|
1503
1570
|
function convertRadkFile(radkBuffer, kanjiDic) {
|
|
1504
1571
|
const fileParsed = iconv.decode(radkBuffer, "euc-jp").split("\n").filter((line) => !line.startsWith("#"));
|
|
1505
1572
|
const radicals = [];
|
|
1506
1573
|
for (let i = 0; i < fileParsed.length; i++) {
|
|
1507
1574
|
const line = fileParsed[i];
|
|
1508
|
-
if (line && line.startsWith("$ ")) {
|
|
1575
|
+
if (line !== void 0 && line.startsWith("$ ")) {
|
|
1509
1576
|
const radical = {
|
|
1510
1577
|
radical: line.charAt(2).trim(),
|
|
1511
1578
|
strokes: line.substring(4).trim()
|
|
@@ -1513,7 +1580,7 @@ function convertRadkFile(radkBuffer, kanjiDic) {
|
|
|
1513
1580
|
let j = i + 1;
|
|
1514
1581
|
let kanjiLine = fileParsed[j];
|
|
1515
1582
|
const kanjiList = [];
|
|
1516
|
-
while (kanjiLine && !kanjiLine.startsWith("$ ")) {
|
|
1583
|
+
while (kanjiLine !== void 0 && !kanjiLine.startsWith("$ ")) {
|
|
1517
1584
|
const kanjis = kanjiLine.split("");
|
|
1518
1585
|
for (const kanji of kanjis) {
|
|
1519
1586
|
const foundKanji = kanjiDic.find(
|
|
@@ -1524,7 +1591,7 @@ function convertRadkFile(radkBuffer, kanjiDic) {
|
|
|
1524
1591
|
kanjiList.push(kanjiObj);
|
|
1525
1592
|
}
|
|
1526
1593
|
kanjiLine = fileParsed[++j];
|
|
1527
|
-
if (
|
|
1594
|
+
if (kanjiLine === void 0) continue;
|
|
1528
1595
|
if (kanjiLine.startsWith("$ ")) i = j - 1;
|
|
1529
1596
|
}
|
|
1530
1597
|
if (kanjiList.length > 0) radical.kanji = kanjiList;
|
|
@@ -1536,7 +1603,7 @@ function convertRadkFile(radkBuffer, kanjiDic) {
|
|
|
1536
1603
|
function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
1537
1604
|
const fileParsed = iconv.decode(kradBuffer, "euc-jp").split("\n").filter((line) => !line.startsWith("#"));
|
|
1538
1605
|
const kanjiWithRadicals = [];
|
|
1539
|
-
for (const line of fileParsed)
|
|
1606
|
+
for (const line of fileParsed)
|
|
1540
1607
|
if (line.length > 0) {
|
|
1541
1608
|
const split = line.split(" : ");
|
|
1542
1609
|
const kanjiChar = split[0];
|
|
@@ -1551,11 +1618,11 @@ function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
|
1551
1618
|
(dictKanji) => dictKanji.kanji === radical
|
|
1552
1619
|
);
|
|
1553
1620
|
let radicalObj = foundRadical ?? { kanji: radical };
|
|
1554
|
-
if (
|
|
1621
|
+
if (foundRadical === void 0) {
|
|
1555
1622
|
const katakanaChar = katakanaList.find(
|
|
1556
1623
|
(kana) => kana.kana === radical
|
|
1557
1624
|
);
|
|
1558
|
-
if (
|
|
1625
|
+
if (katakanaChar === void 0) continue;
|
|
1559
1626
|
radicalObj = {
|
|
1560
1627
|
kanji: katakanaChar.kana,
|
|
1561
1628
|
readingMeaning: [
|
|
@@ -1575,7 +1642,6 @@ function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
|
1575
1642
|
if (kanji.kanji.length === 1 && kanji.radicals.length > 0)
|
|
1576
1643
|
kanjiWithRadicals.push(kanji);
|
|
1577
1644
|
}
|
|
1578
|
-
}
|
|
1579
1645
|
return kanjiWithRadicals;
|
|
1580
1646
|
}
|
|
1581
1647
|
function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs, svgList) {
|
|
@@ -1589,42 +1655,40 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1589
1655
|
const wordPartsMap = /* @__PURE__ */ new Map();
|
|
1590
1656
|
const partExamplesMap = /* @__PURE__ */ new Map();
|
|
1591
1657
|
const entryParts = /* @__PURE__ */ new Set();
|
|
1592
|
-
if (kanjiDic)
|
|
1658
|
+
if (kanjiDic !== void 0)
|
|
1593
1659
|
for (const kanji of kanjiDic) kanjiEntryMap.set(kanji.kanji, kanji);
|
|
1594
|
-
if (wordDefinitionPairs)
|
|
1660
|
+
if (wordDefinitionPairs !== void 0)
|
|
1595
1661
|
for (const pair of wordDefinitionPairs)
|
|
1596
1662
|
wordDefinitionsMap.set(pair.wordID, pair.definitions);
|
|
1597
|
-
if (kanjiDic && svgList)
|
|
1663
|
+
if (kanjiDic !== void 0 && svgList !== void 0)
|
|
1598
1664
|
for (const kanji of kanjiDic) {
|
|
1599
1665
|
const codePoint = kanji.kanji.codePointAt(0).toString(16).toLowerCase();
|
|
1600
1666
|
const svg = svgList.find((file) => {
|
|
1601
1667
|
const baseName = file.split(".")[0].toLowerCase();
|
|
1602
1668
|
return baseName === codePoint || baseName === `0${codePoint}`;
|
|
1603
1669
|
});
|
|
1604
|
-
if (svg) kanjiSVGMap.set(kanji.kanji, svg);
|
|
1670
|
+
if (svg !== void 0) kanjiSVGMap.set(kanji.kanji, svg);
|
|
1605
1671
|
}
|
|
1606
|
-
if (jmDict) {
|
|
1672
|
+
if (jmDict !== void 0) {
|
|
1607
1673
|
for (const word of jmDict) {
|
|
1608
1674
|
wordIDEntryMap.set(word.id, word);
|
|
1609
|
-
if (word.kanjiForms)
|
|
1675
|
+
if (word.kanjiForms !== void 0)
|
|
1610
1676
|
for (const kf of word.kanjiForms)
|
|
1611
|
-
for (const char of kf.form.split("").filter((c) => regexps.kanji.test(c)))
|
|
1677
|
+
for (const char of kf.form.split("").filter((c) => regexps.kanji.test(c)))
|
|
1612
1678
|
if (!kanjiWordsMap.has(char)) kanjiWordsMap.set(char, [word]);
|
|
1613
1679
|
else kanjiWordsMap.get(char).push(word);
|
|
1614
|
-
|
|
1615
|
-
if (tanakaExamples) {
|
|
1680
|
+
if (tanakaExamples !== void 0) {
|
|
1616
1681
|
const rkf = getValidForms(
|
|
1617
1682
|
word.readings,
|
|
1618
1683
|
word.kanjiForms,
|
|
1619
1684
|
word.isCommon
|
|
1620
1685
|
);
|
|
1621
1686
|
const localPartParts = /* @__PURE__ */ new Set();
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1687
|
+
for (const reading of rkf.readings) {
|
|
1688
|
+
entryParts.add(reading.reading);
|
|
1689
|
+
localPartParts.add(reading.reading);
|
|
1690
|
+
}
|
|
1691
|
+
if (rkf.kanjiForms !== void 0 && rkf.kanjiForms.length > 0)
|
|
1628
1692
|
for (const kanjiForm of rkf.kanjiForms) {
|
|
1629
1693
|
entryParts.add(kanjiForm.form);
|
|
1630
1694
|
localPartParts.add(kanjiForm.form);
|
|
@@ -1634,58 +1698,56 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1634
1698
|
wordPartsMap.set(word.id, localPartParts);
|
|
1635
1699
|
}
|
|
1636
1700
|
}
|
|
1637
|
-
if (tanakaExamples) {
|
|
1638
|
-
for (const ex of tanakaExamples)
|
|
1701
|
+
if (tanakaExamples !== void 0) {
|
|
1702
|
+
for (const ex of tanakaExamples)
|
|
1639
1703
|
for (const part of ex.parts) {
|
|
1640
1704
|
if (entryParts.has(part.baseForm)) {
|
|
1641
1705
|
let exList = partExamplesMap.get(
|
|
1642
1706
|
part.baseForm
|
|
1643
1707
|
);
|
|
1644
|
-
if (
|
|
1708
|
+
if (exList === void 0) {
|
|
1645
1709
|
exList = [];
|
|
1646
1710
|
partExamplesMap.set(part.baseForm, exList);
|
|
1647
1711
|
}
|
|
1648
1712
|
exList.push(ex);
|
|
1649
1713
|
}
|
|
1650
|
-
if (part.reading && entryParts.has(part.reading)) {
|
|
1714
|
+
if (part.reading !== void 0 && entryParts.has(part.reading)) {
|
|
1651
1715
|
let exList = partExamplesMap.get(
|
|
1652
1716
|
part.reading
|
|
1653
1717
|
);
|
|
1654
|
-
if (
|
|
1718
|
+
if (exList === void 0) {
|
|
1655
1719
|
exList = [];
|
|
1656
1720
|
partExamplesMap.set(part.reading, exList);
|
|
1657
1721
|
}
|
|
1658
1722
|
exList.push(ex);
|
|
1659
1723
|
}
|
|
1660
|
-
if (part.inflectedForm && entryParts.has(part.inflectedForm)) {
|
|
1724
|
+
if (part.inflectedForm !== void 0 && entryParts.has(part.inflectedForm)) {
|
|
1661
1725
|
let exList = partExamplesMap.get(
|
|
1662
1726
|
part.inflectedForm
|
|
1663
1727
|
);
|
|
1664
|
-
if (
|
|
1728
|
+
if (exList === void 0) {
|
|
1665
1729
|
exList = [];
|
|
1666
1730
|
partExamplesMap.set(part.inflectedForm, exList);
|
|
1667
1731
|
}
|
|
1668
1732
|
exList.push(ex);
|
|
1669
1733
|
}
|
|
1670
|
-
if (part.referenceID && entryParts.has(part.referenceID)) {
|
|
1734
|
+
if (part.referenceID !== void 0 && entryParts.has(part.referenceID)) {
|
|
1671
1735
|
let exList = partExamplesMap.get(
|
|
1672
1736
|
part.referenceID
|
|
1673
1737
|
);
|
|
1674
|
-
if (
|
|
1738
|
+
if (exList === void 0) {
|
|
1675
1739
|
exList = [];
|
|
1676
1740
|
partExamplesMap.set(part.referenceID, exList);
|
|
1677
1741
|
}
|
|
1678
1742
|
exList.push(ex);
|
|
1679
1743
|
}
|
|
1680
1744
|
}
|
|
1681
|
-
}
|
|
1682
1745
|
for (const word of jmDict) {
|
|
1683
|
-
const entryParts2 = wordPartsMap.get(word.id);
|
|
1684
1746
|
const seenEx = /* @__PURE__ */ new Set();
|
|
1685
1747
|
const validExamples = [];
|
|
1686
|
-
for (const p of
|
|
1748
|
+
for (const p of wordPartsMap.get(word.id)) {
|
|
1687
1749
|
const examplesForPart = (_a = partExamplesMap.get(p)) == null ? void 0 : _a.filter((ex) => !seenEx.has(ex.id));
|
|
1688
|
-
if (
|
|
1750
|
+
if (examplesForPart === void 0) continue;
|
|
1689
1751
|
for (const ex of examplesForPart) {
|
|
1690
1752
|
seenEx.add(ex.id);
|
|
1691
1753
|
validExamples.push(ex);
|
|
@@ -1710,49 +1772,44 @@ function mapEntry(entry) {
|
|
|
1710
1772
|
word: entry.word,
|
|
1711
1773
|
pos_title: entry.pos_title,
|
|
1712
1774
|
senses: entry.senses.filter(
|
|
1713
|
-
(sense) => isObjectArray(sense.form_of)
|
|
1714
|
-
(form) => form.word && typeof form.word === "string"
|
|
1715
|
-
) || isStringArray(sense.glosses)
|
|
1775
|
+
(sense) => (isObjectArray(sense.form_of) ? sense.form_of.every((form) => typeof form.word === "string") : isStringArray(sense.glosses)) === true || isStringArray(sense.glosses)
|
|
1716
1776
|
).map((sense) => ({
|
|
1717
|
-
...sense.form_of ? {
|
|
1718
|
-
form_of: sense.form_of.map((form) => form.word)
|
|
1777
|
+
...isObjectArray(sense.form_of) ? {
|
|
1778
|
+
form_of: sense.form_of.map((form) => String(form.word))
|
|
1719
1779
|
} : {},
|
|
1720
1780
|
glosses: sense.glosses
|
|
1721
1781
|
})),
|
|
1722
|
-
...isObjectArray(entry.forms) && entry.forms.every((form) => typeof form.form === "string") ? { forms: entry.forms.map((form) => form.form) } : {}
|
|
1782
|
+
...isObjectArray(entry.forms) && entry.forms.every((form) => typeof form.form === "string") === true ? { forms: entry.forms.map((form) => String(form.form)) } : {}
|
|
1723
1783
|
};
|
|
1724
1784
|
}
|
|
1725
1785
|
function convertJawiktionarySync(buffer) {
|
|
1786
|
+
var _a;
|
|
1726
1787
|
const lines = buffer.toString("utf-8").split("\n");
|
|
1727
1788
|
const entries = [];
|
|
1728
1789
|
for (let i = 0; i < lines.length; i++) {
|
|
1729
|
-
const line = lines[i];
|
|
1730
|
-
if (
|
|
1790
|
+
const line = (_a = lines[i]) == null ? void 0 : _a.trim();
|
|
1791
|
+
if (line === void 0 || line.length === 0) continue;
|
|
1731
1792
|
const obj = JSON.parse(line);
|
|
1732
|
-
if (
|
|
1793
|
+
if (typeof obj === "object" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
1733
1794
|
entries.push(mapEntry(obj));
|
|
1734
1795
|
}
|
|
1735
1796
|
return entries;
|
|
1736
1797
|
}
|
|
1737
1798
|
async function convertJawiktionaryAsync(stream) {
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
stream.destroy();
|
|
1753
|
-
resolve(entries);
|
|
1754
|
-
}
|
|
1755
|
-
);
|
|
1799
|
+
const rl = createInterface({
|
|
1800
|
+
input: stream,
|
|
1801
|
+
crlfDelay: Infinity
|
|
1802
|
+
});
|
|
1803
|
+
const entries = [];
|
|
1804
|
+
for await (const line of rl) {
|
|
1805
|
+
const obj = JSON.parse(line.trim());
|
|
1806
|
+
if (typeof obj === "object" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
1807
|
+
entries.push(mapEntry(obj));
|
|
1808
|
+
}
|
|
1809
|
+
rl.close();
|
|
1810
|
+
stream.close();
|
|
1811
|
+
stream.destroy();
|
|
1812
|
+
return entries;
|
|
1756
1813
|
}
|
|
1757
1814
|
function parseEntry(entry, definitions, definitionMap) {
|
|
1758
1815
|
for (const sense of entry.senses) {
|
|
@@ -1765,12 +1822,12 @@ function parseEntry(entry, definitions, definitionMap) {
|
|
|
1765
1822
|
}
|
|
1766
1823
|
}
|
|
1767
1824
|
}
|
|
1768
|
-
function getWordDefinitions(
|
|
1825
|
+
function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
1769
1826
|
var _a, _b, _c, _d, _e;
|
|
1770
1827
|
const entries = /* @__PURE__ */ new Map();
|
|
1771
|
-
for (const entry of
|
|
1828
|
+
for (const entry of wiktionaryEntries) {
|
|
1772
1829
|
const ent = entries.get(entry.word);
|
|
1773
|
-
if (ent) ent.push(entry);
|
|
1830
|
+
if (ent !== void 0) ent.push(entry);
|
|
1774
1831
|
else entries.set(entry.word, [entry]);
|
|
1775
1832
|
}
|
|
1776
1833
|
const japaneseDefinitions = [];
|
|
@@ -1784,16 +1841,14 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1784
1841
|
const wordKanjiForms = /* @__PURE__ */ new Set();
|
|
1785
1842
|
const rkf = getValidForms(
|
|
1786
1843
|
word.readings,
|
|
1787
|
-
word.kanjiForms
|
|
1788
|
-
word.isCommon
|
|
1844
|
+
word.kanjiForms
|
|
1789
1845
|
);
|
|
1790
|
-
|
|
1791
|
-
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1846
|
+
for (const r of rkf.readings) {
|
|
1847
|
+
validReadings.add(r.reading);
|
|
1848
|
+
wordReadings.add(r.reading);
|
|
1849
|
+
validForms.add(r.reading);
|
|
1850
|
+
}
|
|
1851
|
+
if (rkf.kanjiForms !== void 0 && rkf.kanjiForms.length > 0)
|
|
1797
1852
|
for (const kf of rkf.kanjiForms) {
|
|
1798
1853
|
validKanjiForms.add(kf.form);
|
|
1799
1854
|
wordKanjiForms.add(kf.form);
|
|
@@ -1813,44 +1868,42 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1813
1868
|
const ents = Array.from(entries.values()).flat();
|
|
1814
1869
|
for (const entry of ents) {
|
|
1815
1870
|
let valid = false;
|
|
1816
|
-
if (validKanjiForms
|
|
1871
|
+
if (validKanjiForms.has(entry.word)) {
|
|
1817
1872
|
valid = true;
|
|
1818
1873
|
for (const sense of entry.senses) {
|
|
1819
|
-
if (sense.form_of && sense.form_of.some((form) =>
|
|
1874
|
+
if (sense.form_of !== void 0 && sense.form_of.some((form) => validForms.has(form)))
|
|
1820
1875
|
validFormOfEntries.add(entry.word);
|
|
1821
1876
|
for (const gloss of sense.glosses) {
|
|
1822
1877
|
let hasForm = false;
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
}
|
|
1829
|
-
}
|
|
1878
|
+
for (const r of validForms)
|
|
1879
|
+
if (gloss.includes(r)) {
|
|
1880
|
+
hasForm = true;
|
|
1881
|
+
break;
|
|
1882
|
+
}
|
|
1830
1883
|
if (hasForm) validGlossesEntries.add(entry.word);
|
|
1831
1884
|
}
|
|
1832
1885
|
}
|
|
1833
|
-
if (entry.forms) {
|
|
1886
|
+
if (entry.forms !== void 0) {
|
|
1834
1887
|
for (const form of entry.forms)
|
|
1835
|
-
if (
|
|
1888
|
+
if (validForms.has(form)) validFormsEntries.add(entry.word);
|
|
1836
1889
|
}
|
|
1837
1890
|
}
|
|
1838
|
-
if (
|
|
1891
|
+
if (validForms.has(entry.word)) {
|
|
1839
1892
|
valid = true;
|
|
1840
1893
|
const ftEntry = entriesWithFormTitlesGlobal.get(entry.word);
|
|
1841
|
-
if (ftEntry) ftEntry.push(entry);
|
|
1894
|
+
if (ftEntry !== void 0) ftEntry.push(entry);
|
|
1842
1895
|
else entriesWithFormTitlesGlobal.set(entry.word, [entry]);
|
|
1843
1896
|
}
|
|
1844
1897
|
if (valid) {
|
|
1845
|
-
const tEntry = validTitleEntries.get(
|
|
1846
|
-
|
|
1898
|
+
const tEntry = validTitleEntries.get(
|
|
1899
|
+
entry.word
|
|
1900
|
+
);
|
|
1901
|
+
if (tEntry !== void 0) tEntry.push(entry);
|
|
1847
1902
|
else validTitleEntries.set(entry.word, [entry]);
|
|
1848
1903
|
}
|
|
1849
|
-
if (entry.forms
|
|
1850
|
-
(form) => validKanjiForms.has(form) || validReadings.has(form)
|
|
1851
|
-
)) {
|
|
1904
|
+
if (entry.forms !== void 0 && validForms.has(entry.word) && entry.forms.some((form) => validForms.has(form))) {
|
|
1852
1905
|
const wfEntry = entriesWithFormsGlobal.get(entry.word);
|
|
1853
|
-
if (wfEntry) wfEntry.push(entry);
|
|
1906
|
+
if (wfEntry !== void 0) wfEntry.push(entry);
|
|
1854
1907
|
else entriesWithFormsGlobal.set(entry.word, [entry]);
|
|
1855
1908
|
}
|
|
1856
1909
|
}
|
|
@@ -1865,53 +1918,17 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1865
1918
|
const wfe = Array.from(
|
|
1866
1919
|
entriesWithFormsGlobal.values()
|
|
1867
1920
|
).flat();
|
|
1868
|
-
for (const pos of
|
|
1869
|
-
"\u540D\u8A5E",
|
|
1870
|
-
"\u52D5\u8A5E",
|
|
1871
|
-
"\u6210\u53E5",
|
|
1872
|
-
"\u526F\u8A5E",
|
|
1873
|
-
"\u5F62\u5BB9\u52D5\u8A5E",
|
|
1874
|
-
"\u52A9\u8A5E",
|
|
1875
|
-
"\u611F\u52D5\u8A5E",
|
|
1876
|
-
"\u4EE3\u540D\u8A5E",
|
|
1877
|
-
"\u63A5\u5C3E\u8F9E",
|
|
1878
|
-
"\u63A5\u982D\u8A9E",
|
|
1879
|
-
"\u9020\u8A9E\u6210\u5206",
|
|
1880
|
-
"\u7565\u8A9E",
|
|
1881
|
-
"\u56FA\u6709\u540D\u8A5E",
|
|
1882
|
-
"\u4EBA\u79F0\u4EE3\u540D\u8A5E",
|
|
1883
|
-
"\u63A5\u982D\u8F9E",
|
|
1884
|
-
"\u63A5\u7D9A\u52A9\u8A5E",
|
|
1885
|
-
"\u9593\u6295\u8A5E",
|
|
1886
|
-
"\u52A9\u52D5\u8A5E",
|
|
1887
|
-
"\u5F62\u5BB9\u8A5E",
|
|
1888
|
-
"\u7E2E\u7D04\u5F62",
|
|
1889
|
-
"\u63A5\u8F9E",
|
|
1890
|
-
"\u63A5\u7D9A\u8A5E",
|
|
1891
|
-
"\u9023\u4F53\u8A5E",
|
|
1892
|
-
"\u4EBA\u540D",
|
|
1893
|
-
"\u8A18\u53F7",
|
|
1894
|
-
"\u6570\u8A5E",
|
|
1895
|
-
"\u6163\u7528\u53E5",
|
|
1896
|
-
"\u3053\u3068\u308F\u3056",
|
|
1897
|
-
"\u52A9\u6570\u8A5E",
|
|
1898
|
-
"\u82F1\u6570\u5B57\u6DF7\u5408\u8868\u8A18",
|
|
1899
|
-
"\u52D5\u8A5E\u53E5",
|
|
1900
|
-
"\u6210\u8A9E",
|
|
1901
|
-
"\u610F\u7FA9",
|
|
1902
|
-
"\u982D\u5B57\u8A9E",
|
|
1903
|
-
"\u63A5\u5C3E\u8A9E"
|
|
1904
|
-
]) {
|
|
1921
|
+
for (const pos of posList) {
|
|
1905
1922
|
posMap.set(pos, {});
|
|
1906
1923
|
for (const te of vte)
|
|
1907
1924
|
if (te.pos_title === pos || te.pos_title === "\u548C\u8A9E\u306E\u6F22\u5B57\u8868\u8A18") {
|
|
1908
1925
|
const posEntries = posMap.get(pos);
|
|
1909
1926
|
if (posEntries.title === void 0)
|
|
1910
1927
|
posEntries.title = /* @__PURE__ */ new Map();
|
|
1911
|
-
const
|
|
1928
|
+
const entryList = posEntries.title.get(
|
|
1912
1929
|
te.word
|
|
1913
1930
|
);
|
|
1914
|
-
if (
|
|
1931
|
+
if (entryList !== void 0) entryList.push(te);
|
|
1915
1932
|
else posEntries.title.set(te.word, [te]);
|
|
1916
1933
|
}
|
|
1917
1934
|
for (const ft of fge)
|
|
@@ -1919,8 +1936,8 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1919
1936
|
const posEntries = posMap.get(pos);
|
|
1920
1937
|
if (posEntries.formTitle === void 0)
|
|
1921
1938
|
posEntries.formTitle = /* @__PURE__ */ new Map();
|
|
1922
|
-
const
|
|
1923
|
-
if (
|
|
1939
|
+
const entryList = posEntries.formTitle.get(ft.word);
|
|
1940
|
+
if (entryList !== void 0) entryList.push(ft);
|
|
1924
1941
|
else posEntries.formTitle.set(ft.word, [ft]);
|
|
1925
1942
|
}
|
|
1926
1943
|
for (const wf of wfe)
|
|
@@ -1928,10 +1945,10 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1928
1945
|
const posEntries = posMap.get(pos);
|
|
1929
1946
|
if (posEntries.form === void 0)
|
|
1930
1947
|
posEntries.form = /* @__PURE__ */ new Map();
|
|
1931
|
-
const
|
|
1948
|
+
const entryList = posEntries.form.get(
|
|
1932
1949
|
wf.word
|
|
1933
1950
|
);
|
|
1934
|
-
if (
|
|
1951
|
+
if (entryList !== void 0) entryList.push(wf);
|
|
1935
1952
|
else posEntries.form.set(wf.word, [wf]);
|
|
1936
1953
|
}
|
|
1937
1954
|
}
|
|
@@ -1944,7 +1961,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1944
1961
|
for (const m of word.meanings)
|
|
1945
1962
|
for (const note of m.partOfSpeech) {
|
|
1946
1963
|
const noteEntry = noteMap.get(note);
|
|
1947
|
-
if (noteEntry
|
|
1964
|
+
if ((noteEntry == null ? void 0 : noteEntry.length) === 3) {
|
|
1948
1965
|
const notePos = noteEntry[2];
|
|
1949
1966
|
if (Array.isArray(notePos))
|
|
1950
1967
|
for (const pos of notePos) {
|
|
@@ -1961,21 +1978,21 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1961
1978
|
if (poses.size > 0)
|
|
1962
1979
|
for (const pos of poses) {
|
|
1963
1980
|
const posEntries = posMap.get(pos);
|
|
1964
|
-
if (rkf.kanjiForms)
|
|
1981
|
+
if (rkf.kanjiForms !== void 0)
|
|
1965
1982
|
for (const kf of rkf.kanjiForms) {
|
|
1966
1983
|
const te = (_a = posEntries.title) == null ? void 0 : _a.get(kf);
|
|
1967
1984
|
const fe = (_b = posEntries.form) == null ? void 0 : _b.get(kf);
|
|
1968
|
-
if (te)
|
|
1985
|
+
if (te !== void 0)
|
|
1969
1986
|
entriesWithTitles.push(
|
|
1970
1987
|
...te.filter(
|
|
1971
1988
|
(ent) => validFormOfEntries.has(ent.word) || validGlossesEntries.has(ent.word) || validFormsEntries.has(ent.word)
|
|
1972
1989
|
)
|
|
1973
1990
|
);
|
|
1974
|
-
if (fe)
|
|
1991
|
+
if (fe !== void 0)
|
|
1975
1992
|
entriesWithForms.push(
|
|
1976
1993
|
...fe.filter(
|
|
1977
|
-
(ent) => ent.forms && ent.forms.some(
|
|
1978
|
-
(form) => rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1994
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
1995
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1979
1996
|
)
|
|
1980
1997
|
)
|
|
1981
1998
|
);
|
|
@@ -1984,41 +2001,41 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1984
2001
|
const te = (_c = posEntries.title) == null ? void 0 : _c.get(r);
|
|
1985
2002
|
const fe = (_d = posEntries.form) == null ? void 0 : _d.get(r);
|
|
1986
2003
|
const fte = (_e = posEntries.formTitle) == null ? void 0 : _e.get(r);
|
|
1987
|
-
if (te)
|
|
2004
|
+
if (te !== void 0)
|
|
1988
2005
|
entriesWithTitles.push(
|
|
1989
2006
|
...te.filter(
|
|
1990
|
-
(ent) => ent.forms
|
|
1991
|
-
(form) => rkf.kanjiForms.has(form)
|
|
1992
|
-
)
|
|
2007
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2008
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2009
|
+
)
|
|
1993
2010
|
)
|
|
1994
2011
|
);
|
|
1995
|
-
if (fe)
|
|
2012
|
+
if (fe !== void 0)
|
|
1996
2013
|
entriesWithForms.push(
|
|
1997
2014
|
...fe.filter(
|
|
1998
|
-
(ent) => ent.forms && ent.forms.some(
|
|
1999
|
-
(form) => rkf.kanjiForms && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2015
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2016
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2000
2017
|
)
|
|
2001
2018
|
)
|
|
2002
2019
|
);
|
|
2003
|
-
if (fte) entriesWithFormTitles.push(...fte);
|
|
2020
|
+
if (fte !== void 0) entriesWithFormTitles.push(...fte);
|
|
2004
2021
|
}
|
|
2005
2022
|
}
|
|
2006
2023
|
if (entriesWithTitles.length === 0 && entriesWithFormTitles.length === 0 && entriesWithForms.length === 0) {
|
|
2007
|
-
if (rkf.kanjiForms)
|
|
2024
|
+
if (rkf.kanjiForms !== void 0)
|
|
2008
2025
|
for (const kf of rkf.kanjiForms) {
|
|
2009
2026
|
const te = validTitleEntries.get(kf);
|
|
2010
2027
|
const fe = entriesWithFormsGlobal.get(kf);
|
|
2011
|
-
if (te)
|
|
2028
|
+
if (te !== void 0)
|
|
2012
2029
|
entriesWithTitles.push(
|
|
2013
2030
|
...te.filter(
|
|
2014
2031
|
(ent) => validFormOfEntries.has(ent.word) || validGlossesEntries.has(ent.word) || validFormsEntries.has(ent.word)
|
|
2015
2032
|
)
|
|
2016
2033
|
);
|
|
2017
|
-
if (fe)
|
|
2034
|
+
if (fe !== void 0)
|
|
2018
2035
|
entriesWithForms.push(
|
|
2019
2036
|
...fe.filter(
|
|
2020
|
-
(ent) => ent.forms && ent.forms.some(
|
|
2021
|
-
(form) => rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2037
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2038
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2022
2039
|
)
|
|
2023
2040
|
)
|
|
2024
2041
|
);
|
|
@@ -2027,31 +2044,31 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2027
2044
|
const te = validTitleEntries.get(r);
|
|
2028
2045
|
const fe = entriesWithFormsGlobal.get(r);
|
|
2029
2046
|
const fte = entriesWithFormTitlesGlobal.get(r);
|
|
2030
|
-
if (te)
|
|
2047
|
+
if (te !== void 0)
|
|
2031
2048
|
entriesWithTitles.push(
|
|
2032
2049
|
...te.filter(
|
|
2033
|
-
(ent) => ent.forms
|
|
2034
|
-
(form) => rkf.kanjiForms.has(form)
|
|
2035
|
-
)
|
|
2050
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2051
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2052
|
+
)
|
|
2036
2053
|
)
|
|
2037
2054
|
);
|
|
2038
|
-
if (fe)
|
|
2055
|
+
if (fe !== void 0)
|
|
2039
2056
|
entriesWithForms.push(
|
|
2040
2057
|
...fe.filter(
|
|
2041
|
-
(ent) => ent.forms && ent.forms.some(
|
|
2042
|
-
(form) => rkf.kanjiForms && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2058
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2059
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2043
2060
|
)
|
|
2044
2061
|
)
|
|
2045
2062
|
);
|
|
2046
|
-
if (fte) entriesWithFormTitles.push(...fte);
|
|
2063
|
+
if (fte !== void 0) entriesWithFormTitles.push(...fte);
|
|
2047
2064
|
}
|
|
2048
2065
|
}
|
|
2049
2066
|
if (entriesWithTitles.length > 0 && (entriesWithFormTitles.length > 0 || entriesWithForms.length > 0))
|
|
2050
2067
|
wordEntriesPairs.push({
|
|
2051
2068
|
word,
|
|
2052
2069
|
readings: rkf.readings,
|
|
2053
|
-
...rkf.kanjiForms ? { kanjiForms: rkf.kanjiForms } : {},
|
|
2054
|
-
forms: rkf.kanjiForms ? rkf.readings.union(rkf.kanjiForms) : rkf.readings,
|
|
2070
|
+
...rkf.kanjiForms !== void 0 ? { kanjiForms: rkf.kanjiForms } : {},
|
|
2071
|
+
forms: rkf.kanjiForms !== void 0 ? rkf.readings.union(rkf.kanjiForms) : rkf.readings,
|
|
2055
2072
|
entriesWithTitles,
|
|
2056
2073
|
entriesWithFormTitles,
|
|
2057
2074
|
entriesWithForms
|
|
@@ -2064,59 +2081,54 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2064
2081
|
const readingEntries = [];
|
|
2065
2082
|
const titleFormMap = /* @__PURE__ */ new Map();
|
|
2066
2083
|
const refsMap = /* @__PURE__ */ new Map();
|
|
2067
|
-
const
|
|
2084
|
+
const forms = /* @__PURE__ */ new Set();
|
|
2068
2085
|
for (const ent of pair.entriesWithTitles) {
|
|
2069
|
-
const
|
|
2070
|
-
const
|
|
2071
|
-
const
|
|
2072
|
-
|
|
2073
|
-
if (pair.kanjiForms && pair.kanjiForms.has(ent.word) && (validFormOf || validGlosses || validForms2)) {
|
|
2086
|
+
const hasValidFormOf = validFormOfEntries.has(ent.word);
|
|
2087
|
+
const hasValidForms = validFormsEntries.has(ent.word);
|
|
2088
|
+
const hasForms = ent.forms !== void 0 && ent.forms.some((form) => pair.forms.has(form));
|
|
2089
|
+
if (pair.kanjiForms !== void 0 && pair.kanjiForms.has(ent.word)) {
|
|
2074
2090
|
kanjiFormEntries.push(ent);
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
2080
|
-
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
|
|
2084
|
-
}
|
|
2085
|
-
}
|
|
2086
|
-
if (validGlosses) {
|
|
2087
|
-
for (const gloss of sense.glosses)
|
|
2088
|
-
if (gloss.includes("\u8868\u8A18") || gloss.includes("\u53C2\u7167")) {
|
|
2089
|
-
for (const f of pair.forms)
|
|
2090
|
-
if (gloss.includes(f)) {
|
|
2091
|
-
const elem = refsMap.get(f);
|
|
2092
|
-
if (!elem) refsMap.set(f, /* @__PURE__ */ new Set([ent.word]));
|
|
2093
|
-
else elem.add(ent.word);
|
|
2094
|
-
}
|
|
2095
|
-
}
|
|
2096
|
-
}
|
|
2091
|
+
for (const sense of ent.senses) {
|
|
2092
|
+
if (hasValidFormOf && sense.form_of !== void 0) {
|
|
2093
|
+
for (const form of sense.form_of)
|
|
2094
|
+
if (pair.forms.has(form)) {
|
|
2095
|
+
const elem = titleFormMap.get(form);
|
|
2096
|
+
if (elem === void 0)
|
|
2097
|
+
titleFormMap.set(form, /* @__PURE__ */ new Set([ent.word]));
|
|
2098
|
+
else elem.add(ent.word);
|
|
2099
|
+
}
|
|
2097
2100
|
}
|
|
2098
|
-
|
|
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
|
+
if (hasValidForms && ent.forms !== void 0) {
|
|
2099
2111
|
for (const form of ent.forms)
|
|
2100
|
-
if (pair.
|
|
2112
|
+
if (pair.forms.has(form)) forms.add(form);
|
|
2101
2113
|
}
|
|
2102
2114
|
}
|
|
2103
|
-
if (pair.readings.has(ent.word) &&
|
|
2104
|
-
entriesWithForms.push(ent);
|
|
2115
|
+
if (pair.readings.has(ent.word) && hasForms) entriesWithForms.push(ent);
|
|
2105
2116
|
if (pair.kanjiForms === void 0 && pair.readings.has(ent.word))
|
|
2106
2117
|
readingEntries.push(ent);
|
|
2107
2118
|
}
|
|
2108
2119
|
for (const entry of pair.entriesWithForms) {
|
|
2109
2120
|
const elem = titleFormMap.get(entry.word);
|
|
2110
|
-
if (elem && entry.forms && entry.forms.some((form) => elem.has(form)))
|
|
2121
|
+
if (elem !== void 0 && entry.forms !== void 0 && entry.forms.some((form) => elem.has(form)))
|
|
2111
2122
|
entriesWithForms.push(entry);
|
|
2112
2123
|
}
|
|
2113
2124
|
for (const entry of pair.entriesWithFormTitles) {
|
|
2114
|
-
if (
|
|
2125
|
+
if (forms.has(entry.word)) {
|
|
2115
2126
|
entriesWithForms.push(entry);
|
|
2116
2127
|
continue;
|
|
2117
2128
|
}
|
|
2118
2129
|
const ft = refsMap.get(entry.word);
|
|
2119
|
-
if (ft && !ft.isDisjointFrom(pair.forms))
|
|
2130
|
+
if (ft !== void 0 && !ft.isDisjointFrom(pair.forms))
|
|
2131
|
+
entriesWithForms.push(entry);
|
|
2120
2132
|
}
|
|
2121
2133
|
if (kanjiFormEntries.length > 0) {
|
|
2122
2134
|
for (const entry of kanjiFormEntries)
|
|
@@ -2132,7 +2144,15 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2132
2144
|
if (definitions.length > 0)
|
|
2133
2145
|
japaneseDefinitions.push({
|
|
2134
2146
|
wordID: pair.word.id,
|
|
2135
|
-
definitions
|
|
2147
|
+
definitions,
|
|
2148
|
+
wordForms: pair.forms.union(
|
|
2149
|
+
new Set(
|
|
2150
|
+
pair.forms.values().toArray().flatMap((form) => [
|
|
2151
|
+
hiraganaToKatakana(form),
|
|
2152
|
+
katakanaToHiragana(form)
|
|
2153
|
+
])
|
|
2154
|
+
)
|
|
2155
|
+
)
|
|
2136
2156
|
});
|
|
2137
2157
|
}
|
|
2138
2158
|
for (let i = 0; i < japaneseDefinitions.length; i++) {
|
|
@@ -2141,41 +2161,46 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2141
2161
|
const defCount = definitionMap.get(
|
|
2142
2162
|
pair.definitions[j].definition
|
|
2143
2163
|
);
|
|
2144
|
-
if (defCount && defCount.count > 1)
|
|
2145
|
-
|
|
2164
|
+
if (defCount !== void 0 && defCount.count > 1) {
|
|
2165
|
+
let mnba = true;
|
|
2166
|
+
for (const f of pair.wordForms)
|
|
2167
|
+
if (pair.definitions[j].definition.includes(f)) {
|
|
2168
|
+
mnba = false;
|
|
2169
|
+
break;
|
|
2170
|
+
}
|
|
2171
|
+
pair.definitions[j].mayNotBeAccurate = mnba ? 2 : 1;
|
|
2172
|
+
}
|
|
2146
2173
|
}
|
|
2174
|
+
delete pair.wordForms;
|
|
2147
2175
|
japaneseDefinitions[i] = pair;
|
|
2148
2176
|
}
|
|
2149
2177
|
return japaneseDefinitions;
|
|
2150
2178
|
}
|
|
2151
2179
|
async function getWordDefinitionsWithFurigana(entryList, jmDict) {
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
pair.definitions[j].
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
}
|
|
2173
|
-
resolve(japaneseDefinitions);
|
|
2174
|
-
});
|
|
2180
|
+
const japaneseDefinitions = getWordDefinitions(
|
|
2181
|
+
entryList,
|
|
2182
|
+
jmDict
|
|
2183
|
+
);
|
|
2184
|
+
const kuroshiro = new Kuroshiro.default();
|
|
2185
|
+
await kuroshiro.init(new KuromojiAnalyzer());
|
|
2186
|
+
const convert = kuroshiro.convert.bind(kuroshiro);
|
|
2187
|
+
for (let i = 0; i < japaneseDefinitions.length; i++) {
|
|
2188
|
+
const pair = japaneseDefinitions[i];
|
|
2189
|
+
for (let j = 0; j < pair.definitions.length; j++)
|
|
2190
|
+
if (!pair.definitions[j].definition.includes("\u30FB"))
|
|
2191
|
+
pair.definitions[j].furigana = String(
|
|
2192
|
+
await convert(pair.definitions[j].definition, {
|
|
2193
|
+
to: "hiragana",
|
|
2194
|
+
mode: "furigana"
|
|
2195
|
+
})
|
|
2196
|
+
);
|
|
2197
|
+
japaneseDefinitions[i] = pair;
|
|
2198
|
+
}
|
|
2199
|
+
return japaneseDefinitions;
|
|
2175
2200
|
}
|
|
2176
2201
|
function lookupWordNote(key, notes, tags) {
|
|
2177
2202
|
const info = noteMap.get(key.toLowerCase());
|
|
2178
|
-
if (
|
|
2203
|
+
if (info === void 0) {
|
|
2179
2204
|
notes.push(key);
|
|
2180
2205
|
return { note: key };
|
|
2181
2206
|
}
|
|
@@ -2185,22 +2210,172 @@ function lookupWordNote(key, notes, tags) {
|
|
|
2185
2210
|
return { note: info[1], tag };
|
|
2186
2211
|
}
|
|
2187
2212
|
var wordAddNoteArray = (arr, cb) => {
|
|
2188
|
-
if (
|
|
2213
|
+
if (arr === void 0) return;
|
|
2189
2214
|
for (const v of arr) cb(v);
|
|
2190
2215
|
};
|
|
2191
|
-
function
|
|
2216
|
+
function getKanji(searchedKanji, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
2217
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2218
|
+
let dictKanji = void 0;
|
|
2219
|
+
if (typeof searchedKanji === "string" && dict !== void 0)
|
|
2220
|
+
dictKanji = dict instanceof Map ? dict.get(searchedKanji) : dict.find((entry) => entry.kanji === searchedKanji);
|
|
2221
|
+
else if (typeof searchedKanji === "object") dictKanji = searchedKanji;
|
|
2222
|
+
if (dictKanji !== void 0) {
|
|
2223
|
+
const kanji = {
|
|
2224
|
+
kanji: dictKanji.kanji,
|
|
2225
|
+
strokes: dictKanji.misc.strokeNumber,
|
|
2226
|
+
...((_a = dictKanji.misc) == null ? void 0 : _a.grade) !== void 0 ? { grade: dictKanji.misc.grade } : {},
|
|
2227
|
+
...((_b = dictKanji.misc) == null ? void 0 : _b.frequency) !== void 0 ? { frequency: dictKanji.misc.frequency } : {},
|
|
2228
|
+
...((_c = dictKanji.misc) == null ? void 0 : _c.jlpt) !== void 0 ? { jlpt: dictKanji.misc.jlpt } : {},
|
|
2229
|
+
noteID: `kanji_${dictKanji.kanji}`,
|
|
2230
|
+
...noteTypeName !== void 0 ? { noteTypeName } : {},
|
|
2231
|
+
...deckPath !== void 0 ? { deckPath } : {},
|
|
2232
|
+
tags: []
|
|
2233
|
+
};
|
|
2234
|
+
if (dictKanji.readingMeaning !== void 0 && dictKanji.readingMeaning.length > 0) {
|
|
2235
|
+
const meanings = [];
|
|
2236
|
+
const nanori = [];
|
|
2237
|
+
const onyomi = [];
|
|
2238
|
+
const kunyomi = [];
|
|
2239
|
+
for (const rm of dictKanji.readingMeaning) {
|
|
2240
|
+
if (rm.nanori !== void 0 && rm.nanori.length > 0)
|
|
2241
|
+
nanori.push(...rm.nanori);
|
|
2242
|
+
for (const group of rm.groups) {
|
|
2243
|
+
if (group.readings !== void 0) {
|
|
2244
|
+
onyomi.push(
|
|
2245
|
+
...group.readings.filter((reading) => reading.type === "ja_on").map((reading) => reading.reading)
|
|
2246
|
+
);
|
|
2247
|
+
kunyomi.push(
|
|
2248
|
+
...group.readings.filter(
|
|
2249
|
+
(reading) => reading.type === "ja_kun"
|
|
2250
|
+
).map((reading) => reading.reading)
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
if (group.meanings !== void 0 && group.meanings.length > 0)
|
|
2254
|
+
meanings.push(...group.meanings);
|
|
2255
|
+
}
|
|
2256
|
+
}
|
|
2257
|
+
if (meanings.length > 0) kanji.meanings = meanings;
|
|
2258
|
+
if (nanori.length > 0) kanji.nanori = nanori;
|
|
2259
|
+
if (onyomi.length > 0) kanji.onyomi = onyomi;
|
|
2260
|
+
if (kunyomi.length > 0) kanji.kunyomi = kunyomi;
|
|
2261
|
+
}
|
|
2262
|
+
if (jmDict !== void 0) {
|
|
2263
|
+
let kanjiWords = jmDict instanceof Map ? jmDict.get(kanji.kanji) : jmDict;
|
|
2264
|
+
const firstKfWords = kanjiWords == null ? void 0 : kanjiWords.filter(
|
|
2265
|
+
(word) => word.kanjiForms !== void 0 && word.kanjiForms[0].form.includes(kanji.kanji)
|
|
2266
|
+
);
|
|
2267
|
+
if (firstKfWords !== void 0 && firstKfWords.length > 0)
|
|
2268
|
+
kanjiWords = firstKfWords;
|
|
2269
|
+
if (kanjiWords !== void 0) {
|
|
2270
|
+
const validWords = [];
|
|
2271
|
+
for (const word of kanjiWords) {
|
|
2272
|
+
const kanjiForm = (_d = firstKfWords !== void 0 && firstKfWords.length > 0 ? word.kanjiForms[0] : word.kanjiForms.find(
|
|
2273
|
+
(kf) => kf.form.includes(kanji.kanji)
|
|
2274
|
+
)) == null ? void 0 : _d.form;
|
|
2275
|
+
if (kanjiForm !== void 0) {
|
|
2276
|
+
const reading = (_e = firstKfWords !== void 0 && firstKfWords.length > 0 ? word.readings[0] : word.readings.find(
|
|
2277
|
+
(r) => r.kanjiFormRestrictions !== void 0 && r.kanjiFormRestrictions.includes(kanjiForm)
|
|
2278
|
+
)) == null ? void 0 : _e.reading;
|
|
2279
|
+
if (reading === void 0) continue;
|
|
2280
|
+
const translation = (_f = firstKfWords !== void 0 && firstKfWords.length > 0 ? word.meanings[0] : word.meanings.find(
|
|
2281
|
+
(m) => m.kanjiFormRestrictions !== void 0 && m.kanjiFormRestrictions.includes(kanjiForm)
|
|
2282
|
+
)) == null ? void 0 : _f.translations.map(
|
|
2283
|
+
(t) => typeof t === "string" ? t : t.translation
|
|
2284
|
+
)[0];
|
|
2285
|
+
if (translation === void 0) continue;
|
|
2286
|
+
validWords.push({
|
|
2287
|
+
kanjiForms: [{ kanjiForm }],
|
|
2288
|
+
readings: [{ reading }],
|
|
2289
|
+
translations: [
|
|
2290
|
+
{
|
|
2291
|
+
translation
|
|
2292
|
+
}
|
|
2293
|
+
]
|
|
2294
|
+
});
|
|
2295
|
+
}
|
|
2296
|
+
if (validWords.length === 3) break;
|
|
2297
|
+
}
|
|
2298
|
+
if (validWords.length > 0) kanji.words = validWords;
|
|
2299
|
+
}
|
|
2300
|
+
}
|
|
2301
|
+
if (svgList !== void 0) {
|
|
2302
|
+
const codePoint = kanji.kanji.codePointAt(0).toString(16).toLowerCase();
|
|
2303
|
+
const svg = svgList instanceof Map ? svgList.get(kanji.kanji) : svgList.find(
|
|
2304
|
+
(svgFile) => [`${codePoint}.svg`, `0${codePoint}.svg`].includes(
|
|
2305
|
+
svgFile.toLowerCase()
|
|
2306
|
+
)
|
|
2307
|
+
);
|
|
2308
|
+
if (svg !== void 0) kanji.svg = svg;
|
|
2309
|
+
}
|
|
2310
|
+
if (dictKanji.isKokuji === true) {
|
|
2311
|
+
kanji.kokuji = true;
|
|
2312
|
+
kanji.tags.push("kanji::kokuji");
|
|
2313
|
+
}
|
|
2314
|
+
kanji.tags.push(
|
|
2315
|
+
`kanji::strokes::${kanji.strokes}`,
|
|
2316
|
+
...kanji.frequency !== void 0 ? [`kanji::frequency::${kanji.frequency}`] : [],
|
|
2317
|
+
...kanji.grade !== void 0 ? [`kanji::grade::${kanji.grade}`] : [],
|
|
2318
|
+
...kanji.jlpt !== void 0 ? [`kanji::pre-2010_jlpt::${kanji.jlpt.toLowerCase()}`] : [],
|
|
2319
|
+
`kanji::onyomi::${((_g = kanji.onyomi) == null ? void 0 : _g.length) ?? 0}`,
|
|
2320
|
+
`kanji::kunyomi::${((_h = kanji.kunyomi) == null ? void 0 : _h.length) ?? 0}`,
|
|
2321
|
+
`kanji::nanori::${((_i = kanji.nanori) == null ? void 0 : _i.length) ?? 0}`,
|
|
2322
|
+
`kanji::words::${((_j = kanji.words) == null ? void 0 : _j.length) ?? 0}`,
|
|
2323
|
+
...kanji.svg !== void 0 ? ["kanji::has_svg"] : []
|
|
2324
|
+
);
|
|
2325
|
+
return kanji;
|
|
2326
|
+
} else return void 0;
|
|
2327
|
+
}
|
|
2328
|
+
function getKanjiExtended(info, kanji, dict, useWords, jmDict, svgList, noteTypeName, deckPath, sourceURL) {
|
|
2329
|
+
const kanjiObj = getKanji(
|
|
2330
|
+
kanji,
|
|
2331
|
+
dict,
|
|
2332
|
+
jmDict,
|
|
2333
|
+
svgList,
|
|
2334
|
+
noteTypeName,
|
|
2335
|
+
deckPath
|
|
2336
|
+
);
|
|
2337
|
+
if (kanjiObj !== void 0) {
|
|
2338
|
+
let usedInfo = false;
|
|
2339
|
+
if (info.components !== void 0) {
|
|
2340
|
+
kanjiObj.components = info.components;
|
|
2341
|
+
kanjiObj.tags.push(`kanji::components::${kanjiObj.components.length}`);
|
|
2342
|
+
usedInfo = true;
|
|
2343
|
+
}
|
|
2344
|
+
if (info.mnemonic !== void 0 && info.mnemonic.length > 0) {
|
|
2345
|
+
kanjiObj.mnemonic = info.mnemonic;
|
|
2346
|
+
kanjiObj.tags.push("kanji::has_mnemonic");
|
|
2347
|
+
usedInfo = true;
|
|
2348
|
+
}
|
|
2349
|
+
if (useWords === true && info.words !== void 0 && info.words.length > 0) {
|
|
2350
|
+
kanjiObj.words = info.words;
|
|
2351
|
+
kanjiObj.tags.forEach((tag, index) => {
|
|
2352
|
+
if (tag.startsWith("kanji::words::") && kanjiObj.words !== void 0)
|
|
2353
|
+
kanjiObj.tags.splice(
|
|
2354
|
+
index,
|
|
2355
|
+
1,
|
|
2356
|
+
`kanji::words::${kanjiObj.words.length}`
|
|
2357
|
+
);
|
|
2358
|
+
});
|
|
2359
|
+
usedInfo = true;
|
|
2360
|
+
}
|
|
2361
|
+
if (sourceURL !== void 0 && info.externalInfo === true && usedInfo)
|
|
2362
|
+
kanjiObj.source = sourceURL;
|
|
2363
|
+
return kanjiObj;
|
|
2364
|
+
} else return void 0;
|
|
2365
|
+
}
|
|
2366
|
+
function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeName, deckPath) {
|
|
2192
2367
|
var _a;
|
|
2193
2368
|
let dictWord = void 0;
|
|
2194
|
-
if (typeof
|
|
2369
|
+
if (typeof searchedWord === "string" && dict !== void 0) {
|
|
2195
2370
|
if (Array.isArray(dict))
|
|
2196
2371
|
dictWord = dict.find(
|
|
2197
|
-
(entry) => entry.id ===
|
|
2372
|
+
(entry) => entry.id === searchedWord
|
|
2198
2373
|
);
|
|
2199
|
-
if (dict instanceof Map) dictWord = dict.get(
|
|
2374
|
+
if (dict instanceof Map) dictWord = dict.get(searchedWord);
|
|
2200
2375
|
}
|
|
2201
|
-
if (typeof
|
|
2202
|
-
if (dictWord) {
|
|
2203
|
-
const
|
|
2376
|
+
if (typeof searchedWord === "object") dictWord = searchedWord;
|
|
2377
|
+
if (dictWord !== void 0) {
|
|
2378
|
+
const word = {
|
|
2204
2379
|
id: dictWord.id,
|
|
2205
2380
|
readings: [],
|
|
2206
2381
|
translations: [],
|
|
@@ -2210,46 +2385,46 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2210
2385
|
tags: []
|
|
2211
2386
|
};
|
|
2212
2387
|
if (dictWord.isCommon === true) {
|
|
2213
|
-
|
|
2214
|
-
|
|
2388
|
+
word.common = true;
|
|
2389
|
+
word.tags.push("word::common");
|
|
2215
2390
|
}
|
|
2216
|
-
if (dictWord.kanjiForms)
|
|
2217
|
-
|
|
2391
|
+
if (dictWord.kanjiForms !== void 0)
|
|
2392
|
+
word.kanjiForms = dictWord.kanjiForms.map(
|
|
2218
2393
|
(dictKanjiForm) => ({
|
|
2219
2394
|
kanjiForm: dictKanjiForm.form,
|
|
2220
|
-
...dictKanjiForm.notes ? {
|
|
2395
|
+
...dictKanjiForm.notes !== void 0 ? {
|
|
2221
2396
|
notes: dictKanjiForm.notes.map((note) => {
|
|
2222
2397
|
const noteAndTag = lookupWordNote(
|
|
2223
2398
|
note,
|
|
2224
2399
|
[],
|
|
2225
|
-
|
|
2400
|
+
word.tags
|
|
2226
2401
|
);
|
|
2227
2402
|
return capitalizeString(noteAndTag.note);
|
|
2228
2403
|
})
|
|
2229
2404
|
} : {},
|
|
2230
|
-
...dictKanjiForm.commonness && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
|
|
2405
|
+
...dictKanjiForm.commonness !== void 0 && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
|
|
2231
2406
|
})
|
|
2232
2407
|
);
|
|
2233
|
-
|
|
2408
|
+
word.readings = dictWord.readings.map((dictReading) => ({
|
|
2234
2409
|
reading: dictReading.reading,
|
|
2235
|
-
...dictReading.kanjiFormRestrictions || dictReading.notes ? {
|
|
2410
|
+
...dictReading.kanjiFormRestrictions !== void 0 || dictReading.notes !== void 0 ? {
|
|
2236
2411
|
notes: [
|
|
2237
|
-
...dictReading.kanjiFormRestrictions ? dictReading.kanjiFormRestrictions.map(
|
|
2412
|
+
...dictReading.kanjiFormRestrictions !== void 0 ? dictReading.kanjiFormRestrictions.map(
|
|
2238
2413
|
(restriction) => `Reading restricted to ${restriction}`
|
|
2239
2414
|
) : [],
|
|
2240
|
-
...dictReading.notes ? dictReading.notes.map((note) => {
|
|
2415
|
+
...dictReading.notes !== void 0 ? dictReading.notes.map((note) => {
|
|
2241
2416
|
const noteAndTag = lookupWordNote(
|
|
2242
2417
|
note,
|
|
2243
2418
|
[],
|
|
2244
|
-
|
|
2419
|
+
word.tags
|
|
2245
2420
|
);
|
|
2246
2421
|
return capitalizeString(noteAndTag.note);
|
|
2247
2422
|
}) : []
|
|
2248
2423
|
]
|
|
2249
2424
|
} : {},
|
|
2250
|
-
...dictReading.commonness && dictReading.commonness.length > 0 ? { common: true } : {}
|
|
2425
|
+
...dictReading.commonness !== void 0 && dictReading.commonness.length > 0 ? { common: true } : {}
|
|
2251
2426
|
}));
|
|
2252
|
-
|
|
2427
|
+
word.translations = [];
|
|
2253
2428
|
for (const dictMeaning of dictWord.meanings) {
|
|
2254
2429
|
const translationTypes = [];
|
|
2255
2430
|
const translations = dictMeaning.translations.map(
|
|
@@ -2260,7 +2435,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2260
2435
|
translation.type
|
|
2261
2436
|
);
|
|
2262
2437
|
translationTypes.push(translationNoteAndTag[1]);
|
|
2263
|
-
|
|
2438
|
+
word.tags.push(`word::${translationNoteAndTag[0]}`);
|
|
2264
2439
|
return translation.translation;
|
|
2265
2440
|
}
|
|
2266
2441
|
}
|
|
@@ -2277,15 +2452,15 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2277
2452
|
for (const t of translationTypes) notes.push(t);
|
|
2278
2453
|
wordAddNoteArray(
|
|
2279
2454
|
dictMeaning.partOfSpeech,
|
|
2280
|
-
(pos) => lookupWordNote(pos, notes,
|
|
2455
|
+
(pos) => lookupWordNote(pos, notes, word.tags)
|
|
2281
2456
|
);
|
|
2282
2457
|
wordAddNoteArray(
|
|
2283
2458
|
dictMeaning.fields,
|
|
2284
|
-
(field) => lookupWordNote(field, notes,
|
|
2459
|
+
(field) => lookupWordNote(field, notes, word.tags)
|
|
2285
2460
|
);
|
|
2286
2461
|
wordAddNoteArray(
|
|
2287
2462
|
dictMeaning.dialects,
|
|
2288
|
-
(dialect) => lookupWordNote(dialect, notes,
|
|
2463
|
+
(dialect) => lookupWordNote(dialect, notes, word.tags)
|
|
2289
2464
|
);
|
|
2290
2465
|
wordAddNoteArray(
|
|
2291
2466
|
dictMeaning.antonyms,
|
|
@@ -2297,45 +2472,45 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2297
2472
|
);
|
|
2298
2473
|
wordAddNoteArray(
|
|
2299
2474
|
dictMeaning.info,
|
|
2300
|
-
(info) => lookupWordNote(info, notes,
|
|
2475
|
+
(info) => lookupWordNote(info, notes, word.tags)
|
|
2301
2476
|
);
|
|
2302
2477
|
wordAddNoteArray(
|
|
2303
2478
|
dictMeaning.misc,
|
|
2304
|
-
(misc) => lookupWordNote(misc, notes,
|
|
2479
|
+
(misc) => lookupWordNote(misc, notes, word.tags)
|
|
2305
2480
|
);
|
|
2306
2481
|
for (let i = 0; i < notes.length; i++)
|
|
2307
2482
|
notes[i] = capitalizeString(notes[i]);
|
|
2308
|
-
|
|
2483
|
+
word.translations.push({
|
|
2309
2484
|
translation: translations.join("; "),
|
|
2310
2485
|
notes
|
|
2311
2486
|
});
|
|
2312
2487
|
}
|
|
2313
2488
|
if (dictWord.usuallyInKana === true) {
|
|
2314
|
-
|
|
2315
|
-
|
|
2489
|
+
word.usuallyInKana = true;
|
|
2490
|
+
word.tags.push("word::usually_in_kana_for_all_senses");
|
|
2316
2491
|
}
|
|
2317
|
-
if (kanjiDic &&
|
|
2492
|
+
if (kanjiDic !== void 0 && word.kanjiForms !== void 0) {
|
|
2318
2493
|
const kanji = [];
|
|
2319
2494
|
const seenChars = /* @__PURE__ */ new Set();
|
|
2320
|
-
for (const kanjiForm of
|
|
2495
|
+
for (const kanjiForm of word.kanjiForms)
|
|
2321
2496
|
for (const char of kanjiForm.kanjiForm.split("").filter((c) => regexps.kanji.test(c))) {
|
|
2322
2497
|
if (seenChars.has(char)) continue;
|
|
2323
2498
|
seenChars.add(char);
|
|
2324
2499
|
const kanjiEntry = kanjiDic instanceof Map ? kanjiDic.get(char) : void 0;
|
|
2325
2500
|
const kanjiObj = getKanji(
|
|
2326
2501
|
kanjiEntry ?? char,
|
|
2327
|
-
|
|
2502
|
+
!(kanjiDic instanceof Map) ? kanjiDic : void 0
|
|
2328
2503
|
);
|
|
2329
|
-
if (kanjiObj)
|
|
2504
|
+
if (kanjiObj !== void 0)
|
|
2330
2505
|
kanji.push({
|
|
2331
2506
|
kanji: kanjiObj.kanji,
|
|
2332
|
-
...kanjiObj.meanings && kanjiObj.meanings.length > 0 ? { meanings: kanjiObj.meanings } : {}
|
|
2507
|
+
...kanjiObj.meanings !== void 0 && kanjiObj.meanings.length > 0 ? { meanings: kanjiObj.meanings } : {}
|
|
2333
2508
|
});
|
|
2334
2509
|
}
|
|
2335
|
-
if (kanji.length > 0)
|
|
2510
|
+
if (kanji.length > 0) word.kanji = kanji;
|
|
2336
2511
|
}
|
|
2337
|
-
if (dictWord.hasPhrases !== void 0
|
|
2338
|
-
const exampleList =
|
|
2512
|
+
if (dictWord.hasPhrases === true && examples !== void 0) {
|
|
2513
|
+
const exampleList = examples instanceof Map ? examples.get(dictWord.id) ?? [] : examples;
|
|
2339
2514
|
const rkf = getValidForms(
|
|
2340
2515
|
dictWord.readings,
|
|
2341
2516
|
dictWord.kanjiForms,
|
|
@@ -2344,7 +2519,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2344
2519
|
const readings = new Set(
|
|
2345
2520
|
rkf.readings.map((r) => r.reading)
|
|
2346
2521
|
);
|
|
2347
|
-
const kanjiForms = rkf.kanjiForms ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
|
|
2522
|
+
const kanjiForms = rkf.kanjiForms !== void 0 ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
|
|
2348
2523
|
let kanjiFormExamples = [];
|
|
2349
2524
|
const readingMatchingKanjiFormExamples = [];
|
|
2350
2525
|
const readingExamples = [];
|
|
@@ -2355,7 +2530,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2355
2530
|
const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
|
|
2356
2531
|
const readingAsInflectedFormMatch = part.inflectedForm !== void 0 && readings.has(part.inflectedForm);
|
|
2357
2532
|
const referenceIDMatch = part.referenceID === dictWord.id;
|
|
2358
|
-
if (kanjiForms && kanjiForms.has(part.baseForm) || referenceIDMatch) {
|
|
2533
|
+
if (kanjiForms !== void 0 && kanjiForms.has(part.baseForm) || referenceIDMatch) {
|
|
2359
2534
|
if (readingAsReadingMatch || readingAsInflectedFormMatch) {
|
|
2360
2535
|
readingMatchingKanjiFormExamples.push({
|
|
2361
2536
|
ex: example,
|
|
@@ -2371,30 +2546,33 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2371
2546
|
break;
|
|
2372
2547
|
}
|
|
2373
2548
|
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
2374
|
-
if (
|
|
2549
|
+
if (readingAsBaseFormMatch && kanjiForms === void 0) {
|
|
2375
2550
|
readingExamples.push({ ex: example, partIndex: i });
|
|
2376
2551
|
break;
|
|
2377
2552
|
}
|
|
2378
2553
|
}
|
|
2379
2554
|
if (readingMatchingKanjiForms.size > 0)
|
|
2380
2555
|
kanjiFormExamples = kanjiFormExamples.filter(
|
|
2381
|
-
(ex) => ex.form && readingMatchingKanjiForms.has(ex.form)
|
|
2556
|
+
(ex) => ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
|
|
2382
2557
|
);
|
|
2383
|
-
const includeKanjiFormExamples =
|
|
2558
|
+
const includeKanjiFormExamples = word.kanjiForms !== void 0;
|
|
2384
2559
|
let wordExamples = [
|
|
2385
2560
|
...includeKanjiFormExamples ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : readingExamples
|
|
2386
2561
|
];
|
|
2562
|
+
wordExamples.sort(
|
|
2563
|
+
(a, b) => a.ex.phrase.length - b.ex.phrase.length
|
|
2564
|
+
);
|
|
2387
2565
|
readingMatchingKanjiForms.clear();
|
|
2388
2566
|
const glossSpecificExamples = [];
|
|
2389
2567
|
const seenPhrases = /* @__PURE__ */ new Set();
|
|
2390
|
-
for (let i = 0; i <
|
|
2568
|
+
for (let i = 0; i < word.translations.length; i++)
|
|
2391
2569
|
outer: for (const example of wordExamples) {
|
|
2392
2570
|
if (seenPhrases.has(example.ex.phrase)) continue;
|
|
2393
2571
|
for (let j = 0; j < example.ex.parts.length; j++) {
|
|
2394
2572
|
const part = example.ex.parts[j];
|
|
2395
2573
|
if (j === example.partIndex && part.glossNumber === i + 1) {
|
|
2396
2574
|
example.ex.glossNumber = {
|
|
2397
|
-
wordId:
|
|
2575
|
+
wordId: word.id,
|
|
2398
2576
|
glossNumber: i + 1
|
|
2399
2577
|
};
|
|
2400
2578
|
glossSpecificExamples.push(example);
|
|
@@ -2403,213 +2581,69 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2403
2581
|
}
|
|
2404
2582
|
}
|
|
2405
2583
|
}
|
|
2406
|
-
}
|
|
2407
2584
|
if (glossSpecificExamples.length > 0) {
|
|
2408
|
-
|
|
2409
|
-
if (exes.length < 5) {
|
|
2585
|
+
if (glossSpecificExamples.length < 5) {
|
|
2410
2586
|
wordExamples = wordExamples.filter(
|
|
2411
2587
|
(ex) => !seenPhrases.has(ex.ex.phrase)
|
|
2412
2588
|
);
|
|
2413
2589
|
if (wordExamples.length > 0)
|
|
2414
2590
|
for (const ex of wordExamples) {
|
|
2415
|
-
|
|
2416
|
-
if (
|
|
2591
|
+
glossSpecificExamples.push(ex);
|
|
2592
|
+
if (glossSpecificExamples.length === 5) break;
|
|
2417
2593
|
}
|
|
2418
2594
|
}
|
|
2419
|
-
wordExamples =
|
|
2595
|
+
wordExamples = glossSpecificExamples;
|
|
2420
2596
|
}
|
|
2421
2597
|
if (wordExamples.length > 0) {
|
|
2422
|
-
|
|
2598
|
+
word.phrases = (glossSpecificExamples.length === 0 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => ({
|
|
2423
2599
|
phrase: ex.ex.furigana ?? ex.ex.phrase,
|
|
2424
2600
|
translation: ex.ex.translation,
|
|
2425
2601
|
originalPhrase: ex.ex.phrase,
|
|
2426
|
-
...ex.ex.glossNumber ? { glossNumber: ex.ex.glossNumber } : {}
|
|
2602
|
+
...ex.ex.glossNumber !== void 0 ? { glossNumber: ex.ex.glossNumber } : {}
|
|
2427
2603
|
}));
|
|
2428
|
-
|
|
2604
|
+
word.tags.push("word::has_phrases");
|
|
2429
2605
|
if (glossSpecificExamples.length > 0)
|
|
2430
|
-
|
|
2606
|
+
word.tags.push("word::has_meaning-specific_phrases");
|
|
2431
2607
|
}
|
|
2432
2608
|
}
|
|
2433
|
-
if (definitions) {
|
|
2434
|
-
const defs =
|
|
2435
|
-
|
|
2609
|
+
if (definitions !== void 0) {
|
|
2610
|
+
const defs = definitions instanceof Map ? definitions.get(word.id) : (_a = definitions.find(
|
|
2611
|
+
(wdp) => wdp.wordID === word.id
|
|
2612
|
+
)) == null ? void 0 : _a.definitions;
|
|
2613
|
+
if (defs !== void 0)
|
|
2614
|
+
word.definitions = [
|
|
2615
|
+
...defs.toSorted(
|
|
2616
|
+
(a, b) => (a.mayNotBeAccurate ?? 0) - (b.mayNotBeAccurate ?? 0)
|
|
2617
|
+
)
|
|
2618
|
+
];
|
|
2436
2619
|
}
|
|
2437
|
-
return
|
|
2438
|
-
} else return void 0;
|
|
2439
|
-
}
|
|
2440
|
-
function getKanji(kanji, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
2441
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2442
|
-
let dictKanji = void 0;
|
|
2443
|
-
if (typeof kanji === "string" && dict)
|
|
2444
|
-
dictKanji = Array.isArray(dict) ? dict.find((entry) => entry.kanji === kanji) : dict.get(kanji);
|
|
2445
|
-
else if (typeof kanji === "object") dictKanji = kanji;
|
|
2446
|
-
if (dictKanji) {
|
|
2447
|
-
const kanji2 = {
|
|
2448
|
-
kanji: dictKanji.kanji,
|
|
2449
|
-
strokes: dictKanji.misc.strokeNumber,
|
|
2450
|
-
...dictKanji.misc && dictKanji.misc.grade ? { grade: dictKanji.misc.grade } : {},
|
|
2451
|
-
...dictKanji.misc && dictKanji.misc.frequency ? { frequency: dictKanji.misc.frequency } : {},
|
|
2452
|
-
...dictKanji.misc && dictKanji.misc.jlpt ? { jlpt: dictKanji.misc.jlpt } : {},
|
|
2453
|
-
noteID: `kanji_${dictKanji.kanji}`,
|
|
2454
|
-
...noteTypeName ? { noteTypeName } : {},
|
|
2455
|
-
...deckPath ? { deckPath } : {},
|
|
2456
|
-
tags: []
|
|
2457
|
-
};
|
|
2458
|
-
if (dictKanji.readingMeaning && dictKanji.readingMeaning.length > 0) {
|
|
2459
|
-
const meanings = [];
|
|
2460
|
-
const nanori = [];
|
|
2461
|
-
const onyomi = [];
|
|
2462
|
-
const kunyomi = [];
|
|
2463
|
-
for (const rm of dictKanji.readingMeaning) {
|
|
2464
|
-
if (rm.nanori && rm.nanori.length > 0) nanori.push(...rm.nanori);
|
|
2465
|
-
for (const group of rm.groups) {
|
|
2466
|
-
if (group.readings) {
|
|
2467
|
-
onyomi.push(
|
|
2468
|
-
...group.readings.filter((reading) => reading.type === "ja_on").map((reading) => reading.reading)
|
|
2469
|
-
);
|
|
2470
|
-
kunyomi.push(
|
|
2471
|
-
...group.readings.filter(
|
|
2472
|
-
(reading) => reading.type === "ja_kun"
|
|
2473
|
-
).map((reading) => reading.reading)
|
|
2474
|
-
);
|
|
2475
|
-
}
|
|
2476
|
-
if (group.meanings && group.meanings.length > 0)
|
|
2477
|
-
meanings.push(...group.meanings);
|
|
2478
|
-
}
|
|
2479
|
-
}
|
|
2480
|
-
if (meanings.length > 0) kanji2.meanings = meanings;
|
|
2481
|
-
if (nanori.length > 0) kanji2.nanori = nanori;
|
|
2482
|
-
if (onyomi.length > 0) kanji2.onyomi = onyomi;
|
|
2483
|
-
if (kunyomi.length > 0) kanji2.kunyomi = kunyomi;
|
|
2484
|
-
}
|
|
2485
|
-
if (jmDict) {
|
|
2486
|
-
let kanjiWords = Array.isArray(
|
|
2487
|
-
jmDict
|
|
2488
|
-
) ? jmDict : jmDict.get(kanji2.kanji);
|
|
2489
|
-
const firstKfWords = kanjiWords == null ? void 0 : kanjiWords.filter(
|
|
2490
|
-
(word) => word.kanjiForms && word.kanjiForms[0].form.includes(kanji2.kanji)
|
|
2491
|
-
);
|
|
2492
|
-
if (firstKfWords && firstKfWords.length > 0) kanjiWords = firstKfWords;
|
|
2493
|
-
if (kanjiWords) {
|
|
2494
|
-
const validWords = [];
|
|
2495
|
-
for (const word of kanjiWords) {
|
|
2496
|
-
const kanjiForm = (_a = firstKfWords && firstKfWords.length > 0 ? word.kanjiForms[0] : word.kanjiForms.find(
|
|
2497
|
-
(kf) => kf.form.includes(kanji2.kanji)
|
|
2498
|
-
)) == null ? void 0 : _a.form;
|
|
2499
|
-
if (kanjiForm) {
|
|
2500
|
-
const reading = (_b = firstKfWords && firstKfWords.length > 0 ? word.readings[0] : word.readings.find(
|
|
2501
|
-
(reading2) => reading2.kanjiFormRestrictions && reading2.kanjiFormRestrictions.includes(kanjiForm)
|
|
2502
|
-
)) == null ? void 0 : _b.reading;
|
|
2503
|
-
if (!reading) continue;
|
|
2504
|
-
const translation = (_c = firstKfWords && firstKfWords.length > 0 ? word.meanings[0] : word.meanings.find(
|
|
2505
|
-
(m) => m.translations && m.kanjiFormRestrictions && m.kanjiFormRestrictions.includes(kanjiForm)
|
|
2506
|
-
)) == null ? void 0 : _c.translations.map(
|
|
2507
|
-
(t) => typeof t === "string" ? t : t.translation
|
|
2508
|
-
)[0];
|
|
2509
|
-
if (!translation) continue;
|
|
2510
|
-
validWords.push({
|
|
2511
|
-
kanjiForms: [{ kanjiForm }],
|
|
2512
|
-
readings: [{ reading }],
|
|
2513
|
-
translations: [
|
|
2514
|
-
{
|
|
2515
|
-
translation
|
|
2516
|
-
}
|
|
2517
|
-
]
|
|
2518
|
-
});
|
|
2519
|
-
}
|
|
2520
|
-
if (validWords.length === 3) break;
|
|
2521
|
-
}
|
|
2522
|
-
if (validWords.length > 0) kanji2.words = validWords;
|
|
2523
|
-
}
|
|
2524
|
-
}
|
|
2525
|
-
if (svgList) {
|
|
2526
|
-
const codePoint = kanji2.kanji.codePointAt(0).toString(16).toLowerCase();
|
|
2527
|
-
const svg = Array.isArray(svgList) ? svgList.find(
|
|
2528
|
-
(svgFile) => [`${codePoint}.svg`, `0${codePoint}.svg`].includes(
|
|
2529
|
-
svgFile.toLowerCase()
|
|
2530
|
-
)
|
|
2531
|
-
) : svgList.get(kanji2.kanji);
|
|
2532
|
-
if (svg) kanji2.svg = svg;
|
|
2533
|
-
}
|
|
2534
|
-
if (kanji2.tags && dictKanji.isKokuji === true) {
|
|
2535
|
-
kanji2.kokuji = true;
|
|
2536
|
-
kanji2.tags.push("kanji::kokuji");
|
|
2537
|
-
}
|
|
2538
|
-
kanji2.tags.push(
|
|
2539
|
-
`kanji::strokes::${kanji2.strokes}`,
|
|
2540
|
-
...kanji2.frequency ? [`kanji::frequency::${kanji2.frequency}`] : [],
|
|
2541
|
-
...kanji2.grade ? [`kanji::grade::${kanji2.grade}`] : [],
|
|
2542
|
-
...kanji2.jlpt ? [`kanji::pre-2010_jlpt::${kanji2.jlpt.toLowerCase()}`] : [],
|
|
2543
|
-
`kanji::onyomi::${((_d = kanji2.onyomi) == null ? void 0 : _d.length) ?? 0}`,
|
|
2544
|
-
`kanji::kunyomi::${((_e = kanji2.kunyomi) == null ? void 0 : _e.length) ?? 0}`,
|
|
2545
|
-
`kanji::nanori::${((_f = kanji2.nanori) == null ? void 0 : _f.length) ?? 0}`,
|
|
2546
|
-
`kanji::words::${((_g = kanji2.words) == null ? void 0 : _g.length) ?? 0}`,
|
|
2547
|
-
...kanji2.svg ? ["kanji::has_svg"] : []
|
|
2548
|
-
);
|
|
2549
|
-
return kanji2;
|
|
2550
|
-
} else return void 0;
|
|
2551
|
-
}
|
|
2552
|
-
function getKanjiExtended(info, kanji, dict, useWords, jmDict, svgList, noteTypeName, deckPath, sourceURL) {
|
|
2553
|
-
const kanjiObj = getKanji(
|
|
2554
|
-
kanji,
|
|
2555
|
-
dict,
|
|
2556
|
-
jmDict,
|
|
2557
|
-
svgList,
|
|
2558
|
-
noteTypeName,
|
|
2559
|
-
deckPath
|
|
2560
|
-
);
|
|
2561
|
-
if (kanjiObj) {
|
|
2562
|
-
let usedInfo = false;
|
|
2563
|
-
if (info.components) {
|
|
2564
|
-
kanjiObj.components = info.components;
|
|
2565
|
-
usedInfo = true;
|
|
2566
|
-
}
|
|
2567
|
-
if (info.mnemonic && info.mnemonic.length > 0) {
|
|
2568
|
-
kanjiObj.mnemonic = info.mnemonic;
|
|
2569
|
-
usedInfo = true;
|
|
2570
|
-
}
|
|
2571
|
-
if (useWords === true && info.words && info.words.length > 0) {
|
|
2572
|
-
kanjiObj.words = info.words;
|
|
2573
|
-
usedInfo = true;
|
|
2574
|
-
}
|
|
2575
|
-
if (kanjiObj.components)
|
|
2576
|
-
kanjiObj.tags.push(`kanji::components::${kanjiObj.components.length}`);
|
|
2577
|
-
if (kanjiObj.mnemonic && kanjiObj.mnemonic.length > 0)
|
|
2578
|
-
kanjiObj.tags.push("kanji::has_mnemonic");
|
|
2579
|
-
if (useWords === true && kanjiObj.words && info.words)
|
|
2580
|
-
kanjiObj.tags.forEach((tag, index) => {
|
|
2581
|
-
if (tag.startsWith("kanji::words::") && kanjiObj.words) {
|
|
2582
|
-
kanjiObj.tags.splice(
|
|
2583
|
-
index,
|
|
2584
|
-
1,
|
|
2585
|
-
`kanji::words::${kanjiObj.words.length}`
|
|
2586
|
-
);
|
|
2587
|
-
}
|
|
2588
|
-
});
|
|
2589
|
-
if (sourceURL && info.externalInfo === true && usedInfo)
|
|
2590
|
-
kanjiObj.source = sourceURL;
|
|
2591
|
-
return kanjiObj;
|
|
2620
|
+
return word;
|
|
2592
2621
|
} else return void 0;
|
|
2593
2622
|
}
|
|
2594
2623
|
function isWord(entry) {
|
|
2595
|
-
|
|
2624
|
+
var _a, _b;
|
|
2625
|
+
return isObjectArray((_a = Object.getOwnPropertyDescriptor(entry, "readings")) == null ? void 0 : _a.value) && isObjectArray((_b = Object.getOwnPropertyDescriptor(entry, "translations")) == null ? void 0 : _b.value);
|
|
2596
2626
|
}
|
|
2597
2627
|
function isRadical(entry) {
|
|
2598
|
-
|
|
2628
|
+
var _a;
|
|
2629
|
+
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "radical")) == null ? void 0 : _a.value) === "string";
|
|
2599
2630
|
}
|
|
2600
2631
|
function isKanji(entry) {
|
|
2601
|
-
|
|
2632
|
+
var _a;
|
|
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";
|
|
2602
2634
|
}
|
|
2603
2635
|
function isKana(entry) {
|
|
2604
|
-
|
|
2636
|
+
var _a;
|
|
2637
|
+
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "kana")) == null ? void 0 : _a.value) === "string";
|
|
2605
2638
|
}
|
|
2606
2639
|
function isGrammar(entry) {
|
|
2607
|
-
|
|
2640
|
+
var _a;
|
|
2641
|
+
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "point")) == null ? void 0 : _a.value) === "string";
|
|
2608
2642
|
}
|
|
2609
2643
|
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>" : ""}`;
|
|
2610
|
-
var createEntry = (entry, notes, phrase, glossSpecific) => `<div class="entry${glossSpecific ? " gloss-specific" : ""}">${entry}${notes && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
|
|
2611
|
-
var noKanjiForms = '<span class="word word-kanjiform">(no kanji forms)</span>';
|
|
2644
|
+
var createEntry = (entry, notes, phrase, glossSpecific) => `<div class="entry${glossSpecific === true ? " gloss-specific" : ""}">${entry}${notes !== void 0 && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
|
|
2612
2645
|
function generateAnkiNote(entry) {
|
|
2646
|
+
var _a, _b;
|
|
2613
2647
|
const fields = [];
|
|
2614
2648
|
if (isWord(entry)) {
|
|
2615
2649
|
const firstReading = createEntry(
|
|
@@ -2621,61 +2655,91 @@ function generateAnkiNote(entry) {
|
|
|
2621
2655
|
`<span class="word word-reading">${readingEntry.reading}${readingEntry.audio !== void 0 ? `<br>[sound:${readingEntry.audio}]` : ""}</span>`,
|
|
2622
2656
|
readingEntry.notes
|
|
2623
2657
|
)
|
|
2624
|
-
).join("")}</details>` :
|
|
2625
|
-
const readingsField =
|
|
2626
|
-
|
|
2627
|
-
);
|
|
2628
|
-
const firstKanjiForm = entry.kanjiForms ? createEntry(
|
|
2658
|
+
).join("")}</details>` : "";
|
|
2659
|
+
const readingsField = `${firstReading}${otherReadings}`;
|
|
2660
|
+
const firstKanjiForm = entry.kanjiForms !== void 0 ? createEntry(
|
|
2629
2661
|
`<span class="word word-kanjiform"><ruby><rb>${entry.kanjiForms[0].kanjiForm}</rb><rt>${entry.readings[0].reading}</rt></ruby></span>`,
|
|
2630
2662
|
entry.kanjiForms[0].notes
|
|
2631
2663
|
) : void 0;
|
|
2632
|
-
const otherKanjiForms = entry.kanjiForms && entry.kanjiForms.length > 1 ? `<details><summary>Show other kanji forms</summary>${entry.kanjiForms.slice(1).map((kanjiFormEntry) => {
|
|
2664
|
+
const otherKanjiForms = entry.kanjiForms !== void 0 && entry.kanjiForms.length > 1 ? `<details><summary>Show other kanji forms</summary>${entry.kanjiForms.slice(1).map((kanjiFormEntry) => {
|
|
2633
2665
|
const restrictedReading = entry.readings.find(
|
|
2634
|
-
(r) => r.notes && r.notes.includes(
|
|
2666
|
+
(r) => r.notes !== void 0 && r.notes.includes(
|
|
2635
2667
|
`Reading restricted to ${kanjiFormEntry.kanjiForm}`
|
|
2636
2668
|
)
|
|
2637
2669
|
);
|
|
2638
|
-
return
|
|
2639
|
-
|
|
2640
|
-
|
|
2670
|
+
return createEntry(
|
|
2671
|
+
`<span class="word word-kanjiform">${restrictedReading !== void 0 ? "<ruby><rb>" : ""}${kanjiFormEntry.kanjiForm}${restrictedReading !== void 0 ? `</rb><rt>${restrictedReading.reading}</rt></ruby>` : ""}</span>`,
|
|
2672
|
+
kanjiFormEntry.notes
|
|
2673
|
+
);
|
|
2674
|
+
}).join("")}</details>` : "";
|
|
2675
|
+
const kanjiFormsField = firstKanjiForm !== void 0 ? `${firstKanjiForm}${otherKanjiForms}` : '<span class="word word-kanjiform">(no kanji forms)</span>';
|
|
2641
2676
|
const firstThreeTranslations = entry.translations.slice(0, 3).map(
|
|
2642
|
-
(translationEntry, index) =>
|
|
2677
|
+
(translationEntry, index) => createEntry(
|
|
2678
|
+
`<span class="word word-translation">${translationEntry.translation}</span>`,
|
|
2679
|
+
translationEntry.notes,
|
|
2680
|
+
void 0,
|
|
2681
|
+
entry.phrases !== void 0 ? entry.phrases.some(
|
|
2682
|
+
(phrase, index2) => index === index2 && phrase.glossNumber !== void 0 && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1
|
|
2683
|
+
) ? true : void 0 : void 0
|
|
2684
|
+
)
|
|
2685
|
+
).join("");
|
|
2686
|
+
const otherTranslations = entry.translations.length > 3 ? `<details><summary>Show other translations</summary>${entry.translations.map((translationEntry, index) => {
|
|
2687
|
+
if (index < 3) return "null";
|
|
2688
|
+
return createEntry(
|
|
2689
|
+
`<span class="word word-translation">${translationEntry.translation}</span>`,
|
|
2690
|
+
translationEntry.notes,
|
|
2691
|
+
void 0,
|
|
2692
|
+
entry.phrases !== void 0 ? entry.phrases.some(
|
|
2693
|
+
(phrase, index2) => index === index2 && phrase.glossNumber !== void 0 && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1
|
|
2694
|
+
) ? true : void 0 : void 0
|
|
2695
|
+
);
|
|
2696
|
+
}).filter((translation) => translation !== "null").join("")}</details>` : "";
|
|
2697
|
+
const translationsField = `${firstThreeTranslations}${otherTranslations}`;
|
|
2698
|
+
const firstFivePhrases = (_a = entry.phrases) == null ? void 0 : _a.slice(0, 5).map(
|
|
2699
|
+
(phraseEntry, index) => createEntry(
|
|
2700
|
+
`<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
|
+
[phraseEntry.translation],
|
|
2702
|
+
true,
|
|
2703
|
+
entry.translations.some(
|
|
2704
|
+
(_translation, index2) => index === index2 && phraseEntry.glossNumber !== void 0 && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2705
|
+
) ? true : void 0
|
|
2706
|
+
)
|
|
2707
|
+
).join("");
|
|
2708
|
+
const otherPhrases = entry.phrases !== void 0 && entry.phrases.length > 5 ? `<details><summary>Show other phrases</summary>${entry.phrases.map((phraseEntry, index) => {
|
|
2709
|
+
if (index < 5) return "null";
|
|
2710
|
+
return createEntry(
|
|
2711
|
+
`<span class="word word-phrase"><span class="word word-phrase-original">${phraseEntry.originalPhrase}</span><span class="word word-phrase-furigana">${phraseEntry.phrase}</span></span>`,
|
|
2712
|
+
[phraseEntry.translation],
|
|
2713
|
+
true,
|
|
2714
|
+
entry.translations.some(
|
|
2715
|
+
(_translation, index2) => index === index2 && phraseEntry.glossNumber !== void 0 && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2716
|
+
) ? true : void 0
|
|
2717
|
+
);
|
|
2718
|
+
}).filter((phrase) => phrase !== "null").join("")}</details>` : "";
|
|
2719
|
+
const phrasesField = firstFivePhrases !== void 0 ? `${firstFivePhrases}${otherPhrases}` : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>';
|
|
2720
|
+
const firstThreeDefinitions = (_b = entry.definitions) == null ? void 0 : _b.slice(0, 3).map(
|
|
2721
|
+
(definitionEntry) => createEntry(
|
|
2722
|
+
`<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
|
+
)
|
|
2643
2724
|
).join("");
|
|
2644
|
-
const
|
|
2645
|
-
(
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
].join("");
|
|
2725
|
+
const otherDefinitions = entry.definitions !== void 0 && entry.definitions.length > 3 ? `<details><summary>Show other definitions</summary>${entry.definitions.map(
|
|
2726
|
+
(definitionEntry, index) => index > 2 ? createEntry(
|
|
2727
|
+
`<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>`
|
|
2728
|
+
) : "null"
|
|
2729
|
+
).filter((definition) => definition !== "null").join("")}</details>` : "";
|
|
2730
|
+
const definitionsField = firstThreeDefinitions !== void 0 ? `${firstThreeDefinitions}${otherDefinitions}` : '<span class="word word-definition">(no definitions)</span>';
|
|
2651
2731
|
fields.push(
|
|
2652
|
-
...entry.kanjiForms
|
|
2653
|
-
readingsField,
|
|
2654
|
-
entry.kanjiForms && kanjiFormsField ? kanjiFormsField : noKanjiForms
|
|
2655
|
-
],
|
|
2732
|
+
...entry.kanjiForms !== void 0 && !entry.usuallyInKana ? [kanjiFormsField, readingsField] : [readingsField, kanjiFormsField],
|
|
2656
2733
|
translationsField,
|
|
2657
|
-
|
|
2658
|
-
|
|
2659
|
-
|
|
2660
|
-
[phraseEntry.translation],
|
|
2661
|
-
true,
|
|
2662
|
-
entry.translations.some(
|
|
2663
|
-
(_translation, index2) => index === index2 && phraseEntry.glossNumber && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2664
|
-
) ? true : void 0
|
|
2665
|
-
)
|
|
2666
|
-
).join("") : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>',
|
|
2667
|
-
entry.definitions ? entry.definitions.map(
|
|
2668
|
-
(definitionEntry) => createEntry(
|
|
2669
|
-
`<span class="word word-definition${definitionEntry.mayNotBeAccurate === true ? " mnba" : ""}"><span class="word word-definition-original">${definitionEntry.definition}</span><span class="word word-definition-furigana">${definitionEntry.furigana ?? definitionEntry.definition}</span></span>`
|
|
2670
|
-
)
|
|
2671
|
-
).join("") : '<span class="word word-definition">(no definitions)</span>',
|
|
2672
|
-
entry.kanji ? entry.kanji.map(
|
|
2734
|
+
phrasesField,
|
|
2735
|
+
definitionsField,
|
|
2736
|
+
entry.kanji !== void 0 ? entry.kanji.map(
|
|
2673
2737
|
(kanjiEntry) => createEntry(
|
|
2674
2738
|
`<span class="word word-kanji">${kanjiEntry.kanji}${kanjiEntry.meanings === void 0 ? " (no meanings)" : ""}</span>`,
|
|
2675
2739
|
kanjiEntry.meanings
|
|
2676
2740
|
)
|
|
2677
2741
|
).join("") : '<span class="word word-kanji">(no kanji)</span>',
|
|
2678
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2742
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2679
2743
|
entry.tags.map(
|
|
2680
2744
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2681
2745
|
).join(" ")
|
|
@@ -2695,19 +2759,19 @@ function generateAnkiNote(entry) {
|
|
|
2695
2759
|
`<span class="radical radical-meaning">${meaningEntry}</span>`
|
|
2696
2760
|
)
|
|
2697
2761
|
).join(""),
|
|
2698
|
-
entry.mnemonic ? createEntry(
|
|
2762
|
+
entry.mnemonic !== void 0 ? createEntry(
|
|
2699
2763
|
`<span class="radical radical-mnemonic">${entry.mnemonic}</span>`
|
|
2700
2764
|
) : '<span class="radical radical-mnemonic">(no mnemonic) (Come up with your own!)</span>',
|
|
2701
|
-
entry.kanji ? entry.kanji.map(
|
|
2765
|
+
entry.kanji !== void 0 ? entry.kanji.map(
|
|
2702
2766
|
(kanji) => createEntry(
|
|
2703
|
-
`<span class="radical radical-kanji">${kanji.kanji}${kanji.meanings && kanji.meanings.length
|
|
2767
|
+
`<span class="radical radical-kanji">${kanji.kanji}${kanji.meanings !== void 0 && kanji.meanings.length > 0 ? ` - ${kanji.meanings[0]}` : ""}</span>`
|
|
2704
2768
|
)
|
|
2705
2769
|
).join("") : '<span class="radical radical-kanji">(no "used-in" kanji)</span>',
|
|
2706
|
-
entry.strokes ? createEntry(
|
|
2707
|
-
`<span class="radical radical-strokes">${entry.strokes}<br>${entry.svg ? `<img class="radical radical-stroke-order" src="${entry.svg}" alt="${entry.radical} stroke order SVG">` : "(no stroke order SVG available)"}</span>`
|
|
2770
|
+
entry.strokes !== void 0 ? createEntry(
|
|
2771
|
+
`<span class="radical radical-strokes">${entry.strokes}<br>${entry.svg !== void 0 ? `<img class="radical radical-stroke-order" src="${entry.svg}" alt="${entry.radical} stroke order SVG">` : "(no stroke order SVG available)"}</span>`
|
|
2708
2772
|
) : '<span class="radical radical-strokes">(no stroke number)</span>',
|
|
2709
|
-
entry.sources ? `<span class="radical radical-source">${entry.sources.map((source, index) => `<a href="${source}" target="_blank">Source ${index + 1}</a>`).join("<br>")}</span>` : '<span class="radical radical-source">(no sources)</span>',
|
|
2710
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2773
|
+
entry.sources !== void 0 ? `<span class="radical radical-source">${entry.sources.map((source, index) => `<a href="${source}" target="_blank">Source ${index + 1}</a>`).join("<br>")}</span>` : '<span class="radical radical-source">(no sources)</span>',
|
|
2774
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2711
2775
|
entry.tags.map(
|
|
2712
2776
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2713
2777
|
).join(" ")
|
|
@@ -2716,44 +2780,44 @@ function generateAnkiNote(entry) {
|
|
|
2716
2780
|
if (isKanji(entry))
|
|
2717
2781
|
fields.push(
|
|
2718
2782
|
createEntry(`<span class="kanji kanji-character">${entry.kanji}</span>`),
|
|
2719
|
-
entry.meanings ? entry.meanings.map(
|
|
2783
|
+
entry.meanings !== void 0 ? entry.meanings.map(
|
|
2720
2784
|
(meaningEntry) => createEntry(
|
|
2721
2785
|
`<span class="kanji kanji-meaning">${meaningEntry}</span>`
|
|
2722
2786
|
)
|
|
2723
2787
|
).join("") : '<span class="kanji kanji-meaning">(no meanings)</span>',
|
|
2724
|
-
entry.onyomi ? entry.onyomi.map(
|
|
2788
|
+
entry.onyomi !== void 0 ? entry.onyomi.map(
|
|
2725
2789
|
(onyomiEntry) => createEntry(
|
|
2726
2790
|
`<span class="kanji kanji-onyomi">${onyomiEntry}</span>`
|
|
2727
2791
|
)
|
|
2728
|
-
).join("") : `<span class="kanji kanji-onyomi">(no onyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span
|
|
2729
|
-
entry.kunyomi ? entry.kunyomi.map(
|
|
2792
|
+
).join("") : `<span class="kanji kanji-onyomi">(no onyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2793
|
+
entry.kunyomi !== void 0 ? entry.kunyomi.map(
|
|
2730
2794
|
(kunyomiEntry) => createEntry(
|
|
2731
2795
|
`<span class="kanji kanji-kunyomi">${kunyomiEntry}</span>`
|
|
2732
2796
|
)
|
|
2733
2797
|
).join("") : `<span class="kanji kanji-kunyomi">(no kunyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2734
|
-
entry.nanori ? entry.nanori.map(
|
|
2798
|
+
entry.nanori !== void 0 ? entry.nanori.map(
|
|
2735
2799
|
(nanoriEntry) => createEntry(
|
|
2736
2800
|
`<span class="kanji kanji-nanori">${nanoriEntry}</span>`
|
|
2737
2801
|
)
|
|
2738
2802
|
).join("") : '<span class="kanji kanji-nanori">(no nanori)</span>',
|
|
2739
|
-
entry.components ? entry.components.map(
|
|
2803
|
+
entry.components !== void 0 ? entry.components.map(
|
|
2740
2804
|
(componentEntry) => createEntry(
|
|
2741
|
-
`<span class="kanji kanji-component">${componentEntry.component}${componentEntry.meaning ? ` - ${componentEntry.meaning}` : ""}</span>`
|
|
2805
|
+
`<span class="kanji kanji-component">${componentEntry.component}${componentEntry.meaning !== void 0 ? ` - ${componentEntry.meaning}` : ""}</span>`
|
|
2742
2806
|
)
|
|
2743
2807
|
).join("") : '<span class="kanji kanji-component">(no components)</span>',
|
|
2744
|
-
entry.mnemonic ? createEntry(
|
|
2808
|
+
entry.mnemonic !== void 0 ? createEntry(
|
|
2745
2809
|
`<span class="kanji kanji-mnemonic">${entry.mnemonic}</span>`
|
|
2746
2810
|
) : '<span class="kanji kanji-mnemonic">(no mnemonic) (Come up with your own!)</span>',
|
|
2747
|
-
entry.words ? entry.words.map(
|
|
2811
|
+
entry.words !== void 0 ? entry.words.map(
|
|
2748
2812
|
(word) => createEntry(
|
|
2749
|
-
`<span class="kanji kanji-words">${word.kanjiForms
|
|
2813
|
+
`<span class="kanji kanji-words">${word.kanjiForms.find((kf) => kf.kanjiForm.includes(entry.kanji)).kanjiForm} / ${word.readings[0].reading} - ${word.translations[0].translation}</span>`
|
|
2750
2814
|
)
|
|
2751
2815
|
).join("") : '<span class="kanji kanji-words">(no words) (Search on dictionaries!)</span>',
|
|
2752
|
-
entry.strokes ? createEntry(
|
|
2753
|
-
`<span class="kanji kanji-strokes">${entry.strokes}<br>${entry.svg ? `<img class="kanji kanji-stroke-order" src="${entry.svg}" alt="${entry.kanji} stroke order SVG">` : "(no stroke order SVG available)"}</span>`
|
|
2816
|
+
entry.strokes !== void 0 ? createEntry(
|
|
2817
|
+
`<span class="kanji kanji-strokes">${entry.strokes}<br>${entry.svg !== void 0 ? `<img class="kanji kanji-stroke-order" src="${entry.svg}" alt="${entry.kanji} stroke order SVG">` : "(no stroke order SVG available)"}</span>`
|
|
2754
2818
|
) : '<span class="kanji kanji-strokes">(no stroke number)</span>',
|
|
2755
|
-
entry.source ? `<span class="kanji kanji-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="kanji kanji-source">(no components/mnemonic source)</span>',
|
|
2756
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2819
|
+
entry.source !== void 0 ? `<span class="kanji kanji-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="kanji kanji-source">(no components/mnemonic source)</span>',
|
|
2820
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2757
2821
|
entry.tags.map(
|
|
2758
2822
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2759
2823
|
).join(" ")
|
|
@@ -2765,10 +2829,10 @@ function generateAnkiNote(entry) {
|
|
|
2765
2829
|
createEntry(
|
|
2766
2830
|
`<span class="kana kana-reading">${entry.reading}${entry.audio !== void 0 ? `<br>[sound:${entry.audio}]` : ""}</span>`
|
|
2767
2831
|
),
|
|
2768
|
-
entry.svg ? createEntry(
|
|
2832
|
+
entry.svg !== void 0 ? createEntry(
|
|
2769
2833
|
`<img class="kana kana-stroke-order" src="${entry.svg}" alt="${entry.kana} stroke order SVG">`
|
|
2770
2834
|
) : "(no stroke order SVG available)",
|
|
2771
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2835
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2772
2836
|
entry.tags.map(
|
|
2773
2837
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2774
2838
|
).join(" ")
|
|
@@ -2777,28 +2841,28 @@ function generateAnkiNote(entry) {
|
|
|
2777
2841
|
if (isGrammar(entry))
|
|
2778
2842
|
fields.push(
|
|
2779
2843
|
createEntry(`<span class="grammar grammar-point">${entry.point}</span>`),
|
|
2780
|
-
entry.readings ? entry.readings.map(
|
|
2844
|
+
entry.readings !== void 0 ? entry.readings.map(
|
|
2781
2845
|
(readingEntry) => createEntry(
|
|
2782
2846
|
`<span class="grammar grammar-reading">${readingEntry.reading}</span>`
|
|
2783
2847
|
)
|
|
2784
2848
|
).join("") : '<span class="grammar grammar-reading">(no additional readings)</span>',
|
|
2785
2849
|
createEntry(
|
|
2786
|
-
`<span class="grammar grammar-meaning">${entry.meaning.meaning}${entry.meaning.example && entry.meaning.example.length > 0 ? `<br><span class="grammar grammar-meaning-example">${entry.meaning.example}</span>` : ""}</span>`
|
|
2850
|
+
`<span class="grammar grammar-meaning">${entry.meaning.meaning}${entry.meaning.example !== void 0 && entry.meaning.example.length > 0 ? `<br><span class="grammar grammar-meaning-example">${entry.meaning.example}</span>` : ""}</span>`
|
|
2787
2851
|
),
|
|
2788
|
-
entry.usages ? entry.usages.map(
|
|
2852
|
+
entry.usages !== void 0 ? entry.usages.map(
|
|
2789
2853
|
(usage) => createEntry(
|
|
2790
2854
|
`<span class="grammar grammar-usage">${usage}</span>`
|
|
2791
2855
|
)
|
|
2792
2856
|
).join("") : '<span class="grammar grammar-usage">(no usages)</span>',
|
|
2793
|
-
entry.phrases ? entry.phrases.map(
|
|
2857
|
+
entry.phrases !== void 0 ? entry.phrases.map(
|
|
2794
2858
|
(phraseEntry) => createEntry(
|
|
2795
2859
|
`<span class="grammar grammar-phrase"><span class="grammar grammar-phrase-original">${phraseEntry.originalPhrase}</span><span class="grammar grammar-phrase-furigana">${phraseEntry.phrase}</span></span>`,
|
|
2796
2860
|
[phraseEntry.translation],
|
|
2797
2861
|
true
|
|
2798
2862
|
)
|
|
2799
2863
|
).join("") : '<span class="grammar grammar-phrase">(no phrases) (Search on dictionaries!)</span>',
|
|
2800
|
-
entry.source ? `<span class="grammar grammar-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="grammar grammar-source">(no source)</span>',
|
|
2801
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2864
|
+
entry.source !== void 0 ? `<span class="grammar grammar-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="grammar grammar-source">(no source)</span>',
|
|
2865
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2802
2866
|
entry.tags.map(
|
|
2803
2867
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2804
2868
|
).join(" ")
|
|
@@ -2810,8 +2874,9 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2810
2874
|
const headers = [noteHeaderKeys.separator, noteHeaderKeys.html];
|
|
2811
2875
|
let ankiNotes = "";
|
|
2812
2876
|
if (list.length > 0) {
|
|
2813
|
-
|
|
2814
|
-
|
|
2877
|
+
let noteInfo = {};
|
|
2878
|
+
if (defaultNoteInfo !== void 0) noteInfo = { ...defaultNoteInfo };
|
|
2879
|
+
const infoValues = Object.values(noteInfo);
|
|
2815
2880
|
let invalidList = false;
|
|
2816
2881
|
const firstEntry = list[0];
|
|
2817
2882
|
const firstEntryInfo = {
|
|
@@ -2821,7 +2886,7 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2821
2886
|
};
|
|
2822
2887
|
if (infoValues.length === 0 || infoValues.some((value) => value === true || value === void 0)) {
|
|
2823
2888
|
for (const res of list)
|
|
2824
|
-
if (
|
|
2889
|
+
if (noteInfo.guid === true && res.noteID === void 0 || noteInfo.noteType === true && res.noteTypeName === void 0 || noteInfo.deckPath === true && res.deckPath === void 0 || noteInfo.guid === void 0 && typeof res.noteID !== firstEntryInfo.guid || noteInfo.noteType === void 0 && typeof res.noteTypeName !== firstEntryInfo.noteType || noteInfo.deckPath === void 0 && typeof res.deckPath !== firstEntryInfo.deckPath) {
|
|
2825
2890
|
invalidList = true;
|
|
2826
2891
|
break;
|
|
2827
2892
|
}
|
|
@@ -2830,26 +2895,28 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2830
2895
|
const hasHeader = { guid: false, noteType: false, deckPath: false, tags: false };
|
|
2831
2896
|
let headerCount = 0;
|
|
2832
2897
|
ankiNotes = list.filter((result) => result.doNotCreateNote === void 0).map((result) => {
|
|
2833
|
-
if (typeof
|
|
2834
|
-
if (isWord(result) && result.id
|
|
2898
|
+
if (typeof noteInfo.guid === "string" && result.noteID === void 0) {
|
|
2899
|
+
if (isWord(result) && result.id !== void 0)
|
|
2900
|
+
result.noteID = result.id;
|
|
2835
2901
|
if (isKanji(result)) result.noteID = result.kanji;
|
|
2836
2902
|
if (isRadical(result)) result.noteID = result.radical;
|
|
2837
2903
|
if (isKana(result)) result.noteID = result.kana;
|
|
2838
|
-
if (isGrammar(result) && result.id
|
|
2904
|
+
if (isGrammar(result) && result.id !== void 0)
|
|
2905
|
+
result.noteID = result.id;
|
|
2839
2906
|
}
|
|
2840
|
-
if (typeof
|
|
2841
|
-
result.noteTypeName =
|
|
2842
|
-
if (typeof
|
|
2843
|
-
result.deckPath =
|
|
2844
|
-
if (!hasHeader.guid && result.noteID) {
|
|
2907
|
+
if (typeof noteInfo.noteType === "string" && result.noteTypeName === void 0)
|
|
2908
|
+
result.noteTypeName = noteInfo.noteType;
|
|
2909
|
+
if (typeof noteInfo.deckPath === "string" && result.deckPath === void 0)
|
|
2910
|
+
result.deckPath = noteInfo.deckPath;
|
|
2911
|
+
if (!hasHeader.guid && result.noteID !== void 0) {
|
|
2845
2912
|
headers.push(`${noteHeaderKeys.guid}${++headerCount}`);
|
|
2846
2913
|
hasHeader.guid = true;
|
|
2847
2914
|
}
|
|
2848
|
-
if (!hasHeader.noteType && result.noteTypeName) {
|
|
2915
|
+
if (!hasHeader.noteType && result.noteTypeName !== void 0) {
|
|
2849
2916
|
headers.push(`${noteHeaderKeys.notetype}${++headerCount}`);
|
|
2850
2917
|
hasHeader.noteType = true;
|
|
2851
2918
|
}
|
|
2852
|
-
if (!hasHeader.deckPath && result.deckPath) {
|
|
2919
|
+
if (!hasHeader.deckPath && result.deckPath !== void 0) {
|
|
2853
2920
|
headers.push(`${noteHeaderKeys.deck}${++headerCount}`);
|
|
2854
2921
|
hasHeader.deckPath = true;
|
|
2855
2922
|
}
|
|
@@ -2858,7 +2925,7 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2858
2925
|
headers.push(`${noteHeaderKeys.tags}${note.length + headerCount}`);
|
|
2859
2926
|
hasHeader.tags = true;
|
|
2860
2927
|
}
|
|
2861
|
-
return `${result.noteID ? `${result.noteID} ` : ""}${result.noteTypeName ? `${result.noteTypeName} ` : ""}${result.deckPath ? `${result.deckPath} ` : ""}${note.join(" ")}`;
|
|
2928
|
+
return `${result.noteID !== void 0 ? `${result.noteID} ` : ""}${result.noteTypeName !== void 0 ? `${result.noteTypeName} ` : ""}${result.deckPath !== void 0 ? `${result.deckPath} ` : ""}${note.join(" ")}`;
|
|
2862
2929
|
}).join("\n").trim();
|
|
2863
2930
|
}
|
|
2864
2931
|
return `${headers.join("\n")}
|
|
@@ -2884,6 +2951,7 @@ export {
|
|
|
2884
2951
|
getWord,
|
|
2885
2952
|
getWordDefinitions,
|
|
2886
2953
|
getWordDefinitionsWithFurigana,
|
|
2954
|
+
hiraganaToKatakana,
|
|
2887
2955
|
isGrammar,
|
|
2888
2956
|
isKana,
|
|
2889
2957
|
isKanji,
|
|
@@ -2892,9 +2960,11 @@ export {
|
|
|
2892
2960
|
isStringArray,
|
|
2893
2961
|
isValidArrayWithFirstElement,
|
|
2894
2962
|
isWord,
|
|
2963
|
+
katakanaToHiragana,
|
|
2895
2964
|
notSearchedForms,
|
|
2896
2965
|
noteHeaderKeys,
|
|
2897
2966
|
noteMap,
|
|
2967
|
+
posList,
|
|
2898
2968
|
regexps,
|
|
2899
2969
|
shuffleArray
|
|
2900
2970
|
};
|