henkan 2.2.5 → 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 +587 -571
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +581 -571
- 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 +16 -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 +4 -4
- 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,30 +1655,29 @@ 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,
|
|
@@ -1623,7 +1688,7 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1623
1688
|
entryParts.add(reading.reading);
|
|
1624
1689
|
localPartParts.add(reading.reading);
|
|
1625
1690
|
}
|
|
1626
|
-
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1691
|
+
if (rkf.kanjiForms !== void 0 && rkf.kanjiForms.length > 0)
|
|
1627
1692
|
for (const kanjiForm of rkf.kanjiForms) {
|
|
1628
1693
|
entryParts.add(kanjiForm.form);
|
|
1629
1694
|
localPartParts.add(kanjiForm.form);
|
|
@@ -1633,58 +1698,56 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1633
1698
|
wordPartsMap.set(word.id, localPartParts);
|
|
1634
1699
|
}
|
|
1635
1700
|
}
|
|
1636
|
-
if (tanakaExamples) {
|
|
1637
|
-
for (const ex of tanakaExamples)
|
|
1701
|
+
if (tanakaExamples !== void 0) {
|
|
1702
|
+
for (const ex of tanakaExamples)
|
|
1638
1703
|
for (const part of ex.parts) {
|
|
1639
1704
|
if (entryParts.has(part.baseForm)) {
|
|
1640
1705
|
let exList = partExamplesMap.get(
|
|
1641
1706
|
part.baseForm
|
|
1642
1707
|
);
|
|
1643
|
-
if (
|
|
1708
|
+
if (exList === void 0) {
|
|
1644
1709
|
exList = [];
|
|
1645
1710
|
partExamplesMap.set(part.baseForm, exList);
|
|
1646
1711
|
}
|
|
1647
1712
|
exList.push(ex);
|
|
1648
1713
|
}
|
|
1649
|
-
if (part.reading && entryParts.has(part.reading)) {
|
|
1714
|
+
if (part.reading !== void 0 && entryParts.has(part.reading)) {
|
|
1650
1715
|
let exList = partExamplesMap.get(
|
|
1651
1716
|
part.reading
|
|
1652
1717
|
);
|
|
1653
|
-
if (
|
|
1718
|
+
if (exList === void 0) {
|
|
1654
1719
|
exList = [];
|
|
1655
1720
|
partExamplesMap.set(part.reading, exList);
|
|
1656
1721
|
}
|
|
1657
1722
|
exList.push(ex);
|
|
1658
1723
|
}
|
|
1659
|
-
if (part.inflectedForm && entryParts.has(part.inflectedForm)) {
|
|
1724
|
+
if (part.inflectedForm !== void 0 && entryParts.has(part.inflectedForm)) {
|
|
1660
1725
|
let exList = partExamplesMap.get(
|
|
1661
1726
|
part.inflectedForm
|
|
1662
1727
|
);
|
|
1663
|
-
if (
|
|
1728
|
+
if (exList === void 0) {
|
|
1664
1729
|
exList = [];
|
|
1665
1730
|
partExamplesMap.set(part.inflectedForm, exList);
|
|
1666
1731
|
}
|
|
1667
1732
|
exList.push(ex);
|
|
1668
1733
|
}
|
|
1669
|
-
if (part.referenceID && entryParts.has(part.referenceID)) {
|
|
1734
|
+
if (part.referenceID !== void 0 && entryParts.has(part.referenceID)) {
|
|
1670
1735
|
let exList = partExamplesMap.get(
|
|
1671
1736
|
part.referenceID
|
|
1672
1737
|
);
|
|
1673
|
-
if (
|
|
1738
|
+
if (exList === void 0) {
|
|
1674
1739
|
exList = [];
|
|
1675
1740
|
partExamplesMap.set(part.referenceID, exList);
|
|
1676
1741
|
}
|
|
1677
1742
|
exList.push(ex);
|
|
1678
1743
|
}
|
|
1679
1744
|
}
|
|
1680
|
-
}
|
|
1681
1745
|
for (const word of jmDict) {
|
|
1682
|
-
const entryParts2 = wordPartsMap.get(word.id);
|
|
1683
1746
|
const seenEx = /* @__PURE__ */ new Set();
|
|
1684
1747
|
const validExamples = [];
|
|
1685
|
-
for (const p of
|
|
1748
|
+
for (const p of wordPartsMap.get(word.id)) {
|
|
1686
1749
|
const examplesForPart = (_a = partExamplesMap.get(p)) == null ? void 0 : _a.filter((ex) => !seenEx.has(ex.id));
|
|
1687
|
-
if (
|
|
1750
|
+
if (examplesForPart === void 0) continue;
|
|
1688
1751
|
for (const ex of examplesForPart) {
|
|
1689
1752
|
seenEx.add(ex.id);
|
|
1690
1753
|
validExamples.push(ex);
|
|
@@ -1709,49 +1772,44 @@ function mapEntry(entry) {
|
|
|
1709
1772
|
word: entry.word,
|
|
1710
1773
|
pos_title: entry.pos_title,
|
|
1711
1774
|
senses: entry.senses.filter(
|
|
1712
|
-
(sense) => isObjectArray(sense.form_of)
|
|
1713
|
-
(form) => form.word && typeof form.word === "string"
|
|
1714
|
-
) || 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)
|
|
1715
1776
|
).map((sense) => ({
|
|
1716
|
-
...sense.form_of ? {
|
|
1717
|
-
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))
|
|
1718
1779
|
} : {},
|
|
1719
1780
|
glosses: sense.glosses
|
|
1720
1781
|
})),
|
|
1721
|
-
...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)) } : {}
|
|
1722
1783
|
};
|
|
1723
1784
|
}
|
|
1724
1785
|
function convertJawiktionarySync(buffer) {
|
|
1786
|
+
var _a;
|
|
1725
1787
|
const lines = buffer.toString("utf-8").split("\n");
|
|
1726
1788
|
const entries = [];
|
|
1727
1789
|
for (let i = 0; i < lines.length; i++) {
|
|
1728
|
-
const line = lines[i];
|
|
1729
|
-
if (
|
|
1790
|
+
const line = (_a = lines[i]) == null ? void 0 : _a.trim();
|
|
1791
|
+
if (line === void 0 || line.length === 0) continue;
|
|
1730
1792
|
const obj = JSON.parse(line);
|
|
1731
|
-
if (
|
|
1793
|
+
if (typeof obj === "object" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
1732
1794
|
entries.push(mapEntry(obj));
|
|
1733
1795
|
}
|
|
1734
1796
|
return entries;
|
|
1735
1797
|
}
|
|
1736
1798
|
async function convertJawiktionaryAsync(stream) {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
stream.destroy();
|
|
1752
|
-
resolve(entries);
|
|
1753
|
-
}
|
|
1754
|
-
);
|
|
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;
|
|
1755
1813
|
}
|
|
1756
1814
|
function parseEntry(entry, definitions, definitionMap) {
|
|
1757
1815
|
for (const sense of entry.senses) {
|
|
@@ -1764,12 +1822,12 @@ function parseEntry(entry, definitions, definitionMap) {
|
|
|
1764
1822
|
}
|
|
1765
1823
|
}
|
|
1766
1824
|
}
|
|
1767
|
-
function getWordDefinitions(
|
|
1825
|
+
function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
1768
1826
|
var _a, _b, _c, _d, _e;
|
|
1769
1827
|
const entries = /* @__PURE__ */ new Map();
|
|
1770
|
-
for (const entry of
|
|
1828
|
+
for (const entry of wiktionaryEntries) {
|
|
1771
1829
|
const ent = entries.get(entry.word);
|
|
1772
|
-
if (ent) ent.push(entry);
|
|
1830
|
+
if (ent !== void 0) ent.push(entry);
|
|
1773
1831
|
else entries.set(entry.word, [entry]);
|
|
1774
1832
|
}
|
|
1775
1833
|
const japaneseDefinitions = [];
|
|
@@ -1783,15 +1841,14 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1783
1841
|
const wordKanjiForms = /* @__PURE__ */ new Set();
|
|
1784
1842
|
const rkf = getValidForms(
|
|
1785
1843
|
word.readings,
|
|
1786
|
-
word.kanjiForms
|
|
1787
|
-
word.isCommon
|
|
1844
|
+
word.kanjiForms
|
|
1788
1845
|
);
|
|
1789
1846
|
for (const r of rkf.readings) {
|
|
1790
1847
|
validReadings.add(r.reading);
|
|
1791
1848
|
wordReadings.add(r.reading);
|
|
1792
1849
|
validForms.add(r.reading);
|
|
1793
1850
|
}
|
|
1794
|
-
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1851
|
+
if (rkf.kanjiForms !== void 0 && rkf.kanjiForms.length > 0)
|
|
1795
1852
|
for (const kf of rkf.kanjiForms) {
|
|
1796
1853
|
validKanjiForms.add(kf.form);
|
|
1797
1854
|
wordKanjiForms.add(kf.form);
|
|
@@ -1811,24 +1868,22 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1811
1868
|
const ents = Array.from(entries.values()).flat();
|
|
1812
1869
|
for (const entry of ents) {
|
|
1813
1870
|
let valid = false;
|
|
1814
|
-
if (validKanjiForms
|
|
1871
|
+
if (validKanjiForms.has(entry.word)) {
|
|
1815
1872
|
valid = true;
|
|
1816
1873
|
for (const sense of entry.senses) {
|
|
1817
|
-
if (sense.form_of && sense.form_of.some((form) => validForms.has(form)))
|
|
1874
|
+
if (sense.form_of !== void 0 && sense.form_of.some((form) => validForms.has(form)))
|
|
1818
1875
|
validFormOfEntries.add(entry.word);
|
|
1819
1876
|
for (const gloss of sense.glosses) {
|
|
1820
1877
|
let hasForm = false;
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1878
|
+
for (const r of validForms)
|
|
1879
|
+
if (gloss.includes(r)) {
|
|
1880
|
+
hasForm = true;
|
|
1881
|
+
break;
|
|
1882
|
+
}
|
|
1828
1883
|
if (hasForm) validGlossesEntries.add(entry.word);
|
|
1829
1884
|
}
|
|
1830
1885
|
}
|
|
1831
|
-
if (entry.forms) {
|
|
1886
|
+
if (entry.forms !== void 0) {
|
|
1832
1887
|
for (const form of entry.forms)
|
|
1833
1888
|
if (validForms.has(form)) validFormsEntries.add(entry.word);
|
|
1834
1889
|
}
|
|
@@ -1836,17 +1891,19 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1836
1891
|
if (validForms.has(entry.word)) {
|
|
1837
1892
|
valid = true;
|
|
1838
1893
|
const ftEntry = entriesWithFormTitlesGlobal.get(entry.word);
|
|
1839
|
-
if (ftEntry) ftEntry.push(entry);
|
|
1894
|
+
if (ftEntry !== void 0) ftEntry.push(entry);
|
|
1840
1895
|
else entriesWithFormTitlesGlobal.set(entry.word, [entry]);
|
|
1841
1896
|
}
|
|
1842
1897
|
if (valid) {
|
|
1843
|
-
const tEntry = validTitleEntries.get(
|
|
1844
|
-
|
|
1898
|
+
const tEntry = validTitleEntries.get(
|
|
1899
|
+
entry.word
|
|
1900
|
+
);
|
|
1901
|
+
if (tEntry !== void 0) tEntry.push(entry);
|
|
1845
1902
|
else validTitleEntries.set(entry.word, [entry]);
|
|
1846
1903
|
}
|
|
1847
|
-
if (entry.forms && validForms.has(entry.word) && entry.forms.some((form) => validForms.has(form))) {
|
|
1904
|
+
if (entry.forms !== void 0 && validForms.has(entry.word) && entry.forms.some((form) => validForms.has(form))) {
|
|
1848
1905
|
const wfEntry = entriesWithFormsGlobal.get(entry.word);
|
|
1849
|
-
if (wfEntry) wfEntry.push(entry);
|
|
1906
|
+
if (wfEntry !== void 0) wfEntry.push(entry);
|
|
1850
1907
|
else entriesWithFormsGlobal.set(entry.word, [entry]);
|
|
1851
1908
|
}
|
|
1852
1909
|
}
|
|
@@ -1861,53 +1918,17 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1861
1918
|
const wfe = Array.from(
|
|
1862
1919
|
entriesWithFormsGlobal.values()
|
|
1863
1920
|
).flat();
|
|
1864
|
-
for (const pos of
|
|
1865
|
-
"\u540D\u8A5E",
|
|
1866
|
-
"\u52D5\u8A5E",
|
|
1867
|
-
"\u6210\u53E5",
|
|
1868
|
-
"\u526F\u8A5E",
|
|
1869
|
-
"\u5F62\u5BB9\u52D5\u8A5E",
|
|
1870
|
-
"\u52A9\u8A5E",
|
|
1871
|
-
"\u611F\u52D5\u8A5E",
|
|
1872
|
-
"\u4EE3\u540D\u8A5E",
|
|
1873
|
-
"\u63A5\u5C3E\u8F9E",
|
|
1874
|
-
"\u63A5\u982D\u8A9E",
|
|
1875
|
-
"\u9020\u8A9E\u6210\u5206",
|
|
1876
|
-
"\u7565\u8A9E",
|
|
1877
|
-
"\u56FA\u6709\u540D\u8A5E",
|
|
1878
|
-
"\u4EBA\u79F0\u4EE3\u540D\u8A5E",
|
|
1879
|
-
"\u63A5\u982D\u8F9E",
|
|
1880
|
-
"\u63A5\u7D9A\u52A9\u8A5E",
|
|
1881
|
-
"\u9593\u6295\u8A5E",
|
|
1882
|
-
"\u52A9\u52D5\u8A5E",
|
|
1883
|
-
"\u5F62\u5BB9\u8A5E",
|
|
1884
|
-
"\u7E2E\u7D04\u5F62",
|
|
1885
|
-
"\u63A5\u8F9E",
|
|
1886
|
-
"\u63A5\u7D9A\u8A5E",
|
|
1887
|
-
"\u9023\u4F53\u8A5E",
|
|
1888
|
-
"\u4EBA\u540D",
|
|
1889
|
-
"\u8A18\u53F7",
|
|
1890
|
-
"\u6570\u8A5E",
|
|
1891
|
-
"\u6163\u7528\u53E5",
|
|
1892
|
-
"\u3053\u3068\u308F\u3056",
|
|
1893
|
-
"\u52A9\u6570\u8A5E",
|
|
1894
|
-
"\u82F1\u6570\u5B57\u6DF7\u5408\u8868\u8A18",
|
|
1895
|
-
"\u52D5\u8A5E\u53E5",
|
|
1896
|
-
"\u6210\u8A9E",
|
|
1897
|
-
"\u610F\u7FA9",
|
|
1898
|
-
"\u982D\u5B57\u8A9E",
|
|
1899
|
-
"\u63A5\u5C3E\u8A9E"
|
|
1900
|
-
]) {
|
|
1921
|
+
for (const pos of posList) {
|
|
1901
1922
|
posMap.set(pos, {});
|
|
1902
1923
|
for (const te of vte)
|
|
1903
1924
|
if (te.pos_title === pos || te.pos_title === "\u548C\u8A9E\u306E\u6F22\u5B57\u8868\u8A18") {
|
|
1904
1925
|
const posEntries = posMap.get(pos);
|
|
1905
1926
|
if (posEntries.title === void 0)
|
|
1906
1927
|
posEntries.title = /* @__PURE__ */ new Map();
|
|
1907
|
-
const
|
|
1928
|
+
const entryList = posEntries.title.get(
|
|
1908
1929
|
te.word
|
|
1909
1930
|
);
|
|
1910
|
-
if (
|
|
1931
|
+
if (entryList !== void 0) entryList.push(te);
|
|
1911
1932
|
else posEntries.title.set(te.word, [te]);
|
|
1912
1933
|
}
|
|
1913
1934
|
for (const ft of fge)
|
|
@@ -1915,8 +1936,8 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1915
1936
|
const posEntries = posMap.get(pos);
|
|
1916
1937
|
if (posEntries.formTitle === void 0)
|
|
1917
1938
|
posEntries.formTitle = /* @__PURE__ */ new Map();
|
|
1918
|
-
const
|
|
1919
|
-
if (
|
|
1939
|
+
const entryList = posEntries.formTitle.get(ft.word);
|
|
1940
|
+
if (entryList !== void 0) entryList.push(ft);
|
|
1920
1941
|
else posEntries.formTitle.set(ft.word, [ft]);
|
|
1921
1942
|
}
|
|
1922
1943
|
for (const wf of wfe)
|
|
@@ -1924,10 +1945,10 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1924
1945
|
const posEntries = posMap.get(pos);
|
|
1925
1946
|
if (posEntries.form === void 0)
|
|
1926
1947
|
posEntries.form = /* @__PURE__ */ new Map();
|
|
1927
|
-
const
|
|
1948
|
+
const entryList = posEntries.form.get(
|
|
1928
1949
|
wf.word
|
|
1929
1950
|
);
|
|
1930
|
-
if (
|
|
1951
|
+
if (entryList !== void 0) entryList.push(wf);
|
|
1931
1952
|
else posEntries.form.set(wf.word, [wf]);
|
|
1932
1953
|
}
|
|
1933
1954
|
}
|
|
@@ -1940,7 +1961,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1940
1961
|
for (const m of word.meanings)
|
|
1941
1962
|
for (const note of m.partOfSpeech) {
|
|
1942
1963
|
const noteEntry = noteMap.get(note);
|
|
1943
|
-
if (noteEntry
|
|
1964
|
+
if ((noteEntry == null ? void 0 : noteEntry.length) === 3) {
|
|
1944
1965
|
const notePos = noteEntry[2];
|
|
1945
1966
|
if (Array.isArray(notePos))
|
|
1946
1967
|
for (const pos of notePos) {
|
|
@@ -1957,24 +1978,21 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1957
1978
|
if (poses.size > 0)
|
|
1958
1979
|
for (const pos of poses) {
|
|
1959
1980
|
const posEntries = posMap.get(pos);
|
|
1960
|
-
if (rkf.kanjiForms)
|
|
1981
|
+
if (rkf.kanjiForms !== void 0)
|
|
1961
1982
|
for (const kf of rkf.kanjiForms) {
|
|
1962
1983
|
const te = (_a = posEntries.title) == null ? void 0 : _a.get(kf);
|
|
1963
1984
|
const fe = (_b = posEntries.form) == null ? void 0 : _b.get(kf);
|
|
1964
|
-
if (te)
|
|
1985
|
+
if (te !== void 0)
|
|
1965
1986
|
entriesWithTitles.push(
|
|
1966
1987
|
...te.filter(
|
|
1967
1988
|
(ent) => validFormOfEntries.has(ent.word) || validGlossesEntries.has(ent.word) || validFormsEntries.has(ent.word)
|
|
1968
1989
|
)
|
|
1969
1990
|
);
|
|
1970
|
-
if (fe)
|
|
1991
|
+
if (fe !== void 0)
|
|
1971
1992
|
entriesWithForms.push(
|
|
1972
1993
|
...fe.filter(
|
|
1973
|
-
(ent) => ent.forms && ent.forms.some(
|
|
1974
|
-
(form) =>
|
|
1975
|
-
var _a2;
|
|
1976
|
-
return ((_a2 = rkf.kanjiForms) == null ? void 0 : _a2.has(form)) || rkf.readings.has(form);
|
|
1977
|
-
}
|
|
1994
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
1995
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1978
1996
|
)
|
|
1979
1997
|
)
|
|
1980
1998
|
);
|
|
@@ -1983,50 +2001,41 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1983
2001
|
const te = (_c = posEntries.title) == null ? void 0 : _c.get(r);
|
|
1984
2002
|
const fe = (_d = posEntries.form) == null ? void 0 : _d.get(r);
|
|
1985
2003
|
const fte = (_e = posEntries.formTitle) == null ? void 0 : _e.get(r);
|
|
1986
|
-
if (te)
|
|
2004
|
+
if (te !== void 0)
|
|
1987
2005
|
entriesWithTitles.push(
|
|
1988
2006
|
...te.filter(
|
|
1989
|
-
(ent) => ent.forms && ent.forms.some(
|
|
1990
|
-
(form) =>
|
|
1991
|
-
var _a2;
|
|
1992
|
-
return ((_a2 = rkf.kanjiForms) == null ? void 0 : _a2.has(form)) || rkf.readings.has(form);
|
|
1993
|
-
}
|
|
2007
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2008
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1994
2009
|
)
|
|
1995
2010
|
)
|
|
1996
2011
|
);
|
|
1997
|
-
if (fe)
|
|
2012
|
+
if (fe !== void 0)
|
|
1998
2013
|
entriesWithForms.push(
|
|
1999
2014
|
...fe.filter(
|
|
2000
|
-
(ent) => ent.forms && ent.forms.some(
|
|
2001
|
-
(form) =>
|
|
2002
|
-
var _a2;
|
|
2003
|
-
return ((_a2 = rkf.kanjiForms) == null ? void 0 : _a2.has(form)) || rkf.readings.has(form);
|
|
2004
|
-
}
|
|
2015
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2016
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2005
2017
|
)
|
|
2006
2018
|
)
|
|
2007
2019
|
);
|
|
2008
|
-
if (fte) entriesWithFormTitles.push(...fte);
|
|
2020
|
+
if (fte !== void 0) entriesWithFormTitles.push(...fte);
|
|
2009
2021
|
}
|
|
2010
2022
|
}
|
|
2011
2023
|
if (entriesWithTitles.length === 0 && entriesWithFormTitles.length === 0 && entriesWithForms.length === 0) {
|
|
2012
|
-
if (rkf.kanjiForms)
|
|
2024
|
+
if (rkf.kanjiForms !== void 0)
|
|
2013
2025
|
for (const kf of rkf.kanjiForms) {
|
|
2014
2026
|
const te = validTitleEntries.get(kf);
|
|
2015
2027
|
const fe = entriesWithFormsGlobal.get(kf);
|
|
2016
|
-
if (te)
|
|
2028
|
+
if (te !== void 0)
|
|
2017
2029
|
entriesWithTitles.push(
|
|
2018
2030
|
...te.filter(
|
|
2019
2031
|
(ent) => validFormOfEntries.has(ent.word) || validGlossesEntries.has(ent.word) || validFormsEntries.has(ent.word)
|
|
2020
2032
|
)
|
|
2021
2033
|
);
|
|
2022
|
-
if (fe)
|
|
2034
|
+
if (fe !== void 0)
|
|
2023
2035
|
entriesWithForms.push(
|
|
2024
2036
|
...fe.filter(
|
|
2025
|
-
(ent) => ent.forms && ent.forms.some(
|
|
2026
|
-
(form) =>
|
|
2027
|
-
var _a2;
|
|
2028
|
-
return ((_a2 = rkf.kanjiForms) == null ? void 0 : _a2.has(form)) || rkf.readings.has(form);
|
|
2029
|
-
}
|
|
2037
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2038
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2030
2039
|
)
|
|
2031
2040
|
)
|
|
2032
2041
|
);
|
|
@@ -2035,37 +2044,31 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2035
2044
|
const te = validTitleEntries.get(r);
|
|
2036
2045
|
const fe = entriesWithFormsGlobal.get(r);
|
|
2037
2046
|
const fte = entriesWithFormTitlesGlobal.get(r);
|
|
2038
|
-
if (te)
|
|
2047
|
+
if (te !== void 0)
|
|
2039
2048
|
entriesWithTitles.push(
|
|
2040
2049
|
...te.filter(
|
|
2041
|
-
(ent) => ent.forms && ent.forms.some(
|
|
2042
|
-
(form) =>
|
|
2043
|
-
var _a2;
|
|
2044
|
-
return ((_a2 = rkf.kanjiForms) == null ? void 0 : _a2.has(form)) || rkf.readings.has(form);
|
|
2045
|
-
}
|
|
2050
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2051
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2046
2052
|
)
|
|
2047
2053
|
)
|
|
2048
2054
|
);
|
|
2049
|
-
if (fe)
|
|
2055
|
+
if (fe !== void 0)
|
|
2050
2056
|
entriesWithForms.push(
|
|
2051
2057
|
...fe.filter(
|
|
2052
|
-
(ent) => ent.forms && ent.forms.some(
|
|
2053
|
-
(form) =>
|
|
2054
|
-
var _a2;
|
|
2055
|
-
return ((_a2 = rkf.kanjiForms) == null ? void 0 : _a2.has(form)) || rkf.readings.has(form);
|
|
2056
|
-
}
|
|
2058
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2059
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2057
2060
|
)
|
|
2058
2061
|
)
|
|
2059
2062
|
);
|
|
2060
|
-
if (fte) entriesWithFormTitles.push(...fte);
|
|
2063
|
+
if (fte !== void 0) entriesWithFormTitles.push(...fte);
|
|
2061
2064
|
}
|
|
2062
2065
|
}
|
|
2063
2066
|
if (entriesWithTitles.length > 0 && (entriesWithFormTitles.length > 0 || entriesWithForms.length > 0))
|
|
2064
2067
|
wordEntriesPairs.push({
|
|
2065
2068
|
word,
|
|
2066
2069
|
readings: rkf.readings,
|
|
2067
|
-
...rkf.kanjiForms ? { kanjiForms: rkf.kanjiForms } : {},
|
|
2068
|
-
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,
|
|
2069
2072
|
entriesWithTitles,
|
|
2070
2073
|
entriesWithFormTitles,
|
|
2071
2074
|
entriesWithForms
|
|
@@ -2080,36 +2083,31 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2080
2083
|
const refsMap = /* @__PURE__ */ new Map();
|
|
2081
2084
|
const forms = /* @__PURE__ */ new Set();
|
|
2082
2085
|
for (const ent of pair.entriesWithTitles) {
|
|
2083
|
-
const
|
|
2084
|
-
const
|
|
2085
|
-
const validForms2 = validFormsEntries.has(ent.word);
|
|
2086
|
+
const hasValidFormOf = validFormOfEntries.has(ent.word);
|
|
2087
|
+
const hasValidForms = validFormsEntries.has(ent.word);
|
|
2086
2088
|
const hasForms = ent.forms !== void 0 && ent.forms.some((form) => pair.forms.has(form));
|
|
2087
|
-
if (pair.kanjiForms && pair.kanjiForms.has(ent.word)
|
|
2089
|
+
if (pair.kanjiForms !== void 0 && pair.kanjiForms.has(ent.word)) {
|
|
2088
2090
|
kanjiFormEntries.push(ent);
|
|
2089
|
-
|
|
2090
|
-
|
|
2091
|
-
|
|
2092
|
-
|
|
2093
|
-
|
|
2094
|
-
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
}
|
|
2099
|
-
}
|
|
2100
|
-
if (validGlosses) {
|
|
2101
|
-
for (const gloss of sense.glosses)
|
|
2102
|
-
if (gloss.includes("\u8868\u8A18") || gloss.includes("\u53C2\u7167")) {
|
|
2103
|
-
for (const f of pair.forms)
|
|
2104
|
-
if (gloss.includes(f)) {
|
|
2105
|
-
const elem = refsMap.get(f);
|
|
2106
|
-
if (!elem) refsMap.set(f, /* @__PURE__ */ new Set([ent.word]));
|
|
2107
|
-
else elem.add(ent.word);
|
|
2108
|
-
}
|
|
2109
|
-
}
|
|
2110
|
-
}
|
|
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
|
+
}
|
|
2111
2100
|
}
|
|
2112
|
-
|
|
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) {
|
|
2113
2111
|
for (const form of ent.forms)
|
|
2114
2112
|
if (pair.forms.has(form)) forms.add(form);
|
|
2115
2113
|
}
|
|
@@ -2120,7 +2118,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2120
2118
|
}
|
|
2121
2119
|
for (const entry of pair.entriesWithForms) {
|
|
2122
2120
|
const elem = titleFormMap.get(entry.word);
|
|
2123
|
-
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)))
|
|
2124
2122
|
entriesWithForms.push(entry);
|
|
2125
2123
|
}
|
|
2126
2124
|
for (const entry of pair.entriesWithFormTitles) {
|
|
@@ -2129,7 +2127,8 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2129
2127
|
continue;
|
|
2130
2128
|
}
|
|
2131
2129
|
const ft = refsMap.get(entry.word);
|
|
2132
|
-
if (ft && !ft.isDisjointFrom(pair.forms))
|
|
2130
|
+
if (ft !== void 0 && !ft.isDisjointFrom(pair.forms))
|
|
2131
|
+
entriesWithForms.push(entry);
|
|
2133
2132
|
}
|
|
2134
2133
|
if (kanjiFormEntries.length > 0) {
|
|
2135
2134
|
for (const entry of kanjiFormEntries)
|
|
@@ -2146,7 +2145,14 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2146
2145
|
japaneseDefinitions.push({
|
|
2147
2146
|
wordID: pair.word.id,
|
|
2148
2147
|
definitions,
|
|
2149
|
-
wordForms: pair.forms
|
|
2148
|
+
wordForms: pair.forms.union(
|
|
2149
|
+
new Set(
|
|
2150
|
+
pair.forms.values().toArray().flatMap((form) => [
|
|
2151
|
+
hiraganaToKatakana(form),
|
|
2152
|
+
katakanaToHiragana(form)
|
|
2153
|
+
])
|
|
2154
|
+
)
|
|
2155
|
+
)
|
|
2150
2156
|
});
|
|
2151
2157
|
}
|
|
2152
2158
|
for (let i = 0; i < japaneseDefinitions.length; i++) {
|
|
@@ -2155,14 +2161,14 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2155
2161
|
const defCount = definitionMap.get(
|
|
2156
2162
|
pair.definitions[j].definition
|
|
2157
2163
|
);
|
|
2158
|
-
if (defCount && defCount.count > 1) {
|
|
2164
|
+
if (defCount !== void 0 && defCount.count > 1) {
|
|
2159
2165
|
let mnba = true;
|
|
2160
2166
|
for (const f of pair.wordForms)
|
|
2161
2167
|
if (pair.definitions[j].definition.includes(f)) {
|
|
2162
2168
|
mnba = false;
|
|
2163
2169
|
break;
|
|
2164
2170
|
}
|
|
2165
|
-
|
|
2171
|
+
pair.definitions[j].mayNotBeAccurate = mnba ? 2 : 1;
|
|
2166
2172
|
}
|
|
2167
2173
|
}
|
|
2168
2174
|
delete pair.wordForms;
|
|
@@ -2171,33 +2177,30 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2171
2177
|
return japaneseDefinitions;
|
|
2172
2178
|
}
|
|
2173
2179
|
async function getWordDefinitionsWithFurigana(entryList, jmDict) {
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
pair.definitions[j].
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
}
|
|
2195
|
-
resolve(japaneseDefinitions);
|
|
2196
|
-
});
|
|
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;
|
|
2197
2200
|
}
|
|
2198
2201
|
function lookupWordNote(key, notes, tags) {
|
|
2199
2202
|
const info = noteMap.get(key.toLowerCase());
|
|
2200
|
-
if (
|
|
2203
|
+
if (info === void 0) {
|
|
2201
2204
|
notes.push(key);
|
|
2202
2205
|
return { note: key };
|
|
2203
2206
|
}
|
|
@@ -2207,22 +2210,172 @@ function lookupWordNote(key, notes, tags) {
|
|
|
2207
2210
|
return { note: info[1], tag };
|
|
2208
2211
|
}
|
|
2209
2212
|
var wordAddNoteArray = (arr, cb) => {
|
|
2210
|
-
if (
|
|
2213
|
+
if (arr === void 0) return;
|
|
2211
2214
|
for (const v of arr) cb(v);
|
|
2212
2215
|
};
|
|
2213
|
-
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) {
|
|
2214
2367
|
var _a;
|
|
2215
2368
|
let dictWord = void 0;
|
|
2216
|
-
if (typeof
|
|
2369
|
+
if (typeof searchedWord === "string" && dict !== void 0) {
|
|
2217
2370
|
if (Array.isArray(dict))
|
|
2218
2371
|
dictWord = dict.find(
|
|
2219
|
-
(entry) => entry.id ===
|
|
2372
|
+
(entry) => entry.id === searchedWord
|
|
2220
2373
|
);
|
|
2221
|
-
if (dict instanceof Map) dictWord = dict.get(
|
|
2374
|
+
if (dict instanceof Map) dictWord = dict.get(searchedWord);
|
|
2222
2375
|
}
|
|
2223
|
-
if (typeof
|
|
2224
|
-
if (dictWord) {
|
|
2225
|
-
const
|
|
2376
|
+
if (typeof searchedWord === "object") dictWord = searchedWord;
|
|
2377
|
+
if (dictWord !== void 0) {
|
|
2378
|
+
const word = {
|
|
2226
2379
|
id: dictWord.id,
|
|
2227
2380
|
readings: [],
|
|
2228
2381
|
translations: [],
|
|
@@ -2232,46 +2385,46 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2232
2385
|
tags: []
|
|
2233
2386
|
};
|
|
2234
2387
|
if (dictWord.isCommon === true) {
|
|
2235
|
-
|
|
2236
|
-
|
|
2388
|
+
word.common = true;
|
|
2389
|
+
word.tags.push("word::common");
|
|
2237
2390
|
}
|
|
2238
|
-
if (dictWord.kanjiForms)
|
|
2239
|
-
|
|
2391
|
+
if (dictWord.kanjiForms !== void 0)
|
|
2392
|
+
word.kanjiForms = dictWord.kanjiForms.map(
|
|
2240
2393
|
(dictKanjiForm) => ({
|
|
2241
2394
|
kanjiForm: dictKanjiForm.form,
|
|
2242
|
-
...dictKanjiForm.notes ? {
|
|
2395
|
+
...dictKanjiForm.notes !== void 0 ? {
|
|
2243
2396
|
notes: dictKanjiForm.notes.map((note) => {
|
|
2244
2397
|
const noteAndTag = lookupWordNote(
|
|
2245
2398
|
note,
|
|
2246
2399
|
[],
|
|
2247
|
-
|
|
2400
|
+
word.tags
|
|
2248
2401
|
);
|
|
2249
2402
|
return capitalizeString(noteAndTag.note);
|
|
2250
2403
|
})
|
|
2251
2404
|
} : {},
|
|
2252
|
-
...dictKanjiForm.commonness && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
|
|
2405
|
+
...dictKanjiForm.commonness !== void 0 && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
|
|
2253
2406
|
})
|
|
2254
2407
|
);
|
|
2255
|
-
|
|
2408
|
+
word.readings = dictWord.readings.map((dictReading) => ({
|
|
2256
2409
|
reading: dictReading.reading,
|
|
2257
|
-
...dictReading.kanjiFormRestrictions || dictReading.notes ? {
|
|
2410
|
+
...dictReading.kanjiFormRestrictions !== void 0 || dictReading.notes !== void 0 ? {
|
|
2258
2411
|
notes: [
|
|
2259
|
-
...dictReading.kanjiFormRestrictions ? dictReading.kanjiFormRestrictions.map(
|
|
2412
|
+
...dictReading.kanjiFormRestrictions !== void 0 ? dictReading.kanjiFormRestrictions.map(
|
|
2260
2413
|
(restriction) => `Reading restricted to ${restriction}`
|
|
2261
2414
|
) : [],
|
|
2262
|
-
...dictReading.notes ? dictReading.notes.map((note) => {
|
|
2415
|
+
...dictReading.notes !== void 0 ? dictReading.notes.map((note) => {
|
|
2263
2416
|
const noteAndTag = lookupWordNote(
|
|
2264
2417
|
note,
|
|
2265
2418
|
[],
|
|
2266
|
-
|
|
2419
|
+
word.tags
|
|
2267
2420
|
);
|
|
2268
2421
|
return capitalizeString(noteAndTag.note);
|
|
2269
2422
|
}) : []
|
|
2270
2423
|
]
|
|
2271
2424
|
} : {},
|
|
2272
|
-
...dictReading.commonness && dictReading.commonness.length > 0 ? { common: true } : {}
|
|
2425
|
+
...dictReading.commonness !== void 0 && dictReading.commonness.length > 0 ? { common: true } : {}
|
|
2273
2426
|
}));
|
|
2274
|
-
|
|
2427
|
+
word.translations = [];
|
|
2275
2428
|
for (const dictMeaning of dictWord.meanings) {
|
|
2276
2429
|
const translationTypes = [];
|
|
2277
2430
|
const translations = dictMeaning.translations.map(
|
|
@@ -2282,7 +2435,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2282
2435
|
translation.type
|
|
2283
2436
|
);
|
|
2284
2437
|
translationTypes.push(translationNoteAndTag[1]);
|
|
2285
|
-
|
|
2438
|
+
word.tags.push(`word::${translationNoteAndTag[0]}`);
|
|
2286
2439
|
return translation.translation;
|
|
2287
2440
|
}
|
|
2288
2441
|
}
|
|
@@ -2299,15 +2452,15 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2299
2452
|
for (const t of translationTypes) notes.push(t);
|
|
2300
2453
|
wordAddNoteArray(
|
|
2301
2454
|
dictMeaning.partOfSpeech,
|
|
2302
|
-
(pos) => lookupWordNote(pos, notes,
|
|
2455
|
+
(pos) => lookupWordNote(pos, notes, word.tags)
|
|
2303
2456
|
);
|
|
2304
2457
|
wordAddNoteArray(
|
|
2305
2458
|
dictMeaning.fields,
|
|
2306
|
-
(field) => lookupWordNote(field, notes,
|
|
2459
|
+
(field) => lookupWordNote(field, notes, word.tags)
|
|
2307
2460
|
);
|
|
2308
2461
|
wordAddNoteArray(
|
|
2309
2462
|
dictMeaning.dialects,
|
|
2310
|
-
(dialect) => lookupWordNote(dialect, notes,
|
|
2463
|
+
(dialect) => lookupWordNote(dialect, notes, word.tags)
|
|
2311
2464
|
);
|
|
2312
2465
|
wordAddNoteArray(
|
|
2313
2466
|
dictMeaning.antonyms,
|
|
@@ -2319,45 +2472,45 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2319
2472
|
);
|
|
2320
2473
|
wordAddNoteArray(
|
|
2321
2474
|
dictMeaning.info,
|
|
2322
|
-
(info) => lookupWordNote(info, notes,
|
|
2475
|
+
(info) => lookupWordNote(info, notes, word.tags)
|
|
2323
2476
|
);
|
|
2324
2477
|
wordAddNoteArray(
|
|
2325
2478
|
dictMeaning.misc,
|
|
2326
|
-
(misc) => lookupWordNote(misc, notes,
|
|
2479
|
+
(misc) => lookupWordNote(misc, notes, word.tags)
|
|
2327
2480
|
);
|
|
2328
2481
|
for (let i = 0; i < notes.length; i++)
|
|
2329
2482
|
notes[i] = capitalizeString(notes[i]);
|
|
2330
|
-
|
|
2483
|
+
word.translations.push({
|
|
2331
2484
|
translation: translations.join("; "),
|
|
2332
2485
|
notes
|
|
2333
2486
|
});
|
|
2334
2487
|
}
|
|
2335
2488
|
if (dictWord.usuallyInKana === true) {
|
|
2336
|
-
|
|
2337
|
-
|
|
2489
|
+
word.usuallyInKana = true;
|
|
2490
|
+
word.tags.push("word::usually_in_kana_for_all_senses");
|
|
2338
2491
|
}
|
|
2339
|
-
if (kanjiDic &&
|
|
2492
|
+
if (kanjiDic !== void 0 && word.kanjiForms !== void 0) {
|
|
2340
2493
|
const kanji = [];
|
|
2341
2494
|
const seenChars = /* @__PURE__ */ new Set();
|
|
2342
|
-
for (const kanjiForm of
|
|
2495
|
+
for (const kanjiForm of word.kanjiForms)
|
|
2343
2496
|
for (const char of kanjiForm.kanjiForm.split("").filter((c) => regexps.kanji.test(c))) {
|
|
2344
2497
|
if (seenChars.has(char)) continue;
|
|
2345
2498
|
seenChars.add(char);
|
|
2346
2499
|
const kanjiEntry = kanjiDic instanceof Map ? kanjiDic.get(char) : void 0;
|
|
2347
2500
|
const kanjiObj = getKanji(
|
|
2348
2501
|
kanjiEntry ?? char,
|
|
2349
|
-
|
|
2502
|
+
!(kanjiDic instanceof Map) ? kanjiDic : void 0
|
|
2350
2503
|
);
|
|
2351
|
-
if (kanjiObj)
|
|
2504
|
+
if (kanjiObj !== void 0)
|
|
2352
2505
|
kanji.push({
|
|
2353
2506
|
kanji: kanjiObj.kanji,
|
|
2354
|
-
...kanjiObj.meanings && kanjiObj.meanings.length > 0 ? { meanings: kanjiObj.meanings } : {}
|
|
2507
|
+
...kanjiObj.meanings !== void 0 && kanjiObj.meanings.length > 0 ? { meanings: kanjiObj.meanings } : {}
|
|
2355
2508
|
});
|
|
2356
2509
|
}
|
|
2357
|
-
if (kanji.length > 0)
|
|
2510
|
+
if (kanji.length > 0) word.kanji = kanji;
|
|
2358
2511
|
}
|
|
2359
|
-
if (dictWord.hasPhrases !== void 0
|
|
2360
|
-
const exampleList =
|
|
2512
|
+
if (dictWord.hasPhrases === true && examples !== void 0) {
|
|
2513
|
+
const exampleList = examples instanceof Map ? examples.get(dictWord.id) ?? [] : examples;
|
|
2361
2514
|
const rkf = getValidForms(
|
|
2362
2515
|
dictWord.readings,
|
|
2363
2516
|
dictWord.kanjiForms,
|
|
@@ -2366,7 +2519,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2366
2519
|
const readings = new Set(
|
|
2367
2520
|
rkf.readings.map((r) => r.reading)
|
|
2368
2521
|
);
|
|
2369
|
-
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;
|
|
2370
2523
|
let kanjiFormExamples = [];
|
|
2371
2524
|
const readingMatchingKanjiFormExamples = [];
|
|
2372
2525
|
const readingExamples = [];
|
|
@@ -2377,7 +2530,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2377
2530
|
const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
|
|
2378
2531
|
const readingAsInflectedFormMatch = part.inflectedForm !== void 0 && readings.has(part.inflectedForm);
|
|
2379
2532
|
const referenceIDMatch = part.referenceID === dictWord.id;
|
|
2380
|
-
if (kanjiForms && kanjiForms.has(part.baseForm) || referenceIDMatch) {
|
|
2533
|
+
if (kanjiForms !== void 0 && kanjiForms.has(part.baseForm) || referenceIDMatch) {
|
|
2381
2534
|
if (readingAsReadingMatch || readingAsInflectedFormMatch) {
|
|
2382
2535
|
readingMatchingKanjiFormExamples.push({
|
|
2383
2536
|
ex: example,
|
|
@@ -2393,16 +2546,16 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2393
2546
|
break;
|
|
2394
2547
|
}
|
|
2395
2548
|
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
2396
|
-
if (
|
|
2549
|
+
if (readingAsBaseFormMatch && kanjiForms === void 0) {
|
|
2397
2550
|
readingExamples.push({ ex: example, partIndex: i });
|
|
2398
2551
|
break;
|
|
2399
2552
|
}
|
|
2400
2553
|
}
|
|
2401
2554
|
if (readingMatchingKanjiForms.size > 0)
|
|
2402
2555
|
kanjiFormExamples = kanjiFormExamples.filter(
|
|
2403
|
-
(ex) => ex.form && readingMatchingKanjiForms.has(ex.form)
|
|
2556
|
+
(ex) => ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
|
|
2404
2557
|
);
|
|
2405
|
-
const includeKanjiFormExamples =
|
|
2558
|
+
const includeKanjiFormExamples = word.kanjiForms !== void 0;
|
|
2406
2559
|
let wordExamples = [
|
|
2407
2560
|
...includeKanjiFormExamples ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : readingExamples
|
|
2408
2561
|
];
|
|
@@ -2412,14 +2565,14 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2412
2565
|
readingMatchingKanjiForms.clear();
|
|
2413
2566
|
const glossSpecificExamples = [];
|
|
2414
2567
|
const seenPhrases = /* @__PURE__ */ new Set();
|
|
2415
|
-
for (let i = 0; i <
|
|
2568
|
+
for (let i = 0; i < word.translations.length; i++)
|
|
2416
2569
|
outer: for (const example of wordExamples) {
|
|
2417
2570
|
if (seenPhrases.has(example.ex.phrase)) continue;
|
|
2418
2571
|
for (let j = 0; j < example.ex.parts.length; j++) {
|
|
2419
2572
|
const part = example.ex.parts[j];
|
|
2420
2573
|
if (j === example.partIndex && part.glossNumber === i + 1) {
|
|
2421
2574
|
example.ex.glossNumber = {
|
|
2422
|
-
wordId:
|
|
2575
|
+
wordId: word.id,
|
|
2423
2576
|
glossNumber: i + 1
|
|
2424
2577
|
};
|
|
2425
2578
|
glossSpecificExamples.push(example);
|
|
@@ -2428,7 +2581,6 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2428
2581
|
}
|
|
2429
2582
|
}
|
|
2430
2583
|
}
|
|
2431
|
-
}
|
|
2432
2584
|
if (glossSpecificExamples.length > 0) {
|
|
2433
2585
|
if (glossSpecificExamples.length < 5) {
|
|
2434
2586
|
wordExamples = wordExamples.filter(
|
|
@@ -2443,200 +2595,53 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2443
2595
|
wordExamples = glossSpecificExamples;
|
|
2444
2596
|
}
|
|
2445
2597
|
if (wordExamples.length > 0) {
|
|
2446
|
-
|
|
2598
|
+
word.phrases = (glossSpecificExamples.length === 0 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => ({
|
|
2447
2599
|
phrase: ex.ex.furigana ?? ex.ex.phrase,
|
|
2448
2600
|
translation: ex.ex.translation,
|
|
2449
2601
|
originalPhrase: ex.ex.phrase,
|
|
2450
|
-
...ex.ex.glossNumber ? { glossNumber: ex.ex.glossNumber } : {}
|
|
2602
|
+
...ex.ex.glossNumber !== void 0 ? { glossNumber: ex.ex.glossNumber } : {}
|
|
2451
2603
|
}));
|
|
2452
|
-
|
|
2604
|
+
word.tags.push("word::has_phrases");
|
|
2453
2605
|
if (glossSpecificExamples.length > 0)
|
|
2454
|
-
|
|
2606
|
+
word.tags.push("word::has_meaning-specific_phrases");
|
|
2455
2607
|
}
|
|
2456
2608
|
}
|
|
2457
|
-
if (definitions) {
|
|
2458
|
-
const defs =
|
|
2459
|
-
|
|
2460
|
-
|
|
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 = [
|
|
2461
2615
|
...defs.toSorted(
|
|
2462
|
-
(a, b) =>
|
|
2616
|
+
(a, b) => (a.mayNotBeAccurate ?? 0) - (b.mayNotBeAccurate ?? 0)
|
|
2463
2617
|
)
|
|
2464
2618
|
];
|
|
2465
2619
|
}
|
|
2466
|
-
return
|
|
2467
|
-
} else return void 0;
|
|
2468
|
-
}
|
|
2469
|
-
function getKanji(kanji, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
2470
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
2471
|
-
let dictKanji = void 0;
|
|
2472
|
-
if (typeof kanji === "string" && dict)
|
|
2473
|
-
dictKanji = Array.isArray(dict) ? dict.find((entry) => entry.kanji === kanji) : dict.get(kanji);
|
|
2474
|
-
else if (typeof kanji === "object") dictKanji = kanji;
|
|
2475
|
-
if (dictKanji) {
|
|
2476
|
-
const kanji2 = {
|
|
2477
|
-
kanji: dictKanji.kanji,
|
|
2478
|
-
strokes: dictKanji.misc.strokeNumber,
|
|
2479
|
-
...dictKanji.misc && dictKanji.misc.grade ? { grade: dictKanji.misc.grade } : {},
|
|
2480
|
-
...dictKanji.misc && dictKanji.misc.frequency ? { frequency: dictKanji.misc.frequency } : {},
|
|
2481
|
-
...dictKanji.misc && dictKanji.misc.jlpt ? { jlpt: dictKanji.misc.jlpt } : {},
|
|
2482
|
-
noteID: `kanji_${dictKanji.kanji}`,
|
|
2483
|
-
...noteTypeName ? { noteTypeName } : {},
|
|
2484
|
-
...deckPath ? { deckPath } : {},
|
|
2485
|
-
tags: []
|
|
2486
|
-
};
|
|
2487
|
-
if (dictKanji.readingMeaning && dictKanji.readingMeaning.length > 0) {
|
|
2488
|
-
const meanings = [];
|
|
2489
|
-
const nanori = [];
|
|
2490
|
-
const onyomi = [];
|
|
2491
|
-
const kunyomi = [];
|
|
2492
|
-
for (const rm of dictKanji.readingMeaning) {
|
|
2493
|
-
if (rm.nanori && rm.nanori.length > 0) nanori.push(...rm.nanori);
|
|
2494
|
-
for (const group of rm.groups) {
|
|
2495
|
-
if (group.readings) {
|
|
2496
|
-
onyomi.push(
|
|
2497
|
-
...group.readings.filter((reading) => reading.type === "ja_on").map((reading) => reading.reading)
|
|
2498
|
-
);
|
|
2499
|
-
kunyomi.push(
|
|
2500
|
-
...group.readings.filter(
|
|
2501
|
-
(reading) => reading.type === "ja_kun"
|
|
2502
|
-
).map((reading) => reading.reading)
|
|
2503
|
-
);
|
|
2504
|
-
}
|
|
2505
|
-
if (group.meanings && group.meanings.length > 0)
|
|
2506
|
-
meanings.push(...group.meanings);
|
|
2507
|
-
}
|
|
2508
|
-
}
|
|
2509
|
-
if (meanings.length > 0) kanji2.meanings = meanings;
|
|
2510
|
-
if (nanori.length > 0) kanji2.nanori = nanori;
|
|
2511
|
-
if (onyomi.length > 0) kanji2.onyomi = onyomi;
|
|
2512
|
-
if (kunyomi.length > 0) kanji2.kunyomi = kunyomi;
|
|
2513
|
-
}
|
|
2514
|
-
if (jmDict) {
|
|
2515
|
-
let kanjiWords = Array.isArray(
|
|
2516
|
-
jmDict
|
|
2517
|
-
) ? jmDict : jmDict.get(kanji2.kanji);
|
|
2518
|
-
const firstKfWords = kanjiWords == null ? void 0 : kanjiWords.filter(
|
|
2519
|
-
(word) => word.kanjiForms && word.kanjiForms[0].form.includes(kanji2.kanji)
|
|
2520
|
-
);
|
|
2521
|
-
if (firstKfWords && firstKfWords.length > 0) kanjiWords = firstKfWords;
|
|
2522
|
-
if (kanjiWords) {
|
|
2523
|
-
const validWords = [];
|
|
2524
|
-
for (const word of kanjiWords) {
|
|
2525
|
-
const kanjiForm = (_a = firstKfWords && firstKfWords.length > 0 ? word.kanjiForms[0] : word.kanjiForms.find(
|
|
2526
|
-
(kf) => kf.form.includes(kanji2.kanji)
|
|
2527
|
-
)) == null ? void 0 : _a.form;
|
|
2528
|
-
if (kanjiForm) {
|
|
2529
|
-
const reading = (_b = firstKfWords && firstKfWords.length > 0 ? word.readings[0] : word.readings.find(
|
|
2530
|
-
(reading2) => reading2.kanjiFormRestrictions && reading2.kanjiFormRestrictions.includes(kanjiForm)
|
|
2531
|
-
)) == null ? void 0 : _b.reading;
|
|
2532
|
-
if (!reading) continue;
|
|
2533
|
-
const translation = (_c = firstKfWords && firstKfWords.length > 0 ? word.meanings[0] : word.meanings.find(
|
|
2534
|
-
(m) => m.translations && m.kanjiFormRestrictions && m.kanjiFormRestrictions.includes(kanjiForm)
|
|
2535
|
-
)) == null ? void 0 : _c.translations.map(
|
|
2536
|
-
(t) => typeof t === "string" ? t : t.translation
|
|
2537
|
-
)[0];
|
|
2538
|
-
if (!translation) continue;
|
|
2539
|
-
validWords.push({
|
|
2540
|
-
kanjiForms: [{ kanjiForm }],
|
|
2541
|
-
readings: [{ reading }],
|
|
2542
|
-
translations: [
|
|
2543
|
-
{
|
|
2544
|
-
translation
|
|
2545
|
-
}
|
|
2546
|
-
]
|
|
2547
|
-
});
|
|
2548
|
-
}
|
|
2549
|
-
if (validWords.length === 3) break;
|
|
2550
|
-
}
|
|
2551
|
-
if (validWords.length > 0) kanji2.words = validWords;
|
|
2552
|
-
}
|
|
2553
|
-
}
|
|
2554
|
-
if (svgList) {
|
|
2555
|
-
const codePoint = kanji2.kanji.codePointAt(0).toString(16).toLowerCase();
|
|
2556
|
-
const svg = Array.isArray(svgList) ? svgList.find(
|
|
2557
|
-
(svgFile) => [`${codePoint}.svg`, `0${codePoint}.svg`].includes(
|
|
2558
|
-
svgFile.toLowerCase()
|
|
2559
|
-
)
|
|
2560
|
-
) : svgList.get(kanji2.kanji);
|
|
2561
|
-
if (svg) kanji2.svg = svg;
|
|
2562
|
-
}
|
|
2563
|
-
if (kanji2.tags && dictKanji.isKokuji === true) {
|
|
2564
|
-
kanji2.kokuji = true;
|
|
2565
|
-
kanji2.tags.push("kanji::kokuji");
|
|
2566
|
-
}
|
|
2567
|
-
kanji2.tags.push(
|
|
2568
|
-
`kanji::strokes::${kanji2.strokes}`,
|
|
2569
|
-
...kanji2.frequency ? [`kanji::frequency::${kanji2.frequency}`] : [],
|
|
2570
|
-
...kanji2.grade ? [`kanji::grade::${kanji2.grade}`] : [],
|
|
2571
|
-
...kanji2.jlpt ? [`kanji::pre-2010_jlpt::${kanji2.jlpt.toLowerCase()}`] : [],
|
|
2572
|
-
`kanji::onyomi::${((_d = kanji2.onyomi) == null ? void 0 : _d.length) ?? 0}`,
|
|
2573
|
-
`kanji::kunyomi::${((_e = kanji2.kunyomi) == null ? void 0 : _e.length) ?? 0}`,
|
|
2574
|
-
`kanji::nanori::${((_f = kanji2.nanori) == null ? void 0 : _f.length) ?? 0}`,
|
|
2575
|
-
`kanji::words::${((_g = kanji2.words) == null ? void 0 : _g.length) ?? 0}`,
|
|
2576
|
-
...kanji2.svg ? ["kanji::has_svg"] : []
|
|
2577
|
-
);
|
|
2578
|
-
return kanji2;
|
|
2579
|
-
} else return void 0;
|
|
2580
|
-
}
|
|
2581
|
-
function getKanjiExtended(info, kanji, dict, useWords, jmDict, svgList, noteTypeName, deckPath, sourceURL) {
|
|
2582
|
-
const kanjiObj = getKanji(
|
|
2583
|
-
kanji,
|
|
2584
|
-
dict,
|
|
2585
|
-
jmDict,
|
|
2586
|
-
svgList,
|
|
2587
|
-
noteTypeName,
|
|
2588
|
-
deckPath
|
|
2589
|
-
);
|
|
2590
|
-
if (kanjiObj) {
|
|
2591
|
-
let usedInfo = false;
|
|
2592
|
-
if (info.components) {
|
|
2593
|
-
kanjiObj.components = info.components;
|
|
2594
|
-
usedInfo = true;
|
|
2595
|
-
}
|
|
2596
|
-
if (info.mnemonic && info.mnemonic.length > 0) {
|
|
2597
|
-
kanjiObj.mnemonic = info.mnemonic;
|
|
2598
|
-
usedInfo = true;
|
|
2599
|
-
}
|
|
2600
|
-
if (useWords === true && info.words && info.words.length > 0) {
|
|
2601
|
-
kanjiObj.words = info.words;
|
|
2602
|
-
usedInfo = true;
|
|
2603
|
-
}
|
|
2604
|
-
if (kanjiObj.components)
|
|
2605
|
-
kanjiObj.tags.push(`kanji::components::${kanjiObj.components.length}`);
|
|
2606
|
-
if (kanjiObj.mnemonic && kanjiObj.mnemonic.length > 0)
|
|
2607
|
-
kanjiObj.tags.push("kanji::has_mnemonic");
|
|
2608
|
-
if (useWords === true && kanjiObj.words && info.words)
|
|
2609
|
-
kanjiObj.tags.forEach((tag, index) => {
|
|
2610
|
-
if (tag.startsWith("kanji::words::") && kanjiObj.words) {
|
|
2611
|
-
kanjiObj.tags.splice(
|
|
2612
|
-
index,
|
|
2613
|
-
1,
|
|
2614
|
-
`kanji::words::${kanjiObj.words.length}`
|
|
2615
|
-
);
|
|
2616
|
-
}
|
|
2617
|
-
});
|
|
2618
|
-
if (sourceURL && info.externalInfo === true && usedInfo)
|
|
2619
|
-
kanjiObj.source = sourceURL;
|
|
2620
|
-
return kanjiObj;
|
|
2620
|
+
return word;
|
|
2621
2621
|
} else return void 0;
|
|
2622
2622
|
}
|
|
2623
2623
|
function isWord(entry) {
|
|
2624
|
-
|
|
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);
|
|
2625
2626
|
}
|
|
2626
2627
|
function isRadical(entry) {
|
|
2627
|
-
|
|
2628
|
+
var _a;
|
|
2629
|
+
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "radical")) == null ? void 0 : _a.value) === "string";
|
|
2628
2630
|
}
|
|
2629
2631
|
function isKanji(entry) {
|
|
2630
|
-
|
|
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";
|
|
2631
2634
|
}
|
|
2632
2635
|
function isKana(entry) {
|
|
2633
|
-
|
|
2636
|
+
var _a;
|
|
2637
|
+
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "kana")) == null ? void 0 : _a.value) === "string";
|
|
2634
2638
|
}
|
|
2635
2639
|
function isGrammar(entry) {
|
|
2636
|
-
|
|
2640
|
+
var _a;
|
|
2641
|
+
return typeof ((_a = Object.getOwnPropertyDescriptor(entry, "point")) == null ? void 0 : _a.value) === "string";
|
|
2637
2642
|
}
|
|
2638
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>" : ""}`;
|
|
2639
|
-
var createEntry = (entry, notes, phrase, glossSpecific) => `<div class="entry${glossSpecific ? " gloss-specific" : ""}">${entry}${notes && notes.length > 0 ? createNotes(notes, phrase) : ""}</div>`;
|
|
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>`;
|
|
2640
2645
|
function generateAnkiNote(entry) {
|
|
2641
2646
|
var _a, _b;
|
|
2642
2647
|
const fields = [];
|
|
@@ -2652,42 +2657,41 @@ function generateAnkiNote(entry) {
|
|
|
2652
2657
|
)
|
|
2653
2658
|
).join("")}</details>` : "";
|
|
2654
2659
|
const readingsField = `${firstReading}${otherReadings}`;
|
|
2655
|
-
const firstKanjiForm = entry.kanjiForms ? createEntry(
|
|
2660
|
+
const firstKanjiForm = entry.kanjiForms !== void 0 ? createEntry(
|
|
2656
2661
|
`<span class="word word-kanjiform"><ruby><rb>${entry.kanjiForms[0].kanjiForm}</rb><rt>${entry.readings[0].reading}</rt></ruby></span>`,
|
|
2657
2662
|
entry.kanjiForms[0].notes
|
|
2658
2663
|
) : void 0;
|
|
2659
|
-
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) => {
|
|
2660
2665
|
const restrictedReading = entry.readings.find(
|
|
2661
|
-
(r) => r.notes && r.notes.includes(
|
|
2666
|
+
(r) => r.notes !== void 0 && r.notes.includes(
|
|
2662
2667
|
`Reading restricted to ${kanjiFormEntry.kanjiForm}`
|
|
2663
2668
|
)
|
|
2664
2669
|
);
|
|
2665
|
-
return
|
|
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
|
+
);
|
|
2666
2674
|
}).join("")}</details>` : "";
|
|
2667
|
-
const kanjiFormsField = firstKanjiForm ? `${firstKanjiForm}${otherKanjiForms}` : '<span class="word word-kanjiform">(no kanji forms)</span>';
|
|
2675
|
+
const kanjiFormsField = firstKanjiForm !== void 0 ? `${firstKanjiForm}${otherKanjiForms}` : '<span class="word word-kanjiform">(no kanji forms)</span>';
|
|
2668
2676
|
const firstThreeTranslations = entry.translations.slice(0, 3).map(
|
|
2669
|
-
(translationEntry, index) =>
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
void 0
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
)) ? true : void 0
|
|
2678
|
-
);
|
|
2679
|
-
}
|
|
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
|
+
)
|
|
2680
2685
|
).join("");
|
|
2681
2686
|
const otherTranslations = entry.translations.length > 3 ? `<details><summary>Show other translations</summary>${entry.translations.map((translationEntry, index) => {
|
|
2682
|
-
var _a2;
|
|
2683
2687
|
if (index < 3) return "null";
|
|
2684
2688
|
return createEntry(
|
|
2685
2689
|
`<span class="word word-translation">${translationEntry.translation}</span>`,
|
|
2686
2690
|
translationEntry.notes,
|
|
2687
2691
|
void 0,
|
|
2688
|
-
|
|
2689
|
-
(phrase, index2) => index === index2 && phrase.glossNumber && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1
|
|
2690
|
-
)
|
|
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
|
|
2691
2695
|
);
|
|
2692
2696
|
}).filter((translation) => translation !== "null").join("")}</details>` : "";
|
|
2693
2697
|
const translationsField = `${firstThreeTranslations}${otherTranslations}`;
|
|
@@ -2697,7 +2701,7 @@ function generateAnkiNote(entry) {
|
|
|
2697
2701
|
[phraseEntry.translation],
|
|
2698
2702
|
true,
|
|
2699
2703
|
entry.translations.some(
|
|
2700
|
-
(_translation, index2) => index === index2 && phraseEntry.glossNumber && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2704
|
+
(_translation, index2) => index === index2 && phraseEntry.glossNumber !== void 0 && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2701
2705
|
) ? true : void 0
|
|
2702
2706
|
)
|
|
2703
2707
|
).join("");
|
|
@@ -2708,34 +2712,34 @@ function generateAnkiNote(entry) {
|
|
|
2708
2712
|
[phraseEntry.translation],
|
|
2709
2713
|
true,
|
|
2710
2714
|
entry.translations.some(
|
|
2711
|
-
(_translation, index2) => index === index2 && phraseEntry.glossNumber && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2715
|
+
(_translation, index2) => index === index2 && phraseEntry.glossNumber !== void 0 && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2712
2716
|
) ? true : void 0
|
|
2713
2717
|
);
|
|
2714
2718
|
}).filter((phrase) => phrase !== "null").join("")}</details>` : "";
|
|
2715
|
-
const phrasesField = firstFivePhrases ? `${firstFivePhrases}${otherPhrases}` : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>';
|
|
2719
|
+
const phrasesField = firstFivePhrases !== void 0 ? `${firstFivePhrases}${otherPhrases}` : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>';
|
|
2716
2720
|
const firstThreeDefinitions = (_b = entry.definitions) == null ? void 0 : _b.slice(0, 3).map(
|
|
2717
2721
|
(definitionEntry) => createEntry(
|
|
2718
|
-
`<span class="word word-definition${definitionEntry.mayNotBeAccurate ===
|
|
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>`
|
|
2719
2723
|
)
|
|
2720
2724
|
).join("");
|
|
2721
2725
|
const otherDefinitions = entry.definitions !== void 0 && entry.definitions.length > 3 ? `<details><summary>Show other definitions</summary>${entry.definitions.map(
|
|
2722
|
-
(definitionEntry, index) => index > 2 ?
|
|
2723
|
-
`<span class="word word-definition${definitionEntry.mayNotBeAccurate ===
|
|
2724
|
-
)
|
|
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"
|
|
2725
2729
|
).filter((definition) => definition !== "null").join("")}</details>` : "";
|
|
2726
|
-
const definitionsField = firstThreeDefinitions ? `${firstThreeDefinitions}${otherDefinitions}` : '<span class="word word-definition">(no definitions)</span>';
|
|
2730
|
+
const definitionsField = firstThreeDefinitions !== void 0 ? `${firstThreeDefinitions}${otherDefinitions}` : '<span class="word word-definition">(no definitions)</span>';
|
|
2727
2731
|
fields.push(
|
|
2728
|
-
...entry.kanjiForms && !entry.usuallyInKana ? [kanjiFormsField, readingsField] : [readingsField, kanjiFormsField],
|
|
2732
|
+
...entry.kanjiForms !== void 0 && !entry.usuallyInKana ? [kanjiFormsField, readingsField] : [readingsField, kanjiFormsField],
|
|
2729
2733
|
translationsField,
|
|
2730
2734
|
phrasesField,
|
|
2731
2735
|
definitionsField,
|
|
2732
|
-
entry.kanji ? entry.kanji.map(
|
|
2736
|
+
entry.kanji !== void 0 ? entry.kanji.map(
|
|
2733
2737
|
(kanjiEntry) => createEntry(
|
|
2734
2738
|
`<span class="word word-kanji">${kanjiEntry.kanji}${kanjiEntry.meanings === void 0 ? " (no meanings)" : ""}</span>`,
|
|
2735
2739
|
kanjiEntry.meanings
|
|
2736
2740
|
)
|
|
2737
2741
|
).join("") : '<span class="word word-kanji">(no kanji)</span>',
|
|
2738
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2742
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2739
2743
|
entry.tags.map(
|
|
2740
2744
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2741
2745
|
).join(" ")
|
|
@@ -2755,19 +2759,19 @@ function generateAnkiNote(entry) {
|
|
|
2755
2759
|
`<span class="radical radical-meaning">${meaningEntry}</span>`
|
|
2756
2760
|
)
|
|
2757
2761
|
).join(""),
|
|
2758
|
-
entry.mnemonic ? createEntry(
|
|
2762
|
+
entry.mnemonic !== void 0 ? createEntry(
|
|
2759
2763
|
`<span class="radical radical-mnemonic">${entry.mnemonic}</span>`
|
|
2760
2764
|
) : '<span class="radical radical-mnemonic">(no mnemonic) (Come up with your own!)</span>',
|
|
2761
|
-
entry.kanji ? entry.kanji.map(
|
|
2765
|
+
entry.kanji !== void 0 ? entry.kanji.map(
|
|
2762
2766
|
(kanji) => createEntry(
|
|
2763
|
-
`<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>`
|
|
2764
2768
|
)
|
|
2765
2769
|
).join("") : '<span class="radical radical-kanji">(no "used-in" kanji)</span>',
|
|
2766
|
-
entry.strokes ? createEntry(
|
|
2767
|
-
`<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>`
|
|
2768
2772
|
) : '<span class="radical radical-strokes">(no stroke number)</span>',
|
|
2769
|
-
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>',
|
|
2770
|
-
...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 ? [
|
|
2771
2775
|
entry.tags.map(
|
|
2772
2776
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2773
2777
|
).join(" ")
|
|
@@ -2776,44 +2780,44 @@ function generateAnkiNote(entry) {
|
|
|
2776
2780
|
if (isKanji(entry))
|
|
2777
2781
|
fields.push(
|
|
2778
2782
|
createEntry(`<span class="kanji kanji-character">${entry.kanji}</span>`),
|
|
2779
|
-
entry.meanings ? entry.meanings.map(
|
|
2783
|
+
entry.meanings !== void 0 ? entry.meanings.map(
|
|
2780
2784
|
(meaningEntry) => createEntry(
|
|
2781
2785
|
`<span class="kanji kanji-meaning">${meaningEntry}</span>`
|
|
2782
2786
|
)
|
|
2783
2787
|
).join("") : '<span class="kanji kanji-meaning">(no meanings)</span>',
|
|
2784
|
-
entry.onyomi ? entry.onyomi.map(
|
|
2788
|
+
entry.onyomi !== void 0 ? entry.onyomi.map(
|
|
2785
2789
|
(onyomiEntry) => createEntry(
|
|
2786
2790
|
`<span class="kanji kanji-onyomi">${onyomiEntry}</span>`
|
|
2787
2791
|
)
|
|
2788
2792
|
).join("") : `<span class="kanji kanji-onyomi">(no onyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2789
|
-
entry.kunyomi ? entry.kunyomi.map(
|
|
2793
|
+
entry.kunyomi !== void 0 ? entry.kunyomi.map(
|
|
2790
2794
|
(kunyomiEntry) => createEntry(
|
|
2791
2795
|
`<span class="kanji kanji-kunyomi">${kunyomiEntry}</span>`
|
|
2792
2796
|
)
|
|
2793
2797
|
).join("") : `<span class="kanji kanji-kunyomi">(no kunyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2794
|
-
entry.nanori ? entry.nanori.map(
|
|
2798
|
+
entry.nanori !== void 0 ? entry.nanori.map(
|
|
2795
2799
|
(nanoriEntry) => createEntry(
|
|
2796
2800
|
`<span class="kanji kanji-nanori">${nanoriEntry}</span>`
|
|
2797
2801
|
)
|
|
2798
2802
|
).join("") : '<span class="kanji kanji-nanori">(no nanori)</span>',
|
|
2799
|
-
entry.components ? entry.components.map(
|
|
2803
|
+
entry.components !== void 0 ? entry.components.map(
|
|
2800
2804
|
(componentEntry) => createEntry(
|
|
2801
|
-
`<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>`
|
|
2802
2806
|
)
|
|
2803
2807
|
).join("") : '<span class="kanji kanji-component">(no components)</span>',
|
|
2804
|
-
entry.mnemonic ? createEntry(
|
|
2808
|
+
entry.mnemonic !== void 0 ? createEntry(
|
|
2805
2809
|
`<span class="kanji kanji-mnemonic">${entry.mnemonic}</span>`
|
|
2806
2810
|
) : '<span class="kanji kanji-mnemonic">(no mnemonic) (Come up with your own!)</span>',
|
|
2807
|
-
entry.words ? entry.words.map(
|
|
2811
|
+
entry.words !== void 0 ? entry.words.map(
|
|
2808
2812
|
(word) => createEntry(
|
|
2809
|
-
`<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>`
|
|
2810
2814
|
)
|
|
2811
2815
|
).join("") : '<span class="kanji kanji-words">(no words) (Search on dictionaries!)</span>',
|
|
2812
|
-
entry.strokes ? createEntry(
|
|
2813
|
-
`<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>`
|
|
2814
2818
|
) : '<span class="kanji kanji-strokes">(no stroke number)</span>',
|
|
2815
|
-
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>',
|
|
2816
|
-
...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 ? [
|
|
2817
2821
|
entry.tags.map(
|
|
2818
2822
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2819
2823
|
).join(" ")
|
|
@@ -2825,10 +2829,10 @@ function generateAnkiNote(entry) {
|
|
|
2825
2829
|
createEntry(
|
|
2826
2830
|
`<span class="kana kana-reading">${entry.reading}${entry.audio !== void 0 ? `<br>[sound:${entry.audio}]` : ""}</span>`
|
|
2827
2831
|
),
|
|
2828
|
-
entry.svg ? createEntry(
|
|
2832
|
+
entry.svg !== void 0 ? createEntry(
|
|
2829
2833
|
`<img class="kana kana-stroke-order" src="${entry.svg}" alt="${entry.kana} stroke order SVG">`
|
|
2830
2834
|
) : "(no stroke order SVG available)",
|
|
2831
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2835
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2832
2836
|
entry.tags.map(
|
|
2833
2837
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2834
2838
|
).join(" ")
|
|
@@ -2837,28 +2841,28 @@ function generateAnkiNote(entry) {
|
|
|
2837
2841
|
if (isGrammar(entry))
|
|
2838
2842
|
fields.push(
|
|
2839
2843
|
createEntry(`<span class="grammar grammar-point">${entry.point}</span>`),
|
|
2840
|
-
entry.readings ? entry.readings.map(
|
|
2844
|
+
entry.readings !== void 0 ? entry.readings.map(
|
|
2841
2845
|
(readingEntry) => createEntry(
|
|
2842
2846
|
`<span class="grammar grammar-reading">${readingEntry.reading}</span>`
|
|
2843
2847
|
)
|
|
2844
2848
|
).join("") : '<span class="grammar grammar-reading">(no additional readings)</span>',
|
|
2845
2849
|
createEntry(
|
|
2846
|
-
`<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>`
|
|
2847
2851
|
),
|
|
2848
|
-
entry.usages ? entry.usages.map(
|
|
2852
|
+
entry.usages !== void 0 ? entry.usages.map(
|
|
2849
2853
|
(usage) => createEntry(
|
|
2850
2854
|
`<span class="grammar grammar-usage">${usage}</span>`
|
|
2851
2855
|
)
|
|
2852
2856
|
).join("") : '<span class="grammar grammar-usage">(no usages)</span>',
|
|
2853
|
-
entry.phrases ? entry.phrases.map(
|
|
2857
|
+
entry.phrases !== void 0 ? entry.phrases.map(
|
|
2854
2858
|
(phraseEntry) => createEntry(
|
|
2855
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>`,
|
|
2856
2860
|
[phraseEntry.translation],
|
|
2857
2861
|
true
|
|
2858
2862
|
)
|
|
2859
2863
|
).join("") : '<span class="grammar grammar-phrase">(no phrases) (Search on dictionaries!)</span>',
|
|
2860
|
-
entry.source ? `<span class="grammar grammar-source"><a href="${entry.source}" target="_blank">Source</a></span>` : '<span class="grammar grammar-source">(no source)</span>',
|
|
2861
|
-
...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 ? [
|
|
2862
2866
|
entry.tags.map(
|
|
2863
2867
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2864
2868
|
).join(" ")
|
|
@@ -2870,8 +2874,9 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2870
2874
|
const headers = [noteHeaderKeys.separator, noteHeaderKeys.html];
|
|
2871
2875
|
let ankiNotes = "";
|
|
2872
2876
|
if (list.length > 0) {
|
|
2873
|
-
|
|
2874
|
-
|
|
2877
|
+
let noteInfo = {};
|
|
2878
|
+
if (defaultNoteInfo !== void 0) noteInfo = { ...defaultNoteInfo };
|
|
2879
|
+
const infoValues = Object.values(noteInfo);
|
|
2875
2880
|
let invalidList = false;
|
|
2876
2881
|
const firstEntry = list[0];
|
|
2877
2882
|
const firstEntryInfo = {
|
|
@@ -2881,7 +2886,7 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2881
2886
|
};
|
|
2882
2887
|
if (infoValues.length === 0 || infoValues.some((value) => value === true || value === void 0)) {
|
|
2883
2888
|
for (const res of list)
|
|
2884
|
-
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) {
|
|
2885
2890
|
invalidList = true;
|
|
2886
2891
|
break;
|
|
2887
2892
|
}
|
|
@@ -2890,26 +2895,28 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2890
2895
|
const hasHeader = { guid: false, noteType: false, deckPath: false, tags: false };
|
|
2891
2896
|
let headerCount = 0;
|
|
2892
2897
|
ankiNotes = list.filter((result) => result.doNotCreateNote === void 0).map((result) => {
|
|
2893
|
-
if (typeof
|
|
2894
|
-
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;
|
|
2895
2901
|
if (isKanji(result)) result.noteID = result.kanji;
|
|
2896
2902
|
if (isRadical(result)) result.noteID = result.radical;
|
|
2897
2903
|
if (isKana(result)) result.noteID = result.kana;
|
|
2898
|
-
if (isGrammar(result) && result.id
|
|
2904
|
+
if (isGrammar(result) && result.id !== void 0)
|
|
2905
|
+
result.noteID = result.id;
|
|
2899
2906
|
}
|
|
2900
|
-
if (typeof
|
|
2901
|
-
result.noteTypeName =
|
|
2902
|
-
if (typeof
|
|
2903
|
-
result.deckPath =
|
|
2904
|
-
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) {
|
|
2905
2912
|
headers.push(`${noteHeaderKeys.guid}${++headerCount}`);
|
|
2906
2913
|
hasHeader.guid = true;
|
|
2907
2914
|
}
|
|
2908
|
-
if (!hasHeader.noteType && result.noteTypeName) {
|
|
2915
|
+
if (!hasHeader.noteType && result.noteTypeName !== void 0) {
|
|
2909
2916
|
headers.push(`${noteHeaderKeys.notetype}${++headerCount}`);
|
|
2910
2917
|
hasHeader.noteType = true;
|
|
2911
2918
|
}
|
|
2912
|
-
if (!hasHeader.deckPath && result.deckPath) {
|
|
2919
|
+
if (!hasHeader.deckPath && result.deckPath !== void 0) {
|
|
2913
2920
|
headers.push(`${noteHeaderKeys.deck}${++headerCount}`);
|
|
2914
2921
|
hasHeader.deckPath = true;
|
|
2915
2922
|
}
|
|
@@ -2918,7 +2925,7 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2918
2925
|
headers.push(`${noteHeaderKeys.tags}${note.length + headerCount}`);
|
|
2919
2926
|
hasHeader.tags = true;
|
|
2920
2927
|
}
|
|
2921
|
-
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(" ")}`;
|
|
2922
2929
|
}).join("\n").trim();
|
|
2923
2930
|
}
|
|
2924
2931
|
return `${headers.join("\n")}
|
|
@@ -2944,6 +2951,7 @@ export {
|
|
|
2944
2951
|
getWord,
|
|
2945
2952
|
getWordDefinitions,
|
|
2946
2953
|
getWordDefinitionsWithFurigana,
|
|
2954
|
+
hiraganaToKatakana,
|
|
2947
2955
|
isGrammar,
|
|
2948
2956
|
isKana,
|
|
2949
2957
|
isKanji,
|
|
@@ -2952,9 +2960,11 @@ export {
|
|
|
2952
2960
|
isStringArray,
|
|
2953
2961
|
isValidArrayWithFirstElement,
|
|
2954
2962
|
isWord,
|
|
2963
|
+
katakanaToHiragana,
|
|
2955
2964
|
notSearchedForms,
|
|
2956
2965
|
noteHeaderKeys,
|
|
2957
2966
|
noteMap,
|
|
2967
|
+
posList,
|
|
2958
2968
|
regexps,
|
|
2959
2969
|
shuffleArray
|
|
2960
2970
|
};
|