henkan 2.2.5 → 2.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +1 -1
- package/dist/index.cjs.js +596 -604
- package/dist/index.cjs.js.map +3 -3
- package/dist/index.mjs +585 -587
- 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 +13 -9
- 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 +11 -6
- 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/tsconfig.json +60 -0
- package/tsconfig.types.json +9 -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?.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?.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,34 +1501,38 @@ function convertKanjiDic(xmlString) {
|
|
|
1431
1501
|
return dict;
|
|
1432
1502
|
}
|
|
1433
1503
|
function convertTanakaCorpus(tanakaString) {
|
|
1434
|
-
var _a;
|
|
1435
1504
|
const tanakaArray = [];
|
|
1436
1505
|
const tanakaParsed = tanakaString.split("\n");
|
|
1437
1506
|
for (let i = 0; i <= tanakaParsed.length; i += 2) {
|
|
1438
1507
|
let a = tanakaParsed[i];
|
|
1439
1508
|
let b = tanakaParsed[i + 1];
|
|
1440
|
-
if (a && b && a.startsWith("A: ") && b.startsWith("B: ")) {
|
|
1509
|
+
if (a !== void 0 && b !== void 0 && a.startsWith("A: ") && b.startsWith("B: ")) {
|
|
1441
1510
|
a = a.replace("A: ", "");
|
|
1442
1511
|
b = b.replace("B: ", "");
|
|
1443
|
-
const idMatch = regexps.tanakaID.exec(a);
|
|
1512
|
+
const idMatch = regexps.tanakaID.exec(a)?.groups["id"]?.trim();
|
|
1513
|
+
const idParts = String(idMatch).split("_");
|
|
1514
|
+
const id = `${Number(idParts[0])}_${Number(idParts[1])}`;
|
|
1444
1515
|
const aParts = a.replace(regexps.tanakaID, "").split(" ");
|
|
1445
1516
|
const bRawParts = b.split(" ").filter((part) => part.trim().length !== 0);
|
|
1446
1517
|
const bParts = [];
|
|
1447
1518
|
for (const part of bRawParts) {
|
|
1448
1519
|
const partMatches = regexps.tanakaPart.exec(part);
|
|
1449
|
-
const baseForm = partMatches
|
|
1520
|
+
const baseForm = partMatches?.groups["base"];
|
|
1450
1521
|
const examplePart = { baseForm };
|
|
1451
|
-
const reading = partMatches
|
|
1452
|
-
const glossNumber = partMatches
|
|
1453
|
-
const inflectedForm = partMatches
|
|
1454
|
-
if (reading)
|
|
1522
|
+
const reading = partMatches?.groups["reading"];
|
|
1523
|
+
const glossNumber = partMatches?.groups["glossnum"];
|
|
1524
|
+
const inflectedForm = partMatches?.groups["inflection"];
|
|
1525
|
+
if (reading !== void 0)
|
|
1455
1526
|
if (regexps.tanakaReferenceID.test(reading)) {
|
|
1456
1527
|
const referenceID = regexps.tanakaReferenceID.exec(reading);
|
|
1457
|
-
examplePart.referenceID =
|
|
1528
|
+
examplePart.referenceID = `${Number(
|
|
1529
|
+
referenceID?.groups["entryid"]
|
|
1530
|
+
)}`;
|
|
1458
1531
|
} else examplePart.reading = reading;
|
|
1459
|
-
if (glossNumber)
|
|
1532
|
+
if (glossNumber !== void 0)
|
|
1460
1533
|
examplePart.glossNumber = glossNumber.startsWith("0") ? Number.parseInt(glossNumber.substring(1)) : Number.parseInt(glossNumber);
|
|
1461
|
-
if (inflectedForm
|
|
1534
|
+
if (inflectedForm !== void 0)
|
|
1535
|
+
examplePart.inflectedForm = inflectedForm;
|
|
1462
1536
|
if (baseForm.endsWith("~")) {
|
|
1463
1537
|
examplePart.edited = true;
|
|
1464
1538
|
examplePart.baseForm = examplePart.baseForm.replace("~", "");
|
|
@@ -1468,7 +1542,7 @@ function convertTanakaCorpus(tanakaString) {
|
|
|
1468
1542
|
const phrase = aParts[0];
|
|
1469
1543
|
const translation = aParts[1];
|
|
1470
1544
|
tanakaArray.push({
|
|
1471
|
-
id
|
|
1545
|
+
id,
|
|
1472
1546
|
phrase: phrase.trim(),
|
|
1473
1547
|
translation: translation.trim(),
|
|
1474
1548
|
parts: bParts
|
|
@@ -1478,34 +1552,26 @@ function convertTanakaCorpus(tanakaString) {
|
|
|
1478
1552
|
return tanakaArray;
|
|
1479
1553
|
}
|
|
1480
1554
|
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;
|
|
1555
|
+
const tanakaArray = convertTanakaCorpus(tanakaString);
|
|
1556
|
+
const kuroshiro = new Kuroshiro.default();
|
|
1557
|
+
await kuroshiro.init(new KuromojiAnalyzer());
|
|
1558
|
+
const convert = kuroshiro.convert.bind(kuroshiro);
|
|
1559
|
+
for (let i = 0; i < tanakaArray.length; i++)
|
|
1560
|
+
if (!tanakaArray[i].phrase.includes("\u30FB"))
|
|
1561
|
+
tanakaArray[i].furigana = String(
|
|
1562
|
+
await convert(tanakaArray[i].phrase, {
|
|
1563
|
+
to: "hiragana",
|
|
1564
|
+
mode: "furigana"
|
|
1497
1565
|
})
|
|
1498
1566
|
);
|
|
1499
|
-
|
|
1500
|
-
}
|
|
1501
|
-
);
|
|
1567
|
+
return tanakaArray;
|
|
1502
1568
|
}
|
|
1503
1569
|
function convertRadkFile(radkBuffer, kanjiDic) {
|
|
1504
1570
|
const fileParsed = iconv.decode(radkBuffer, "euc-jp").split("\n").filter((line) => !line.startsWith("#"));
|
|
1505
1571
|
const radicals = [];
|
|
1506
1572
|
for (let i = 0; i < fileParsed.length; i++) {
|
|
1507
1573
|
const line = fileParsed[i];
|
|
1508
|
-
if (line && line.startsWith("$ ")) {
|
|
1574
|
+
if (line !== void 0 && line.startsWith("$ ")) {
|
|
1509
1575
|
const radical = {
|
|
1510
1576
|
radical: line.charAt(2).trim(),
|
|
1511
1577
|
strokes: line.substring(4).trim()
|
|
@@ -1513,7 +1579,7 @@ function convertRadkFile(radkBuffer, kanjiDic) {
|
|
|
1513
1579
|
let j = i + 1;
|
|
1514
1580
|
let kanjiLine = fileParsed[j];
|
|
1515
1581
|
const kanjiList = [];
|
|
1516
|
-
while (kanjiLine && !kanjiLine.startsWith("$ ")) {
|
|
1582
|
+
while (kanjiLine !== void 0 && !kanjiLine.startsWith("$ ")) {
|
|
1517
1583
|
const kanjis = kanjiLine.split("");
|
|
1518
1584
|
for (const kanji of kanjis) {
|
|
1519
1585
|
const foundKanji = kanjiDic.find(
|
|
@@ -1524,7 +1590,7 @@ function convertRadkFile(radkBuffer, kanjiDic) {
|
|
|
1524
1590
|
kanjiList.push(kanjiObj);
|
|
1525
1591
|
}
|
|
1526
1592
|
kanjiLine = fileParsed[++j];
|
|
1527
|
-
if (
|
|
1593
|
+
if (kanjiLine === void 0) continue;
|
|
1528
1594
|
if (kanjiLine.startsWith("$ ")) i = j - 1;
|
|
1529
1595
|
}
|
|
1530
1596
|
if (kanjiList.length > 0) radical.kanji = kanjiList;
|
|
@@ -1536,7 +1602,7 @@ function convertRadkFile(radkBuffer, kanjiDic) {
|
|
|
1536
1602
|
function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
1537
1603
|
const fileParsed = iconv.decode(kradBuffer, "euc-jp").split("\n").filter((line) => !line.startsWith("#"));
|
|
1538
1604
|
const kanjiWithRadicals = [];
|
|
1539
|
-
for (const line of fileParsed)
|
|
1605
|
+
for (const line of fileParsed)
|
|
1540
1606
|
if (line.length > 0) {
|
|
1541
1607
|
const split = line.split(" : ");
|
|
1542
1608
|
const kanjiChar = split[0];
|
|
@@ -1551,11 +1617,11 @@ function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
|
1551
1617
|
(dictKanji) => dictKanji.kanji === radical
|
|
1552
1618
|
);
|
|
1553
1619
|
let radicalObj = foundRadical ?? { kanji: radical };
|
|
1554
|
-
if (
|
|
1620
|
+
if (foundRadical === void 0) {
|
|
1555
1621
|
const katakanaChar = katakanaList.find(
|
|
1556
1622
|
(kana) => kana.kana === radical
|
|
1557
1623
|
);
|
|
1558
|
-
if (
|
|
1624
|
+
if (katakanaChar === void 0) continue;
|
|
1559
1625
|
radicalObj = {
|
|
1560
1626
|
kanji: katakanaChar.kana,
|
|
1561
1627
|
readingMeaning: [
|
|
@@ -1575,11 +1641,9 @@ function convertKradFile(kradBuffer, kanjiDic, katakanaList) {
|
|
|
1575
1641
|
if (kanji.kanji.length === 1 && kanji.radicals.length > 0)
|
|
1576
1642
|
kanjiWithRadicals.push(kanji);
|
|
1577
1643
|
}
|
|
1578
|
-
}
|
|
1579
1644
|
return kanjiWithRadicals;
|
|
1580
1645
|
}
|
|
1581
1646
|
function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs, svgList) {
|
|
1582
|
-
var _a;
|
|
1583
1647
|
const kanjiEntryMap = /* @__PURE__ */ new Map();
|
|
1584
1648
|
const wordIDEntryMap = /* @__PURE__ */ new Map();
|
|
1585
1649
|
const kanjiWordsMap = /* @__PURE__ */ new Map();
|
|
@@ -1589,30 +1653,29 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1589
1653
|
const wordPartsMap = /* @__PURE__ */ new Map();
|
|
1590
1654
|
const partExamplesMap = /* @__PURE__ */ new Map();
|
|
1591
1655
|
const entryParts = /* @__PURE__ */ new Set();
|
|
1592
|
-
if (kanjiDic)
|
|
1656
|
+
if (kanjiDic !== void 0)
|
|
1593
1657
|
for (const kanji of kanjiDic) kanjiEntryMap.set(kanji.kanji, kanji);
|
|
1594
|
-
if (wordDefinitionPairs)
|
|
1658
|
+
if (wordDefinitionPairs !== void 0)
|
|
1595
1659
|
for (const pair of wordDefinitionPairs)
|
|
1596
1660
|
wordDefinitionsMap.set(pair.wordID, pair.definitions);
|
|
1597
|
-
if (kanjiDic && svgList)
|
|
1661
|
+
if (kanjiDic !== void 0 && svgList !== void 0)
|
|
1598
1662
|
for (const kanji of kanjiDic) {
|
|
1599
1663
|
const codePoint = kanji.kanji.codePointAt(0).toString(16).toLowerCase();
|
|
1600
1664
|
const svg = svgList.find((file) => {
|
|
1601
1665
|
const baseName = file.split(".")[0].toLowerCase();
|
|
1602
1666
|
return baseName === codePoint || baseName === `0${codePoint}`;
|
|
1603
1667
|
});
|
|
1604
|
-
if (svg) kanjiSVGMap.set(kanji.kanji, svg);
|
|
1668
|
+
if (svg !== void 0) kanjiSVGMap.set(kanji.kanji, svg);
|
|
1605
1669
|
}
|
|
1606
|
-
if (jmDict) {
|
|
1670
|
+
if (jmDict !== void 0) {
|
|
1607
1671
|
for (const word of jmDict) {
|
|
1608
1672
|
wordIDEntryMap.set(word.id, word);
|
|
1609
|
-
if (word.kanjiForms)
|
|
1673
|
+
if (word.kanjiForms !== void 0)
|
|
1610
1674
|
for (const kf of word.kanjiForms)
|
|
1611
|
-
for (const char of kf.form.split("").filter((c) => regexps.kanji.test(c)))
|
|
1675
|
+
for (const char of kf.form.split("").filter((c) => regexps.kanji.test(c)))
|
|
1612
1676
|
if (!kanjiWordsMap.has(char)) kanjiWordsMap.set(char, [word]);
|
|
1613
1677
|
else kanjiWordsMap.get(char).push(word);
|
|
1614
|
-
|
|
1615
|
-
if (tanakaExamples) {
|
|
1678
|
+
if (tanakaExamples !== void 0) {
|
|
1616
1679
|
const rkf = getValidForms(
|
|
1617
1680
|
word.readings,
|
|
1618
1681
|
word.kanjiForms,
|
|
@@ -1623,7 +1686,7 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1623
1686
|
entryParts.add(reading.reading);
|
|
1624
1687
|
localPartParts.add(reading.reading);
|
|
1625
1688
|
}
|
|
1626
|
-
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1689
|
+
if (rkf.kanjiForms !== void 0 && rkf.kanjiForms.length > 0)
|
|
1627
1690
|
for (const kanjiForm of rkf.kanjiForms) {
|
|
1628
1691
|
entryParts.add(kanjiForm.form);
|
|
1629
1692
|
localPartParts.add(kanjiForm.form);
|
|
@@ -1633,58 +1696,56 @@ function createEntryMaps(jmDict, kanjiDic, tanakaExamples, wordDefinitionPairs,
|
|
|
1633
1696
|
wordPartsMap.set(word.id, localPartParts);
|
|
1634
1697
|
}
|
|
1635
1698
|
}
|
|
1636
|
-
if (tanakaExamples) {
|
|
1637
|
-
for (const ex of tanakaExamples)
|
|
1699
|
+
if (tanakaExamples !== void 0) {
|
|
1700
|
+
for (const ex of tanakaExamples)
|
|
1638
1701
|
for (const part of ex.parts) {
|
|
1639
1702
|
if (entryParts.has(part.baseForm)) {
|
|
1640
1703
|
let exList = partExamplesMap.get(
|
|
1641
1704
|
part.baseForm
|
|
1642
1705
|
);
|
|
1643
|
-
if (
|
|
1706
|
+
if (exList === void 0) {
|
|
1644
1707
|
exList = [];
|
|
1645
1708
|
partExamplesMap.set(part.baseForm, exList);
|
|
1646
1709
|
}
|
|
1647
1710
|
exList.push(ex);
|
|
1648
1711
|
}
|
|
1649
|
-
if (part.reading && entryParts.has(part.reading)) {
|
|
1712
|
+
if (part.reading !== void 0 && entryParts.has(part.reading)) {
|
|
1650
1713
|
let exList = partExamplesMap.get(
|
|
1651
1714
|
part.reading
|
|
1652
1715
|
);
|
|
1653
|
-
if (
|
|
1716
|
+
if (exList === void 0) {
|
|
1654
1717
|
exList = [];
|
|
1655
1718
|
partExamplesMap.set(part.reading, exList);
|
|
1656
1719
|
}
|
|
1657
1720
|
exList.push(ex);
|
|
1658
1721
|
}
|
|
1659
|
-
if (part.inflectedForm && entryParts.has(part.inflectedForm)) {
|
|
1722
|
+
if (part.inflectedForm !== void 0 && entryParts.has(part.inflectedForm)) {
|
|
1660
1723
|
let exList = partExamplesMap.get(
|
|
1661
1724
|
part.inflectedForm
|
|
1662
1725
|
);
|
|
1663
|
-
if (
|
|
1726
|
+
if (exList === void 0) {
|
|
1664
1727
|
exList = [];
|
|
1665
1728
|
partExamplesMap.set(part.inflectedForm, exList);
|
|
1666
1729
|
}
|
|
1667
1730
|
exList.push(ex);
|
|
1668
1731
|
}
|
|
1669
|
-
if (part.referenceID && entryParts.has(part.referenceID)) {
|
|
1732
|
+
if (part.referenceID !== void 0 && entryParts.has(part.referenceID)) {
|
|
1670
1733
|
let exList = partExamplesMap.get(
|
|
1671
1734
|
part.referenceID
|
|
1672
1735
|
);
|
|
1673
|
-
if (
|
|
1736
|
+
if (exList === void 0) {
|
|
1674
1737
|
exList = [];
|
|
1675
1738
|
partExamplesMap.set(part.referenceID, exList);
|
|
1676
1739
|
}
|
|
1677
1740
|
exList.push(ex);
|
|
1678
1741
|
}
|
|
1679
1742
|
}
|
|
1680
|
-
}
|
|
1681
1743
|
for (const word of jmDict) {
|
|
1682
|
-
const entryParts2 = wordPartsMap.get(word.id);
|
|
1683
1744
|
const seenEx = /* @__PURE__ */ new Set();
|
|
1684
1745
|
const validExamples = [];
|
|
1685
|
-
for (const p of
|
|
1686
|
-
const examplesForPart =
|
|
1687
|
-
if (
|
|
1746
|
+
for (const p of wordPartsMap.get(word.id)) {
|
|
1747
|
+
const examplesForPart = partExamplesMap.get(p)?.filter((ex) => !seenEx.has(ex.id));
|
|
1748
|
+
if (examplesForPart === void 0) continue;
|
|
1688
1749
|
for (const ex of examplesForPart) {
|
|
1689
1750
|
seenEx.add(ex.id);
|
|
1690
1751
|
validExamples.push(ex);
|
|
@@ -1709,49 +1770,43 @@ function mapEntry(entry) {
|
|
|
1709
1770
|
word: entry.word,
|
|
1710
1771
|
pos_title: entry.pos_title,
|
|
1711
1772
|
senses: entry.senses.filter(
|
|
1712
|
-
(sense) => isObjectArray(sense.form_of)
|
|
1713
|
-
(form) => form.word && typeof form.word === "string"
|
|
1714
|
-
) || isStringArray(sense.glosses)
|
|
1773
|
+
(sense) => (isObjectArray(sense.form_of) ? sense.form_of.every((form) => typeof form.word === "string") : isStringArray(sense.glosses)) === true || isStringArray(sense.glosses)
|
|
1715
1774
|
).map((sense) => ({
|
|
1716
|
-
...sense.form_of ? {
|
|
1717
|
-
form_of: sense.form_of.map((form) => form.word)
|
|
1775
|
+
...isObjectArray(sense.form_of) ? {
|
|
1776
|
+
form_of: sense.form_of.map((form) => String(form.word))
|
|
1718
1777
|
} : {},
|
|
1719
1778
|
glosses: sense.glosses
|
|
1720
1779
|
})),
|
|
1721
|
-
...isObjectArray(entry.forms) && entry.forms.every((form) => typeof form.form === "string") ? { forms: entry.forms.map((form) => form.form) } : {}
|
|
1780
|
+
...isObjectArray(entry.forms) && entry.forms.every((form) => typeof form.form === "string") === true ? { forms: entry.forms.map((form) => String(form.form)) } : {}
|
|
1722
1781
|
};
|
|
1723
1782
|
}
|
|
1724
1783
|
function convertJawiktionarySync(buffer) {
|
|
1725
1784
|
const lines = buffer.toString("utf-8").split("\n");
|
|
1726
1785
|
const entries = [];
|
|
1727
1786
|
for (let i = 0; i < lines.length; i++) {
|
|
1728
|
-
const line = lines[i];
|
|
1729
|
-
if (
|
|
1787
|
+
const line = lines[i]?.trim();
|
|
1788
|
+
if (line === void 0 || line.length === 0) continue;
|
|
1730
1789
|
const obj = JSON.parse(line);
|
|
1731
|
-
if (
|
|
1790
|
+
if (typeof obj === "object" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
1732
1791
|
entries.push(mapEntry(obj));
|
|
1733
1792
|
}
|
|
1734
1793
|
return entries;
|
|
1735
1794
|
}
|
|
1736
1795
|
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
|
-
);
|
|
1796
|
+
const rl = createInterface({
|
|
1797
|
+
input: stream,
|
|
1798
|
+
crlfDelay: Infinity
|
|
1799
|
+
});
|
|
1800
|
+
const entries = [];
|
|
1801
|
+
for await (const line of rl) {
|
|
1802
|
+
const obj = JSON.parse(line.trim());
|
|
1803
|
+
if (typeof obj === "object" && (obj.lang === "\u65E5\u672C\u8A9E" || obj.lang === "\u53E4\u5178\u65E5\u672C\u8A9E"))
|
|
1804
|
+
entries.push(mapEntry(obj));
|
|
1805
|
+
}
|
|
1806
|
+
rl.close();
|
|
1807
|
+
stream.close();
|
|
1808
|
+
stream.destroy();
|
|
1809
|
+
return entries;
|
|
1755
1810
|
}
|
|
1756
1811
|
function parseEntry(entry, definitions, definitionMap) {
|
|
1757
1812
|
for (const sense of entry.senses) {
|
|
@@ -1764,12 +1819,11 @@ function parseEntry(entry, definitions, definitionMap) {
|
|
|
1764
1819
|
}
|
|
1765
1820
|
}
|
|
1766
1821
|
}
|
|
1767
|
-
function getWordDefinitions(
|
|
1768
|
-
var _a, _b, _c, _d, _e;
|
|
1822
|
+
function getWordDefinitions(wiktionaryEntries, jmDict) {
|
|
1769
1823
|
const entries = /* @__PURE__ */ new Map();
|
|
1770
|
-
for (const entry of
|
|
1824
|
+
for (const entry of wiktionaryEntries) {
|
|
1771
1825
|
const ent = entries.get(entry.word);
|
|
1772
|
-
if (ent) ent.push(entry);
|
|
1826
|
+
if (ent !== void 0) ent.push(entry);
|
|
1773
1827
|
else entries.set(entry.word, [entry]);
|
|
1774
1828
|
}
|
|
1775
1829
|
const japaneseDefinitions = [];
|
|
@@ -1783,15 +1837,14 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1783
1837
|
const wordKanjiForms = /* @__PURE__ */ new Set();
|
|
1784
1838
|
const rkf = getValidForms(
|
|
1785
1839
|
word.readings,
|
|
1786
|
-
word.kanjiForms
|
|
1787
|
-
word.isCommon
|
|
1840
|
+
word.kanjiForms
|
|
1788
1841
|
);
|
|
1789
1842
|
for (const r of rkf.readings) {
|
|
1790
1843
|
validReadings.add(r.reading);
|
|
1791
1844
|
wordReadings.add(r.reading);
|
|
1792
1845
|
validForms.add(r.reading);
|
|
1793
1846
|
}
|
|
1794
|
-
if (rkf.kanjiForms && rkf.kanjiForms.length > 0)
|
|
1847
|
+
if (rkf.kanjiForms !== void 0 && rkf.kanjiForms.length > 0)
|
|
1795
1848
|
for (const kf of rkf.kanjiForms) {
|
|
1796
1849
|
validKanjiForms.add(kf.form);
|
|
1797
1850
|
wordKanjiForms.add(kf.form);
|
|
@@ -1811,24 +1864,22 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1811
1864
|
const ents = Array.from(entries.values()).flat();
|
|
1812
1865
|
for (const entry of ents) {
|
|
1813
1866
|
let valid = false;
|
|
1814
|
-
if (validKanjiForms
|
|
1867
|
+
if (validKanjiForms.has(entry.word)) {
|
|
1815
1868
|
valid = true;
|
|
1816
1869
|
for (const sense of entry.senses) {
|
|
1817
|
-
if (sense.form_of && sense.form_of.some((form) => validForms.has(form)))
|
|
1870
|
+
if (sense.form_of !== void 0 && sense.form_of.some((form) => validForms.has(form)))
|
|
1818
1871
|
validFormOfEntries.add(entry.word);
|
|
1819
1872
|
for (const gloss of sense.glosses) {
|
|
1820
1873
|
let hasForm = false;
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
}
|
|
1827
|
-
}
|
|
1874
|
+
for (const r of validForms)
|
|
1875
|
+
if (gloss.includes(r)) {
|
|
1876
|
+
hasForm = true;
|
|
1877
|
+
break;
|
|
1878
|
+
}
|
|
1828
1879
|
if (hasForm) validGlossesEntries.add(entry.word);
|
|
1829
1880
|
}
|
|
1830
1881
|
}
|
|
1831
|
-
if (entry.forms) {
|
|
1882
|
+
if (entry.forms !== void 0) {
|
|
1832
1883
|
for (const form of entry.forms)
|
|
1833
1884
|
if (validForms.has(form)) validFormsEntries.add(entry.word);
|
|
1834
1885
|
}
|
|
@@ -1836,17 +1887,19 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1836
1887
|
if (validForms.has(entry.word)) {
|
|
1837
1888
|
valid = true;
|
|
1838
1889
|
const ftEntry = entriesWithFormTitlesGlobal.get(entry.word);
|
|
1839
|
-
if (ftEntry) ftEntry.push(entry);
|
|
1890
|
+
if (ftEntry !== void 0) ftEntry.push(entry);
|
|
1840
1891
|
else entriesWithFormTitlesGlobal.set(entry.word, [entry]);
|
|
1841
1892
|
}
|
|
1842
1893
|
if (valid) {
|
|
1843
|
-
const tEntry = validTitleEntries.get(
|
|
1844
|
-
|
|
1894
|
+
const tEntry = validTitleEntries.get(
|
|
1895
|
+
entry.word
|
|
1896
|
+
);
|
|
1897
|
+
if (tEntry !== void 0) tEntry.push(entry);
|
|
1845
1898
|
else validTitleEntries.set(entry.word, [entry]);
|
|
1846
1899
|
}
|
|
1847
|
-
if (entry.forms && validForms.has(entry.word) && entry.forms.some((form) => validForms.has(form))) {
|
|
1900
|
+
if (entry.forms !== void 0 && validForms.has(entry.word) && entry.forms.some((form) => validForms.has(form))) {
|
|
1848
1901
|
const wfEntry = entriesWithFormsGlobal.get(entry.word);
|
|
1849
|
-
if (wfEntry) wfEntry.push(entry);
|
|
1902
|
+
if (wfEntry !== void 0) wfEntry.push(entry);
|
|
1850
1903
|
else entriesWithFormsGlobal.set(entry.word, [entry]);
|
|
1851
1904
|
}
|
|
1852
1905
|
}
|
|
@@ -1861,53 +1914,17 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1861
1914
|
const wfe = Array.from(
|
|
1862
1915
|
entriesWithFormsGlobal.values()
|
|
1863
1916
|
).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
|
-
]) {
|
|
1917
|
+
for (const pos of posList) {
|
|
1901
1918
|
posMap.set(pos, {});
|
|
1902
1919
|
for (const te of vte)
|
|
1903
1920
|
if (te.pos_title === pos || te.pos_title === "\u548C\u8A9E\u306E\u6F22\u5B57\u8868\u8A18") {
|
|
1904
1921
|
const posEntries = posMap.get(pos);
|
|
1905
1922
|
if (posEntries.title === void 0)
|
|
1906
1923
|
posEntries.title = /* @__PURE__ */ new Map();
|
|
1907
|
-
const
|
|
1924
|
+
const entryList = posEntries.title.get(
|
|
1908
1925
|
te.word
|
|
1909
1926
|
);
|
|
1910
|
-
if (
|
|
1927
|
+
if (entryList !== void 0) entryList.push(te);
|
|
1911
1928
|
else posEntries.title.set(te.word, [te]);
|
|
1912
1929
|
}
|
|
1913
1930
|
for (const ft of fge)
|
|
@@ -1915,8 +1932,8 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1915
1932
|
const posEntries = posMap.get(pos);
|
|
1916
1933
|
if (posEntries.formTitle === void 0)
|
|
1917
1934
|
posEntries.formTitle = /* @__PURE__ */ new Map();
|
|
1918
|
-
const
|
|
1919
|
-
if (
|
|
1935
|
+
const entryList = posEntries.formTitle.get(ft.word);
|
|
1936
|
+
if (entryList !== void 0) entryList.push(ft);
|
|
1920
1937
|
else posEntries.formTitle.set(ft.word, [ft]);
|
|
1921
1938
|
}
|
|
1922
1939
|
for (const wf of wfe)
|
|
@@ -1924,10 +1941,10 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1924
1941
|
const posEntries = posMap.get(pos);
|
|
1925
1942
|
if (posEntries.form === void 0)
|
|
1926
1943
|
posEntries.form = /* @__PURE__ */ new Map();
|
|
1927
|
-
const
|
|
1944
|
+
const entryList = posEntries.form.get(
|
|
1928
1945
|
wf.word
|
|
1929
1946
|
);
|
|
1930
|
-
if (
|
|
1947
|
+
if (entryList !== void 0) entryList.push(wf);
|
|
1931
1948
|
else posEntries.form.set(wf.word, [wf]);
|
|
1932
1949
|
}
|
|
1933
1950
|
}
|
|
@@ -1940,7 +1957,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1940
1957
|
for (const m of word.meanings)
|
|
1941
1958
|
for (const note of m.partOfSpeech) {
|
|
1942
1959
|
const noteEntry = noteMap.get(note);
|
|
1943
|
-
if (noteEntry
|
|
1960
|
+
if (noteEntry?.length === 3) {
|
|
1944
1961
|
const notePos = noteEntry[2];
|
|
1945
1962
|
if (Array.isArray(notePos))
|
|
1946
1963
|
for (const pos of notePos) {
|
|
@@ -1957,76 +1974,64 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
1957
1974
|
if (poses.size > 0)
|
|
1958
1975
|
for (const pos of poses) {
|
|
1959
1976
|
const posEntries = posMap.get(pos);
|
|
1960
|
-
if (rkf.kanjiForms)
|
|
1977
|
+
if (rkf.kanjiForms !== void 0)
|
|
1961
1978
|
for (const kf of rkf.kanjiForms) {
|
|
1962
|
-
const te =
|
|
1963
|
-
const fe =
|
|
1964
|
-
if (te)
|
|
1979
|
+
const te = posEntries.title?.get(kf);
|
|
1980
|
+
const fe = posEntries.form?.get(kf);
|
|
1981
|
+
if (te !== void 0)
|
|
1965
1982
|
entriesWithTitles.push(
|
|
1966
1983
|
...te.filter(
|
|
1967
1984
|
(ent) => validFormOfEntries.has(ent.word) || validGlossesEntries.has(ent.word) || validFormsEntries.has(ent.word)
|
|
1968
1985
|
)
|
|
1969
1986
|
);
|
|
1970
|
-
if (fe)
|
|
1987
|
+
if (fe !== void 0)
|
|
1971
1988
|
entriesWithForms.push(
|
|
1972
1989
|
...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
|
-
}
|
|
1990
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
1991
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1978
1992
|
)
|
|
1979
1993
|
)
|
|
1980
1994
|
);
|
|
1981
1995
|
}
|
|
1982
1996
|
for (const r of rkf.readings) {
|
|
1983
|
-
const te =
|
|
1984
|
-
const fe =
|
|
1985
|
-
const fte =
|
|
1986
|
-
if (te)
|
|
1997
|
+
const te = posEntries.title?.get(r);
|
|
1998
|
+
const fe = posEntries.form?.get(r);
|
|
1999
|
+
const fte = posEntries.formTitle?.get(r);
|
|
2000
|
+
if (te !== void 0)
|
|
1987
2001
|
entriesWithTitles.push(
|
|
1988
2002
|
...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
|
-
}
|
|
2003
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2004
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
1994
2005
|
)
|
|
1995
2006
|
)
|
|
1996
2007
|
);
|
|
1997
|
-
if (fe)
|
|
2008
|
+
if (fe !== void 0)
|
|
1998
2009
|
entriesWithForms.push(
|
|
1999
2010
|
...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
|
-
}
|
|
2011
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2012
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2005
2013
|
)
|
|
2006
2014
|
)
|
|
2007
2015
|
);
|
|
2008
|
-
if (fte) entriesWithFormTitles.push(...fte);
|
|
2016
|
+
if (fte !== void 0) entriesWithFormTitles.push(...fte);
|
|
2009
2017
|
}
|
|
2010
2018
|
}
|
|
2011
2019
|
if (entriesWithTitles.length === 0 && entriesWithFormTitles.length === 0 && entriesWithForms.length === 0) {
|
|
2012
|
-
if (rkf.kanjiForms)
|
|
2020
|
+
if (rkf.kanjiForms !== void 0)
|
|
2013
2021
|
for (const kf of rkf.kanjiForms) {
|
|
2014
2022
|
const te = validTitleEntries.get(kf);
|
|
2015
2023
|
const fe = entriesWithFormsGlobal.get(kf);
|
|
2016
|
-
if (te)
|
|
2024
|
+
if (te !== void 0)
|
|
2017
2025
|
entriesWithTitles.push(
|
|
2018
2026
|
...te.filter(
|
|
2019
2027
|
(ent) => validFormOfEntries.has(ent.word) || validGlossesEntries.has(ent.word) || validFormsEntries.has(ent.word)
|
|
2020
2028
|
)
|
|
2021
2029
|
);
|
|
2022
|
-
if (fe)
|
|
2030
|
+
if (fe !== void 0)
|
|
2023
2031
|
entriesWithForms.push(
|
|
2024
2032
|
...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
|
-
}
|
|
2033
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2034
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2030
2035
|
)
|
|
2031
2036
|
)
|
|
2032
2037
|
);
|
|
@@ -2035,37 +2040,31 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2035
2040
|
const te = validTitleEntries.get(r);
|
|
2036
2041
|
const fe = entriesWithFormsGlobal.get(r);
|
|
2037
2042
|
const fte = entriesWithFormTitlesGlobal.get(r);
|
|
2038
|
-
if (te)
|
|
2043
|
+
if (te !== void 0)
|
|
2039
2044
|
entriesWithTitles.push(
|
|
2040
2045
|
...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
|
-
}
|
|
2046
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2047
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2046
2048
|
)
|
|
2047
2049
|
)
|
|
2048
2050
|
);
|
|
2049
|
-
if (fe)
|
|
2051
|
+
if (fe !== void 0)
|
|
2050
2052
|
entriesWithForms.push(
|
|
2051
2053
|
...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
|
-
}
|
|
2054
|
+
(ent) => ent.forms !== void 0 && ent.forms.some(
|
|
2055
|
+
(form) => rkf.kanjiForms !== void 0 && rkf.kanjiForms.has(form) || rkf.readings.has(form)
|
|
2057
2056
|
)
|
|
2058
2057
|
)
|
|
2059
2058
|
);
|
|
2060
|
-
if (fte) entriesWithFormTitles.push(...fte);
|
|
2059
|
+
if (fte !== void 0) entriesWithFormTitles.push(...fte);
|
|
2061
2060
|
}
|
|
2062
2061
|
}
|
|
2063
2062
|
if (entriesWithTitles.length > 0 && (entriesWithFormTitles.length > 0 || entriesWithForms.length > 0))
|
|
2064
2063
|
wordEntriesPairs.push({
|
|
2065
2064
|
word,
|
|
2066
2065
|
readings: rkf.readings,
|
|
2067
|
-
...rkf.kanjiForms ? { kanjiForms: rkf.kanjiForms } : {},
|
|
2068
|
-
forms: rkf.kanjiForms ? rkf.readings.union(rkf.kanjiForms) : rkf.readings,
|
|
2066
|
+
...rkf.kanjiForms !== void 0 ? { kanjiForms: rkf.kanjiForms } : {},
|
|
2067
|
+
forms: rkf.kanjiForms !== void 0 ? rkf.readings.union(rkf.kanjiForms) : rkf.readings,
|
|
2069
2068
|
entriesWithTitles,
|
|
2070
2069
|
entriesWithFormTitles,
|
|
2071
2070
|
entriesWithForms
|
|
@@ -2080,36 +2079,31 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2080
2079
|
const refsMap = /* @__PURE__ */ new Map();
|
|
2081
2080
|
const forms = /* @__PURE__ */ new Set();
|
|
2082
2081
|
for (const ent of pair.entriesWithTitles) {
|
|
2083
|
-
const
|
|
2084
|
-
const
|
|
2085
|
-
const validForms2 = validFormsEntries.has(ent.word);
|
|
2082
|
+
const hasValidFormOf = validFormOfEntries.has(ent.word);
|
|
2083
|
+
const hasValidForms = validFormsEntries.has(ent.word);
|
|
2086
2084
|
const hasForms = ent.forms !== void 0 && ent.forms.some((form) => pair.forms.has(form));
|
|
2087
|
-
if (pair.kanjiForms && pair.kanjiForms.has(ent.word)
|
|
2085
|
+
if (pair.kanjiForms !== void 0 && pair.kanjiForms.has(ent.word)) {
|
|
2088
2086
|
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
|
-
}
|
|
2087
|
+
for (const sense of ent.senses) {
|
|
2088
|
+
if (hasValidFormOf && sense.form_of !== void 0) {
|
|
2089
|
+
for (const form of sense.form_of)
|
|
2090
|
+
if (pair.forms.has(form)) {
|
|
2091
|
+
const elem = titleFormMap.get(form);
|
|
2092
|
+
if (elem === void 0)
|
|
2093
|
+
titleFormMap.set(form, /* @__PURE__ */ new Set([ent.word]));
|
|
2094
|
+
else elem.add(ent.word);
|
|
2095
|
+
}
|
|
2111
2096
|
}
|
|
2112
|
-
|
|
2097
|
+
for (const gloss of sense.glosses)
|
|
2098
|
+
for (const f of pair.forms)
|
|
2099
|
+
if (gloss.includes(f)) {
|
|
2100
|
+
const elem = refsMap.get(f);
|
|
2101
|
+
if (elem === void 0)
|
|
2102
|
+
refsMap.set(f, /* @__PURE__ */ new Set([ent.word]));
|
|
2103
|
+
else elem.add(ent.word);
|
|
2104
|
+
}
|
|
2105
|
+
}
|
|
2106
|
+
if (hasValidForms && ent.forms !== void 0) {
|
|
2113
2107
|
for (const form of ent.forms)
|
|
2114
2108
|
if (pair.forms.has(form)) forms.add(form);
|
|
2115
2109
|
}
|
|
@@ -2120,7 +2114,7 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2120
2114
|
}
|
|
2121
2115
|
for (const entry of pair.entriesWithForms) {
|
|
2122
2116
|
const elem = titleFormMap.get(entry.word);
|
|
2123
|
-
if (elem && entry.forms && entry.forms.some((form) => elem.has(form)))
|
|
2117
|
+
if (elem !== void 0 && entry.forms !== void 0 && entry.forms.some((form) => elem.has(form)))
|
|
2124
2118
|
entriesWithForms.push(entry);
|
|
2125
2119
|
}
|
|
2126
2120
|
for (const entry of pair.entriesWithFormTitles) {
|
|
@@ -2129,7 +2123,8 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2129
2123
|
continue;
|
|
2130
2124
|
}
|
|
2131
2125
|
const ft = refsMap.get(entry.word);
|
|
2132
|
-
if (ft && !ft.isDisjointFrom(pair.forms))
|
|
2126
|
+
if (ft !== void 0 && !ft.isDisjointFrom(pair.forms))
|
|
2127
|
+
entriesWithForms.push(entry);
|
|
2133
2128
|
}
|
|
2134
2129
|
if (kanjiFormEntries.length > 0) {
|
|
2135
2130
|
for (const entry of kanjiFormEntries)
|
|
@@ -2146,7 +2141,14 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2146
2141
|
japaneseDefinitions.push({
|
|
2147
2142
|
wordID: pair.word.id,
|
|
2148
2143
|
definitions,
|
|
2149
|
-
wordForms: pair.forms
|
|
2144
|
+
wordForms: pair.forms.union(
|
|
2145
|
+
new Set(
|
|
2146
|
+
pair.forms.values().toArray().flatMap((form) => [
|
|
2147
|
+
hiraganaToKatakana(form),
|
|
2148
|
+
katakanaToHiragana(form)
|
|
2149
|
+
])
|
|
2150
|
+
)
|
|
2151
|
+
)
|
|
2150
2152
|
});
|
|
2151
2153
|
}
|
|
2152
2154
|
for (let i = 0; i < japaneseDefinitions.length; i++) {
|
|
@@ -2155,14 +2157,14 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2155
2157
|
const defCount = definitionMap.get(
|
|
2156
2158
|
pair.definitions[j].definition
|
|
2157
2159
|
);
|
|
2158
|
-
if (defCount && defCount.count > 1) {
|
|
2160
|
+
if (defCount !== void 0 && defCount.count > 1) {
|
|
2159
2161
|
let mnba = true;
|
|
2160
2162
|
for (const f of pair.wordForms)
|
|
2161
2163
|
if (pair.definitions[j].definition.includes(f)) {
|
|
2162
2164
|
mnba = false;
|
|
2163
2165
|
break;
|
|
2164
2166
|
}
|
|
2165
|
-
|
|
2167
|
+
pair.definitions[j].mayNotBeAccurate = mnba ? 2 : 1;
|
|
2166
2168
|
}
|
|
2167
2169
|
}
|
|
2168
2170
|
delete pair.wordForms;
|
|
@@ -2171,33 +2173,30 @@ function getWordDefinitions(entryList, jmDict) {
|
|
|
2171
2173
|
return japaneseDefinitions;
|
|
2172
2174
|
}
|
|
2173
2175
|
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
|
-
});
|
|
2176
|
+
const japaneseDefinitions = getWordDefinitions(
|
|
2177
|
+
entryList,
|
|
2178
|
+
jmDict
|
|
2179
|
+
);
|
|
2180
|
+
const kuroshiro = new Kuroshiro.default();
|
|
2181
|
+
await kuroshiro.init(new KuromojiAnalyzer());
|
|
2182
|
+
const convert = kuroshiro.convert.bind(kuroshiro);
|
|
2183
|
+
for (let i = 0; i < japaneseDefinitions.length; i++) {
|
|
2184
|
+
const pair = japaneseDefinitions[i];
|
|
2185
|
+
for (let j = 0; j < pair.definitions.length; j++)
|
|
2186
|
+
if (!pair.definitions[j].definition.includes("\u30FB"))
|
|
2187
|
+
pair.definitions[j].furigana = String(
|
|
2188
|
+
await convert(pair.definitions[j].definition, {
|
|
2189
|
+
to: "hiragana",
|
|
2190
|
+
mode: "furigana"
|
|
2191
|
+
})
|
|
2192
|
+
);
|
|
2193
|
+
japaneseDefinitions[i] = pair;
|
|
2194
|
+
}
|
|
2195
|
+
return japaneseDefinitions;
|
|
2197
2196
|
}
|
|
2198
2197
|
function lookupWordNote(key, notes, tags) {
|
|
2199
2198
|
const info = noteMap.get(key.toLowerCase());
|
|
2200
|
-
if (
|
|
2199
|
+
if (info === void 0) {
|
|
2201
2200
|
notes.push(key);
|
|
2202
2201
|
return { note: key };
|
|
2203
2202
|
}
|
|
@@ -2207,22 +2206,170 @@ function lookupWordNote(key, notes, tags) {
|
|
|
2207
2206
|
return { note: info[1], tag };
|
|
2208
2207
|
}
|
|
2209
2208
|
var wordAddNoteArray = (arr, cb) => {
|
|
2210
|
-
if (
|
|
2209
|
+
if (arr === void 0) return;
|
|
2211
2210
|
for (const v of arr) cb(v);
|
|
2212
2211
|
};
|
|
2213
|
-
function
|
|
2214
|
-
|
|
2212
|
+
function getKanji(searchedKanji, dict, jmDict, svgList, noteTypeName, deckPath) {
|
|
2213
|
+
let dictKanji = void 0;
|
|
2214
|
+
if (typeof searchedKanji === "string" && dict !== void 0)
|
|
2215
|
+
dictKanji = dict instanceof Map ? dict.get(searchedKanji) : dict.find((entry) => entry.kanji === searchedKanji);
|
|
2216
|
+
else if (typeof searchedKanji === "object") dictKanji = searchedKanji;
|
|
2217
|
+
if (dictKanji !== void 0) {
|
|
2218
|
+
const kanji = {
|
|
2219
|
+
kanji: dictKanji.kanji,
|
|
2220
|
+
strokes: dictKanji.misc.strokeNumber,
|
|
2221
|
+
...dictKanji.misc?.grade !== void 0 ? { grade: dictKanji.misc.grade } : {},
|
|
2222
|
+
...dictKanji.misc?.frequency !== void 0 ? { frequency: dictKanji.misc.frequency } : {},
|
|
2223
|
+
...dictKanji.misc?.jlpt !== void 0 ? { jlpt: dictKanji.misc.jlpt } : {},
|
|
2224
|
+
noteID: `kanji_${dictKanji.kanji}`,
|
|
2225
|
+
...noteTypeName !== void 0 ? { noteTypeName } : {},
|
|
2226
|
+
...deckPath !== void 0 ? { deckPath } : {},
|
|
2227
|
+
tags: []
|
|
2228
|
+
};
|
|
2229
|
+
if (dictKanji.readingMeaning !== void 0 && dictKanji.readingMeaning.length > 0) {
|
|
2230
|
+
const meanings = [];
|
|
2231
|
+
const nanori = [];
|
|
2232
|
+
const onyomi = [];
|
|
2233
|
+
const kunyomi = [];
|
|
2234
|
+
for (const rm of dictKanji.readingMeaning) {
|
|
2235
|
+
if (rm.nanori !== void 0 && rm.nanori.length > 0)
|
|
2236
|
+
nanori.push(...rm.nanori);
|
|
2237
|
+
for (const group of rm.groups) {
|
|
2238
|
+
if (group.readings !== void 0) {
|
|
2239
|
+
onyomi.push(
|
|
2240
|
+
...group.readings.filter((reading) => reading.type === "ja_on").map((reading) => reading.reading)
|
|
2241
|
+
);
|
|
2242
|
+
kunyomi.push(
|
|
2243
|
+
...group.readings.filter(
|
|
2244
|
+
(reading) => reading.type === "ja_kun"
|
|
2245
|
+
).map((reading) => reading.reading)
|
|
2246
|
+
);
|
|
2247
|
+
}
|
|
2248
|
+
if (group.meanings !== void 0 && group.meanings.length > 0)
|
|
2249
|
+
meanings.push(...group.meanings);
|
|
2250
|
+
}
|
|
2251
|
+
}
|
|
2252
|
+
if (meanings.length > 0) kanji.meanings = meanings;
|
|
2253
|
+
if (nanori.length > 0) kanji.nanori = nanori;
|
|
2254
|
+
if (onyomi.length > 0) kanji.onyomi = onyomi;
|
|
2255
|
+
if (kunyomi.length > 0) kanji.kunyomi = kunyomi;
|
|
2256
|
+
}
|
|
2257
|
+
if (jmDict !== void 0) {
|
|
2258
|
+
let kanjiWords = jmDict instanceof Map ? jmDict.get(kanji.kanji) : jmDict;
|
|
2259
|
+
const firstKfWords = kanjiWords?.filter(
|
|
2260
|
+
(word) => word.kanjiForms !== void 0 && word.kanjiForms[0].form.includes(kanji.kanji)
|
|
2261
|
+
);
|
|
2262
|
+
if (firstKfWords !== void 0 && firstKfWords.length > 0)
|
|
2263
|
+
kanjiWords = firstKfWords;
|
|
2264
|
+
if (kanjiWords !== void 0) {
|
|
2265
|
+
const validWords = [];
|
|
2266
|
+
for (const word of kanjiWords) {
|
|
2267
|
+
const kanjiForm = (firstKfWords !== void 0 && firstKfWords.length > 0 ? word.kanjiForms[0] : word.kanjiForms.find(
|
|
2268
|
+
(kf) => kf.form.includes(kanji.kanji)
|
|
2269
|
+
))?.form;
|
|
2270
|
+
if (kanjiForm !== void 0) {
|
|
2271
|
+
const reading = (firstKfWords !== void 0 && firstKfWords.length > 0 ? word.readings[0] : word.readings.find(
|
|
2272
|
+
(r) => r.kanjiFormRestrictions !== void 0 && r.kanjiFormRestrictions.includes(kanjiForm)
|
|
2273
|
+
))?.reading;
|
|
2274
|
+
if (reading === void 0) continue;
|
|
2275
|
+
const translation = (firstKfWords !== void 0 && firstKfWords.length > 0 ? word.meanings[0] : word.meanings.find(
|
|
2276
|
+
(m) => m.kanjiFormRestrictions !== void 0 && m.kanjiFormRestrictions.includes(kanjiForm)
|
|
2277
|
+
))?.translations.map(
|
|
2278
|
+
(t) => typeof t === "string" ? t : t.translation
|
|
2279
|
+
)[0];
|
|
2280
|
+
if (translation === void 0) continue;
|
|
2281
|
+
validWords.push({
|
|
2282
|
+
kanjiForms: [{ kanjiForm }],
|
|
2283
|
+
readings: [{ reading }],
|
|
2284
|
+
translations: [
|
|
2285
|
+
{
|
|
2286
|
+
translation
|
|
2287
|
+
}
|
|
2288
|
+
]
|
|
2289
|
+
});
|
|
2290
|
+
}
|
|
2291
|
+
if (validWords.length === 3) break;
|
|
2292
|
+
}
|
|
2293
|
+
if (validWords.length > 0) kanji.words = validWords;
|
|
2294
|
+
}
|
|
2295
|
+
}
|
|
2296
|
+
if (svgList !== void 0) {
|
|
2297
|
+
const codePoint = kanji.kanji.codePointAt(0).toString(16).toLowerCase();
|
|
2298
|
+
const svg = svgList instanceof Map ? svgList.get(kanji.kanji) : svgList.find(
|
|
2299
|
+
(svgFile) => [`${codePoint}.svg`, `0${codePoint}.svg`].includes(
|
|
2300
|
+
svgFile.toLowerCase()
|
|
2301
|
+
)
|
|
2302
|
+
);
|
|
2303
|
+
if (svg !== void 0) kanji.svg = svg;
|
|
2304
|
+
}
|
|
2305
|
+
if (dictKanji.isKokuji === true) {
|
|
2306
|
+
kanji.kokuji = true;
|
|
2307
|
+
kanji.tags.push("kanji::kokuji");
|
|
2308
|
+
}
|
|
2309
|
+
kanji.tags.push(
|
|
2310
|
+
`kanji::strokes::${kanji.strokes}`,
|
|
2311
|
+
...kanji.frequency !== void 0 ? [`kanji::frequency::${kanji.frequency}`] : [],
|
|
2312
|
+
...kanji.grade !== void 0 ? [`kanji::grade::${kanji.grade}`] : [],
|
|
2313
|
+
...kanji.jlpt !== void 0 ? [`kanji::pre-2010_jlpt::${kanji.jlpt.toLowerCase()}`] : [],
|
|
2314
|
+
`kanji::onyomi::${kanji.onyomi?.length ?? 0}`,
|
|
2315
|
+
`kanji::kunyomi::${kanji.kunyomi?.length ?? 0}`,
|
|
2316
|
+
`kanji::nanori::${kanji.nanori?.length ?? 0}`,
|
|
2317
|
+
`kanji::words::${kanji.words?.length ?? 0}`,
|
|
2318
|
+
...kanji.svg !== void 0 ? ["kanji::has_svg"] : []
|
|
2319
|
+
);
|
|
2320
|
+
return kanji;
|
|
2321
|
+
} else return void 0;
|
|
2322
|
+
}
|
|
2323
|
+
function getKanjiExtended(info, kanji, dict, useWords, jmDict, svgList, noteTypeName, deckPath, sourceURL) {
|
|
2324
|
+
const kanjiObj = getKanji(
|
|
2325
|
+
kanji,
|
|
2326
|
+
dict,
|
|
2327
|
+
jmDict,
|
|
2328
|
+
svgList,
|
|
2329
|
+
noteTypeName,
|
|
2330
|
+
deckPath
|
|
2331
|
+
);
|
|
2332
|
+
if (kanjiObj !== void 0) {
|
|
2333
|
+
let usedInfo = false;
|
|
2334
|
+
if (info.components !== void 0) {
|
|
2335
|
+
kanjiObj.components = info.components;
|
|
2336
|
+
kanjiObj.tags.push(`kanji::components::${kanjiObj.components.length}`);
|
|
2337
|
+
usedInfo = true;
|
|
2338
|
+
}
|
|
2339
|
+
if (info.mnemonic !== void 0 && info.mnemonic.length > 0) {
|
|
2340
|
+
kanjiObj.mnemonic = info.mnemonic;
|
|
2341
|
+
kanjiObj.tags.push("kanji::has_mnemonic");
|
|
2342
|
+
usedInfo = true;
|
|
2343
|
+
}
|
|
2344
|
+
if (useWords === true && info.words !== void 0 && info.words.length > 0) {
|
|
2345
|
+
kanjiObj.words = info.words;
|
|
2346
|
+
kanjiObj.tags.forEach((tag, index) => {
|
|
2347
|
+
if (tag.startsWith("kanji::words::") && kanjiObj.words !== void 0)
|
|
2348
|
+
kanjiObj.tags.splice(
|
|
2349
|
+
index,
|
|
2350
|
+
1,
|
|
2351
|
+
`kanji::words::${kanjiObj.words.length}`
|
|
2352
|
+
);
|
|
2353
|
+
});
|
|
2354
|
+
usedInfo = true;
|
|
2355
|
+
}
|
|
2356
|
+
if (sourceURL !== void 0 && info.externalInfo === true && usedInfo)
|
|
2357
|
+
kanjiObj.source = sourceURL;
|
|
2358
|
+
return kanjiObj;
|
|
2359
|
+
} else return void 0;
|
|
2360
|
+
}
|
|
2361
|
+
function getWord(searchedWord, dict, kanjiDic, examples, definitions, noteTypeName, deckPath) {
|
|
2215
2362
|
let dictWord = void 0;
|
|
2216
|
-
if (typeof
|
|
2363
|
+
if (typeof searchedWord === "string" && dict !== void 0) {
|
|
2217
2364
|
if (Array.isArray(dict))
|
|
2218
2365
|
dictWord = dict.find(
|
|
2219
|
-
(entry) => entry.id ===
|
|
2366
|
+
(entry) => entry.id === searchedWord
|
|
2220
2367
|
);
|
|
2221
|
-
if (dict instanceof Map) dictWord = dict.get(
|
|
2368
|
+
if (dict instanceof Map) dictWord = dict.get(searchedWord);
|
|
2222
2369
|
}
|
|
2223
|
-
if (typeof
|
|
2224
|
-
if (dictWord) {
|
|
2225
|
-
const
|
|
2370
|
+
if (typeof searchedWord === "object") dictWord = searchedWord;
|
|
2371
|
+
if (dictWord !== void 0) {
|
|
2372
|
+
const word = {
|
|
2226
2373
|
id: dictWord.id,
|
|
2227
2374
|
readings: [],
|
|
2228
2375
|
translations: [],
|
|
@@ -2232,46 +2379,46 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2232
2379
|
tags: []
|
|
2233
2380
|
};
|
|
2234
2381
|
if (dictWord.isCommon === true) {
|
|
2235
|
-
|
|
2236
|
-
|
|
2382
|
+
word.common = true;
|
|
2383
|
+
word.tags.push("word::common");
|
|
2237
2384
|
}
|
|
2238
|
-
if (dictWord.kanjiForms)
|
|
2239
|
-
|
|
2385
|
+
if (dictWord.kanjiForms !== void 0)
|
|
2386
|
+
word.kanjiForms = dictWord.kanjiForms.map(
|
|
2240
2387
|
(dictKanjiForm) => ({
|
|
2241
2388
|
kanjiForm: dictKanjiForm.form,
|
|
2242
|
-
...dictKanjiForm.notes ? {
|
|
2389
|
+
...dictKanjiForm.notes !== void 0 ? {
|
|
2243
2390
|
notes: dictKanjiForm.notes.map((note) => {
|
|
2244
2391
|
const noteAndTag = lookupWordNote(
|
|
2245
2392
|
note,
|
|
2246
2393
|
[],
|
|
2247
|
-
|
|
2394
|
+
word.tags
|
|
2248
2395
|
);
|
|
2249
2396
|
return capitalizeString(noteAndTag.note);
|
|
2250
2397
|
})
|
|
2251
2398
|
} : {},
|
|
2252
|
-
...dictKanjiForm.commonness && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
|
|
2399
|
+
...dictKanjiForm.commonness !== void 0 && dictKanjiForm.commonness.length > 0 ? { common: true } : {}
|
|
2253
2400
|
})
|
|
2254
2401
|
);
|
|
2255
|
-
|
|
2402
|
+
word.readings = dictWord.readings.map((dictReading) => ({
|
|
2256
2403
|
reading: dictReading.reading,
|
|
2257
|
-
...dictReading.kanjiFormRestrictions || dictReading.notes ? {
|
|
2404
|
+
...dictReading.kanjiFormRestrictions !== void 0 || dictReading.notes !== void 0 ? {
|
|
2258
2405
|
notes: [
|
|
2259
|
-
...dictReading.kanjiFormRestrictions ? dictReading.kanjiFormRestrictions.map(
|
|
2406
|
+
...dictReading.kanjiFormRestrictions !== void 0 ? dictReading.kanjiFormRestrictions.map(
|
|
2260
2407
|
(restriction) => `Reading restricted to ${restriction}`
|
|
2261
2408
|
) : [],
|
|
2262
|
-
...dictReading.notes ? dictReading.notes.map((note) => {
|
|
2409
|
+
...dictReading.notes !== void 0 ? dictReading.notes.map((note) => {
|
|
2263
2410
|
const noteAndTag = lookupWordNote(
|
|
2264
2411
|
note,
|
|
2265
2412
|
[],
|
|
2266
|
-
|
|
2413
|
+
word.tags
|
|
2267
2414
|
);
|
|
2268
2415
|
return capitalizeString(noteAndTag.note);
|
|
2269
2416
|
}) : []
|
|
2270
2417
|
]
|
|
2271
2418
|
} : {},
|
|
2272
|
-
...dictReading.commonness && dictReading.commonness.length > 0 ? { common: true } : {}
|
|
2419
|
+
...dictReading.commonness !== void 0 && dictReading.commonness.length > 0 ? { common: true } : {}
|
|
2273
2420
|
}));
|
|
2274
|
-
|
|
2421
|
+
word.translations = [];
|
|
2275
2422
|
for (const dictMeaning of dictWord.meanings) {
|
|
2276
2423
|
const translationTypes = [];
|
|
2277
2424
|
const translations = dictMeaning.translations.map(
|
|
@@ -2282,7 +2429,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2282
2429
|
translation.type
|
|
2283
2430
|
);
|
|
2284
2431
|
translationTypes.push(translationNoteAndTag[1]);
|
|
2285
|
-
|
|
2432
|
+
word.tags.push(`word::${translationNoteAndTag[0]}`);
|
|
2286
2433
|
return translation.translation;
|
|
2287
2434
|
}
|
|
2288
2435
|
}
|
|
@@ -2299,15 +2446,15 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2299
2446
|
for (const t of translationTypes) notes.push(t);
|
|
2300
2447
|
wordAddNoteArray(
|
|
2301
2448
|
dictMeaning.partOfSpeech,
|
|
2302
|
-
(pos) => lookupWordNote(pos, notes,
|
|
2449
|
+
(pos) => lookupWordNote(pos, notes, word.tags)
|
|
2303
2450
|
);
|
|
2304
2451
|
wordAddNoteArray(
|
|
2305
2452
|
dictMeaning.fields,
|
|
2306
|
-
(field) => lookupWordNote(field, notes,
|
|
2453
|
+
(field) => lookupWordNote(field, notes, word.tags)
|
|
2307
2454
|
);
|
|
2308
2455
|
wordAddNoteArray(
|
|
2309
2456
|
dictMeaning.dialects,
|
|
2310
|
-
(dialect) => lookupWordNote(dialect, notes,
|
|
2457
|
+
(dialect) => lookupWordNote(dialect, notes, word.tags)
|
|
2311
2458
|
);
|
|
2312
2459
|
wordAddNoteArray(
|
|
2313
2460
|
dictMeaning.antonyms,
|
|
@@ -2319,45 +2466,45 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2319
2466
|
);
|
|
2320
2467
|
wordAddNoteArray(
|
|
2321
2468
|
dictMeaning.info,
|
|
2322
|
-
(info) => lookupWordNote(info, notes,
|
|
2469
|
+
(info) => lookupWordNote(info, notes, word.tags)
|
|
2323
2470
|
);
|
|
2324
2471
|
wordAddNoteArray(
|
|
2325
2472
|
dictMeaning.misc,
|
|
2326
|
-
(misc) => lookupWordNote(misc, notes,
|
|
2473
|
+
(misc) => lookupWordNote(misc, notes, word.tags)
|
|
2327
2474
|
);
|
|
2328
2475
|
for (let i = 0; i < notes.length; i++)
|
|
2329
2476
|
notes[i] = capitalizeString(notes[i]);
|
|
2330
|
-
|
|
2477
|
+
word.translations.push({
|
|
2331
2478
|
translation: translations.join("; "),
|
|
2332
2479
|
notes
|
|
2333
2480
|
});
|
|
2334
2481
|
}
|
|
2335
2482
|
if (dictWord.usuallyInKana === true) {
|
|
2336
|
-
|
|
2337
|
-
|
|
2483
|
+
word.usuallyInKana = true;
|
|
2484
|
+
word.tags.push("word::usually_in_kana_for_all_senses");
|
|
2338
2485
|
}
|
|
2339
|
-
if (kanjiDic &&
|
|
2486
|
+
if (kanjiDic !== void 0 && word.kanjiForms !== void 0) {
|
|
2340
2487
|
const kanji = [];
|
|
2341
2488
|
const seenChars = /* @__PURE__ */ new Set();
|
|
2342
|
-
for (const kanjiForm of
|
|
2489
|
+
for (const kanjiForm of word.kanjiForms)
|
|
2343
2490
|
for (const char of kanjiForm.kanjiForm.split("").filter((c) => regexps.kanji.test(c))) {
|
|
2344
2491
|
if (seenChars.has(char)) continue;
|
|
2345
2492
|
seenChars.add(char);
|
|
2346
2493
|
const kanjiEntry = kanjiDic instanceof Map ? kanjiDic.get(char) : void 0;
|
|
2347
2494
|
const kanjiObj = getKanji(
|
|
2348
2495
|
kanjiEntry ?? char,
|
|
2349
|
-
|
|
2496
|
+
!(kanjiDic instanceof Map) ? kanjiDic : void 0
|
|
2350
2497
|
);
|
|
2351
|
-
if (kanjiObj)
|
|
2498
|
+
if (kanjiObj !== void 0)
|
|
2352
2499
|
kanji.push({
|
|
2353
2500
|
kanji: kanjiObj.kanji,
|
|
2354
|
-
...kanjiObj.meanings && kanjiObj.meanings.length > 0 ? { meanings: kanjiObj.meanings } : {}
|
|
2501
|
+
...kanjiObj.meanings !== void 0 && kanjiObj.meanings.length > 0 ? { meanings: kanjiObj.meanings } : {}
|
|
2355
2502
|
});
|
|
2356
2503
|
}
|
|
2357
|
-
if (kanji.length > 0)
|
|
2504
|
+
if (kanji.length > 0) word.kanji = kanji;
|
|
2358
2505
|
}
|
|
2359
|
-
if (dictWord.hasPhrases !== void 0
|
|
2360
|
-
const exampleList =
|
|
2506
|
+
if (dictWord.hasPhrases === true && examples !== void 0) {
|
|
2507
|
+
const exampleList = examples instanceof Map ? examples.get(dictWord.id) ?? [] : examples;
|
|
2361
2508
|
const rkf = getValidForms(
|
|
2362
2509
|
dictWord.readings,
|
|
2363
2510
|
dictWord.kanjiForms,
|
|
@@ -2366,7 +2513,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2366
2513
|
const readings = new Set(
|
|
2367
2514
|
rkf.readings.map((r) => r.reading)
|
|
2368
2515
|
);
|
|
2369
|
-
const kanjiForms = rkf.kanjiForms ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
|
|
2516
|
+
const kanjiForms = rkf.kanjiForms !== void 0 ? new Set(rkf.kanjiForms.map((kf) => kf.form)) : void 0;
|
|
2370
2517
|
let kanjiFormExamples = [];
|
|
2371
2518
|
const readingMatchingKanjiFormExamples = [];
|
|
2372
2519
|
const readingExamples = [];
|
|
@@ -2377,7 +2524,7 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2377
2524
|
const readingAsReadingMatch = part.reading !== void 0 && readings.has(part.reading);
|
|
2378
2525
|
const readingAsInflectedFormMatch = part.inflectedForm !== void 0 && readings.has(part.inflectedForm);
|
|
2379
2526
|
const referenceIDMatch = part.referenceID === dictWord.id;
|
|
2380
|
-
if (kanjiForms && kanjiForms.has(part.baseForm) || referenceIDMatch) {
|
|
2527
|
+
if (kanjiForms !== void 0 && kanjiForms.has(part.baseForm) || referenceIDMatch) {
|
|
2381
2528
|
if (readingAsReadingMatch || readingAsInflectedFormMatch) {
|
|
2382
2529
|
readingMatchingKanjiFormExamples.push({
|
|
2383
2530
|
ex: example,
|
|
@@ -2393,16 +2540,16 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2393
2540
|
break;
|
|
2394
2541
|
}
|
|
2395
2542
|
const readingAsBaseFormMatch = readings.has(part.baseForm);
|
|
2396
|
-
if (
|
|
2543
|
+
if (readingAsBaseFormMatch && kanjiForms === void 0) {
|
|
2397
2544
|
readingExamples.push({ ex: example, partIndex: i });
|
|
2398
2545
|
break;
|
|
2399
2546
|
}
|
|
2400
2547
|
}
|
|
2401
2548
|
if (readingMatchingKanjiForms.size > 0)
|
|
2402
2549
|
kanjiFormExamples = kanjiFormExamples.filter(
|
|
2403
|
-
(ex) => ex.form && readingMatchingKanjiForms.has(ex.form)
|
|
2550
|
+
(ex) => ex.form !== void 0 && readingMatchingKanjiForms.has(ex.form)
|
|
2404
2551
|
);
|
|
2405
|
-
const includeKanjiFormExamples =
|
|
2552
|
+
const includeKanjiFormExamples = word.kanjiForms !== void 0;
|
|
2406
2553
|
let wordExamples = [
|
|
2407
2554
|
...includeKanjiFormExamples ? [...readingMatchingKanjiFormExamples, ...kanjiFormExamples] : readingExamples
|
|
2408
2555
|
];
|
|
@@ -2412,14 +2559,14 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2412
2559
|
readingMatchingKanjiForms.clear();
|
|
2413
2560
|
const glossSpecificExamples = [];
|
|
2414
2561
|
const seenPhrases = /* @__PURE__ */ new Set();
|
|
2415
|
-
for (let i = 0; i <
|
|
2562
|
+
for (let i = 0; i < word.translations.length; i++)
|
|
2416
2563
|
outer: for (const example of wordExamples) {
|
|
2417
2564
|
if (seenPhrases.has(example.ex.phrase)) continue;
|
|
2418
2565
|
for (let j = 0; j < example.ex.parts.length; j++) {
|
|
2419
2566
|
const part = example.ex.parts[j];
|
|
2420
2567
|
if (j === example.partIndex && part.glossNumber === i + 1) {
|
|
2421
2568
|
example.ex.glossNumber = {
|
|
2422
|
-
wordId:
|
|
2569
|
+
wordId: word.id,
|
|
2423
2570
|
glossNumber: i + 1
|
|
2424
2571
|
};
|
|
2425
2572
|
glossSpecificExamples.push(example);
|
|
@@ -2428,7 +2575,6 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2428
2575
|
}
|
|
2429
2576
|
}
|
|
2430
2577
|
}
|
|
2431
|
-
}
|
|
2432
2578
|
if (glossSpecificExamples.length > 0) {
|
|
2433
2579
|
if (glossSpecificExamples.length < 5) {
|
|
2434
2580
|
wordExamples = wordExamples.filter(
|
|
@@ -2443,202 +2589,49 @@ function getWord(word, dict, kanjiDic, examples, definitions, noteTypeName, deck
|
|
|
2443
2589
|
wordExamples = glossSpecificExamples;
|
|
2444
2590
|
}
|
|
2445
2591
|
if (wordExamples.length > 0) {
|
|
2446
|
-
|
|
2592
|
+
word.phrases = (glossSpecificExamples.length === 0 ? wordExamples.slice(0, 5) : wordExamples).map((ex) => ({
|
|
2447
2593
|
phrase: ex.ex.furigana ?? ex.ex.phrase,
|
|
2448
2594
|
translation: ex.ex.translation,
|
|
2449
2595
|
originalPhrase: ex.ex.phrase,
|
|
2450
|
-
...ex.ex.glossNumber ? { glossNumber: ex.ex.glossNumber } : {}
|
|
2596
|
+
...ex.ex.glossNumber !== void 0 ? { glossNumber: ex.ex.glossNumber } : {}
|
|
2451
2597
|
}));
|
|
2452
|
-
|
|
2598
|
+
word.tags.push("word::has_phrases");
|
|
2453
2599
|
if (glossSpecificExamples.length > 0)
|
|
2454
|
-
|
|
2600
|
+
word.tags.push("word::has_meaning-specific_phrases");
|
|
2455
2601
|
}
|
|
2456
2602
|
}
|
|
2457
|
-
if (definitions) {
|
|
2458
|
-
const defs =
|
|
2459
|
-
|
|
2460
|
-
|
|
2603
|
+
if (definitions !== void 0) {
|
|
2604
|
+
const defs = definitions instanceof Map ? definitions.get(word.id) : definitions.find(
|
|
2605
|
+
(wdp) => wdp.wordID === word.id
|
|
2606
|
+
)?.definitions;
|
|
2607
|
+
if (defs !== void 0)
|
|
2608
|
+
word.definitions = [
|
|
2461
2609
|
...defs.toSorted(
|
|
2462
|
-
(a, b) =>
|
|
2610
|
+
(a, b) => (a.mayNotBeAccurate ?? 0) - (b.mayNotBeAccurate ?? 0)
|
|
2463
2611
|
)
|
|
2464
2612
|
];
|
|
2465
2613
|
}
|
|
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;
|
|
2614
|
+
return word;
|
|
2621
2615
|
} else return void 0;
|
|
2622
2616
|
}
|
|
2623
2617
|
function isWord(entry) {
|
|
2624
|
-
return entry
|
|
2618
|
+
return isObjectArray(Object.getOwnPropertyDescriptor(entry, "readings")?.value) && isObjectArray(Object.getOwnPropertyDescriptor(entry, "translations")?.value);
|
|
2625
2619
|
}
|
|
2626
2620
|
function isRadical(entry) {
|
|
2627
|
-
return entry
|
|
2621
|
+
return typeof Object.getOwnPropertyDescriptor(entry, "radical")?.value === "string";
|
|
2628
2622
|
}
|
|
2629
2623
|
function isKanji(entry) {
|
|
2630
|
-
return entry
|
|
2624
|
+
return !Object.hasOwn(entry, "translations") && !Object.hasOwn(entry, "readings") && !Object.hasOwn(entry, "radical") && typeof Object.getOwnPropertyDescriptor(entry, "kanji")?.value === "string";
|
|
2631
2625
|
}
|
|
2632
2626
|
function isKana(entry) {
|
|
2633
|
-
return entry
|
|
2627
|
+
return typeof Object.getOwnPropertyDescriptor(entry, "kana")?.value === "string";
|
|
2634
2628
|
}
|
|
2635
2629
|
function isGrammar(entry) {
|
|
2636
|
-
return entry
|
|
2630
|
+
return typeof Object.getOwnPropertyDescriptor(entry, "point")?.value === "string";
|
|
2637
2631
|
}
|
|
2638
2632
|
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>`;
|
|
2633
|
+
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
2634
|
function generateAnkiNote(entry) {
|
|
2641
|
-
var _a, _b;
|
|
2642
2635
|
const fields = [];
|
|
2643
2636
|
if (isWord(entry)) {
|
|
2644
2637
|
const firstReading = createEntry(
|
|
@@ -2652,52 +2645,51 @@ function generateAnkiNote(entry) {
|
|
|
2652
2645
|
)
|
|
2653
2646
|
).join("")}</details>` : "";
|
|
2654
2647
|
const readingsField = `${firstReading}${otherReadings}`;
|
|
2655
|
-
const firstKanjiForm = entry.kanjiForms ? createEntry(
|
|
2648
|
+
const firstKanjiForm = entry.kanjiForms !== void 0 ? createEntry(
|
|
2656
2649
|
`<span class="word word-kanjiform"><ruby><rb>${entry.kanjiForms[0].kanjiForm}</rb><rt>${entry.readings[0].reading}</rt></ruby></span>`,
|
|
2657
2650
|
entry.kanjiForms[0].notes
|
|
2658
2651
|
) : void 0;
|
|
2659
|
-
const otherKanjiForms = entry.kanjiForms && entry.kanjiForms.length > 1 ? `<details><summary>Show other kanji forms</summary>${entry.kanjiForms.slice(1).map((kanjiFormEntry) => {
|
|
2652
|
+
const otherKanjiForms = entry.kanjiForms !== void 0 && entry.kanjiForms.length > 1 ? `<details><summary>Show other kanji forms</summary>${entry.kanjiForms.slice(1).map((kanjiFormEntry) => {
|
|
2660
2653
|
const restrictedReading = entry.readings.find(
|
|
2661
|
-
(r) => r.notes && r.notes.includes(
|
|
2654
|
+
(r) => r.notes !== void 0 && r.notes.includes(
|
|
2662
2655
|
`Reading restricted to ${kanjiFormEntry.kanjiForm}`
|
|
2663
2656
|
)
|
|
2664
2657
|
);
|
|
2665
|
-
return
|
|
2658
|
+
return createEntry(
|
|
2659
|
+
`<span class="word word-kanjiform">${restrictedReading !== void 0 ? "<ruby><rb>" : ""}${kanjiFormEntry.kanjiForm}${restrictedReading !== void 0 ? `</rb><rt>${restrictedReading.reading}</rt></ruby>` : ""}</span>`,
|
|
2660
|
+
kanjiFormEntry.notes
|
|
2661
|
+
);
|
|
2666
2662
|
}).join("")}</details>` : "";
|
|
2667
|
-
const kanjiFormsField = firstKanjiForm ? `${firstKanjiForm}${otherKanjiForms}` : '<span class="word word-kanjiform">(no kanji forms)</span>';
|
|
2663
|
+
const kanjiFormsField = firstKanjiForm !== void 0 ? `${firstKanjiForm}${otherKanjiForms}` : '<span class="word word-kanjiform">(no kanji forms)</span>';
|
|
2668
2664
|
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
|
-
}
|
|
2665
|
+
(translationEntry, index) => createEntry(
|
|
2666
|
+
`<span class="word word-translation">${translationEntry.translation}</span>`,
|
|
2667
|
+
translationEntry.notes,
|
|
2668
|
+
void 0,
|
|
2669
|
+
entry.phrases !== void 0 ? entry.phrases.some(
|
|
2670
|
+
(phrase, index2) => index === index2 && phrase.glossNumber !== void 0 && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1
|
|
2671
|
+
) ? true : void 0 : void 0
|
|
2672
|
+
)
|
|
2680
2673
|
).join("");
|
|
2681
2674
|
const otherTranslations = entry.translations.length > 3 ? `<details><summary>Show other translations</summary>${entry.translations.map((translationEntry, index) => {
|
|
2682
|
-
var _a2;
|
|
2683
2675
|
if (index < 3) return "null";
|
|
2684
2676
|
return createEntry(
|
|
2685
2677
|
`<span class="word word-translation">${translationEntry.translation}</span>`,
|
|
2686
2678
|
translationEntry.notes,
|
|
2687
2679
|
void 0,
|
|
2688
|
-
|
|
2689
|
-
(phrase, index2) => index === index2 && phrase.glossNumber && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1
|
|
2690
|
-
)
|
|
2680
|
+
entry.phrases !== void 0 ? entry.phrases.some(
|
|
2681
|
+
(phrase, index2) => index === index2 && phrase.glossNumber !== void 0 && phrase.glossNumber.wordId === entry.id && phrase.glossNumber.glossNumber === index + 1
|
|
2682
|
+
) ? true : void 0 : void 0
|
|
2691
2683
|
);
|
|
2692
2684
|
}).filter((translation) => translation !== "null").join("")}</details>` : "";
|
|
2693
2685
|
const translationsField = `${firstThreeTranslations}${otherTranslations}`;
|
|
2694
|
-
const firstFivePhrases =
|
|
2686
|
+
const firstFivePhrases = entry.phrases?.slice(0, 5).map(
|
|
2695
2687
|
(phraseEntry, index) => createEntry(
|
|
2696
2688
|
`<span class="word word-phrase"><span class="word word-phrase-original">${phraseEntry.originalPhrase}</span><span class="word word-phrase-furigana">${phraseEntry.phrase}</span></span>`,
|
|
2697
2689
|
[phraseEntry.translation],
|
|
2698
2690
|
true,
|
|
2699
2691
|
entry.translations.some(
|
|
2700
|
-
(_translation, index2) => index === index2 && phraseEntry.glossNumber && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2692
|
+
(_translation, index2) => index === index2 && phraseEntry.glossNumber !== void 0 && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2701
2693
|
) ? true : void 0
|
|
2702
2694
|
)
|
|
2703
2695
|
).join("");
|
|
@@ -2708,34 +2700,34 @@ function generateAnkiNote(entry) {
|
|
|
2708
2700
|
[phraseEntry.translation],
|
|
2709
2701
|
true,
|
|
2710
2702
|
entry.translations.some(
|
|
2711
|
-
(_translation, index2) => index === index2 && phraseEntry.glossNumber && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2703
|
+
(_translation, index2) => index === index2 && phraseEntry.glossNumber !== void 0 && phraseEntry.glossNumber.wordId === entry.id && phraseEntry.glossNumber.glossNumber === index2 + 1
|
|
2712
2704
|
) ? true : void 0
|
|
2713
2705
|
);
|
|
2714
2706
|
}).filter((phrase) => phrase !== "null").join("")}</details>` : "";
|
|
2715
|
-
const phrasesField = firstFivePhrases ? `${firstFivePhrases}${otherPhrases}` : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>';
|
|
2716
|
-
const firstThreeDefinitions =
|
|
2707
|
+
const phrasesField = firstFivePhrases !== void 0 ? `${firstFivePhrases}${otherPhrases}` : '<span class="word word-phrase">(no phrases) (Search on dictionaries!)</span>';
|
|
2708
|
+
const firstThreeDefinitions = entry.definitions?.slice(0, 3).map(
|
|
2717
2709
|
(definitionEntry) => createEntry(
|
|
2718
|
-
`<span class="word word-definition${definitionEntry.mayNotBeAccurate ===
|
|
2710
|
+
`<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
2711
|
)
|
|
2720
2712
|
).join("");
|
|
2721
2713
|
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
|
-
)
|
|
2714
|
+
(definitionEntry, index) => index > 2 ? createEntry(
|
|
2715
|
+
`<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>`
|
|
2716
|
+
) : "null"
|
|
2725
2717
|
).filter((definition) => definition !== "null").join("")}</details>` : "";
|
|
2726
|
-
const definitionsField = firstThreeDefinitions ? `${firstThreeDefinitions}${otherDefinitions}` : '<span class="word word-definition">(no definitions)</span>';
|
|
2718
|
+
const definitionsField = firstThreeDefinitions !== void 0 ? `${firstThreeDefinitions}${otherDefinitions}` : '<span class="word word-definition">(no definitions)</span>';
|
|
2727
2719
|
fields.push(
|
|
2728
|
-
...entry.kanjiForms && !entry.usuallyInKana ? [kanjiFormsField, readingsField] : [readingsField, kanjiFormsField],
|
|
2720
|
+
...entry.kanjiForms !== void 0 && !entry.usuallyInKana ? [kanjiFormsField, readingsField] : [readingsField, kanjiFormsField],
|
|
2729
2721
|
translationsField,
|
|
2730
2722
|
phrasesField,
|
|
2731
2723
|
definitionsField,
|
|
2732
|
-
entry.kanji ? entry.kanji.map(
|
|
2724
|
+
entry.kanji !== void 0 ? entry.kanji.map(
|
|
2733
2725
|
(kanjiEntry) => createEntry(
|
|
2734
2726
|
`<span class="word word-kanji">${kanjiEntry.kanji}${kanjiEntry.meanings === void 0 ? " (no meanings)" : ""}</span>`,
|
|
2735
2727
|
kanjiEntry.meanings
|
|
2736
2728
|
)
|
|
2737
2729
|
).join("") : '<span class="word word-kanji">(no kanji)</span>',
|
|
2738
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2730
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2739
2731
|
entry.tags.map(
|
|
2740
2732
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2741
2733
|
).join(" ")
|
|
@@ -2755,19 +2747,19 @@ function generateAnkiNote(entry) {
|
|
|
2755
2747
|
`<span class="radical radical-meaning">${meaningEntry}</span>`
|
|
2756
2748
|
)
|
|
2757
2749
|
).join(""),
|
|
2758
|
-
entry.mnemonic ? createEntry(
|
|
2750
|
+
entry.mnemonic !== void 0 ? createEntry(
|
|
2759
2751
|
`<span class="radical radical-mnemonic">${entry.mnemonic}</span>`
|
|
2760
2752
|
) : '<span class="radical radical-mnemonic">(no mnemonic) (Come up with your own!)</span>',
|
|
2761
|
-
entry.kanji ? entry.kanji.map(
|
|
2753
|
+
entry.kanji !== void 0 ? entry.kanji.map(
|
|
2762
2754
|
(kanji) => createEntry(
|
|
2763
|
-
`<span class="radical radical-kanji">${kanji.kanji}${kanji.meanings && kanji.meanings.length
|
|
2755
|
+
`<span class="radical radical-kanji">${kanji.kanji}${kanji.meanings !== void 0 && kanji.meanings.length > 0 ? ` - ${kanji.meanings[0]}` : ""}</span>`
|
|
2764
2756
|
)
|
|
2765
2757
|
).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>`
|
|
2758
|
+
entry.strokes !== void 0 ? createEntry(
|
|
2759
|
+
`<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
2760
|
) : '<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 ? [
|
|
2761
|
+
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>',
|
|
2762
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2771
2763
|
entry.tags.map(
|
|
2772
2764
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2773
2765
|
).join(" ")
|
|
@@ -2776,44 +2768,44 @@ function generateAnkiNote(entry) {
|
|
|
2776
2768
|
if (isKanji(entry))
|
|
2777
2769
|
fields.push(
|
|
2778
2770
|
createEntry(`<span class="kanji kanji-character">${entry.kanji}</span>`),
|
|
2779
|
-
entry.meanings ? entry.meanings.map(
|
|
2771
|
+
entry.meanings !== void 0 ? entry.meanings.map(
|
|
2780
2772
|
(meaningEntry) => createEntry(
|
|
2781
2773
|
`<span class="kanji kanji-meaning">${meaningEntry}</span>`
|
|
2782
2774
|
)
|
|
2783
2775
|
).join("") : '<span class="kanji kanji-meaning">(no meanings)</span>',
|
|
2784
|
-
entry.onyomi ? entry.onyomi.map(
|
|
2776
|
+
entry.onyomi !== void 0 ? entry.onyomi.map(
|
|
2785
2777
|
(onyomiEntry) => createEntry(
|
|
2786
2778
|
`<span class="kanji kanji-onyomi">${onyomiEntry}</span>`
|
|
2787
2779
|
)
|
|
2788
2780
|
).join("") : `<span class="kanji kanji-onyomi">(no onyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2789
|
-
entry.kunyomi ? entry.kunyomi.map(
|
|
2781
|
+
entry.kunyomi !== void 0 ? entry.kunyomi.map(
|
|
2790
2782
|
(kunyomiEntry) => createEntry(
|
|
2791
2783
|
`<span class="kanji kanji-kunyomi">${kunyomiEntry}</span>`
|
|
2792
2784
|
)
|
|
2793
2785
|
).join("") : `<span class="kanji kanji-kunyomi">(no kunyomi) ${entry.kokuji === true ? "(kokuji)" : ""}</span>`,
|
|
2794
|
-
entry.nanori ? entry.nanori.map(
|
|
2786
|
+
entry.nanori !== void 0 ? entry.nanori.map(
|
|
2795
2787
|
(nanoriEntry) => createEntry(
|
|
2796
2788
|
`<span class="kanji kanji-nanori">${nanoriEntry}</span>`
|
|
2797
2789
|
)
|
|
2798
2790
|
).join("") : '<span class="kanji kanji-nanori">(no nanori)</span>',
|
|
2799
|
-
entry.components ? entry.components.map(
|
|
2791
|
+
entry.components !== void 0 ? entry.components.map(
|
|
2800
2792
|
(componentEntry) => createEntry(
|
|
2801
|
-
`<span class="kanji kanji-component">${componentEntry.component}${componentEntry.meaning ? ` - ${componentEntry.meaning}` : ""}</span>`
|
|
2793
|
+
`<span class="kanji kanji-component">${componentEntry.component}${componentEntry.meaning !== void 0 ? ` - ${componentEntry.meaning}` : ""}</span>`
|
|
2802
2794
|
)
|
|
2803
2795
|
).join("") : '<span class="kanji kanji-component">(no components)</span>',
|
|
2804
|
-
entry.mnemonic ? createEntry(
|
|
2796
|
+
entry.mnemonic !== void 0 ? createEntry(
|
|
2805
2797
|
`<span class="kanji kanji-mnemonic">${entry.mnemonic}</span>`
|
|
2806
2798
|
) : '<span class="kanji kanji-mnemonic">(no mnemonic) (Come up with your own!)</span>',
|
|
2807
|
-
entry.words ? entry.words.map(
|
|
2799
|
+
entry.words !== void 0 ? entry.words.map(
|
|
2808
2800
|
(word) => createEntry(
|
|
2809
|
-
`<span class="kanji kanji-words">${word.kanjiForms
|
|
2801
|
+
`<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
2802
|
)
|
|
2811
2803
|
).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>`
|
|
2804
|
+
entry.strokes !== void 0 ? createEntry(
|
|
2805
|
+
`<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
2806
|
) : '<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 ? [
|
|
2807
|
+
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>',
|
|
2808
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2817
2809
|
entry.tags.map(
|
|
2818
2810
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2819
2811
|
).join(" ")
|
|
@@ -2825,10 +2817,10 @@ function generateAnkiNote(entry) {
|
|
|
2825
2817
|
createEntry(
|
|
2826
2818
|
`<span class="kana kana-reading">${entry.reading}${entry.audio !== void 0 ? `<br>[sound:${entry.audio}]` : ""}</span>`
|
|
2827
2819
|
),
|
|
2828
|
-
entry.svg ? createEntry(
|
|
2820
|
+
entry.svg !== void 0 ? createEntry(
|
|
2829
2821
|
`<img class="kana kana-stroke-order" src="${entry.svg}" alt="${entry.kana} stroke order SVG">`
|
|
2830
2822
|
) : "(no stroke order SVG available)",
|
|
2831
|
-
...entry.tags && entry.tags.length > 0 ? [
|
|
2823
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2832
2824
|
entry.tags.map(
|
|
2833
2825
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2834
2826
|
).join(" ")
|
|
@@ -2837,28 +2829,28 @@ function generateAnkiNote(entry) {
|
|
|
2837
2829
|
if (isGrammar(entry))
|
|
2838
2830
|
fields.push(
|
|
2839
2831
|
createEntry(`<span class="grammar grammar-point">${entry.point}</span>`),
|
|
2840
|
-
entry.readings ? entry.readings.map(
|
|
2832
|
+
entry.readings !== void 0 ? entry.readings.map(
|
|
2841
2833
|
(readingEntry) => createEntry(
|
|
2842
2834
|
`<span class="grammar grammar-reading">${readingEntry.reading}</span>`
|
|
2843
2835
|
)
|
|
2844
2836
|
).join("") : '<span class="grammar grammar-reading">(no additional readings)</span>',
|
|
2845
2837
|
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>`
|
|
2838
|
+
`<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
2839
|
),
|
|
2848
|
-
entry.usages ? entry.usages.map(
|
|
2840
|
+
entry.usages !== void 0 ? entry.usages.map(
|
|
2849
2841
|
(usage) => createEntry(
|
|
2850
2842
|
`<span class="grammar grammar-usage">${usage}</span>`
|
|
2851
2843
|
)
|
|
2852
2844
|
).join("") : '<span class="grammar grammar-usage">(no usages)</span>',
|
|
2853
|
-
entry.phrases ? entry.phrases.map(
|
|
2845
|
+
entry.phrases !== void 0 ? entry.phrases.map(
|
|
2854
2846
|
(phraseEntry) => createEntry(
|
|
2855
2847
|
`<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
2848
|
[phraseEntry.translation],
|
|
2857
2849
|
true
|
|
2858
2850
|
)
|
|
2859
2851
|
).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 ? [
|
|
2852
|
+
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>',
|
|
2853
|
+
...entry.tags !== void 0 && entry.tags.length > 0 ? [
|
|
2862
2854
|
entry.tags.map(
|
|
2863
2855
|
(tag) => tag.trim().toLowerCase().replaceAll(" ", "::")
|
|
2864
2856
|
).join(" ")
|
|
@@ -2870,8 +2862,9 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2870
2862
|
const headers = [noteHeaderKeys.separator, noteHeaderKeys.html];
|
|
2871
2863
|
let ankiNotes = "";
|
|
2872
2864
|
if (list.length > 0) {
|
|
2873
|
-
|
|
2874
|
-
|
|
2865
|
+
let noteInfo = {};
|
|
2866
|
+
if (defaultNoteInfo !== void 0) noteInfo = { ...defaultNoteInfo };
|
|
2867
|
+
const infoValues = Object.values(noteInfo);
|
|
2875
2868
|
let invalidList = false;
|
|
2876
2869
|
const firstEntry = list[0];
|
|
2877
2870
|
const firstEntryInfo = {
|
|
@@ -2881,7 +2874,7 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2881
2874
|
};
|
|
2882
2875
|
if (infoValues.length === 0 || infoValues.some((value) => value === true || value === void 0)) {
|
|
2883
2876
|
for (const res of list)
|
|
2884
|
-
if (
|
|
2877
|
+
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
2878
|
invalidList = true;
|
|
2886
2879
|
break;
|
|
2887
2880
|
}
|
|
@@ -2890,26 +2883,28 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2890
2883
|
const hasHeader = { guid: false, noteType: false, deckPath: false, tags: false };
|
|
2891
2884
|
let headerCount = 0;
|
|
2892
2885
|
ankiNotes = list.filter((result) => result.doNotCreateNote === void 0).map((result) => {
|
|
2893
|
-
if (typeof
|
|
2894
|
-
if (isWord(result) && result.id
|
|
2886
|
+
if (typeof noteInfo.guid === "string" && result.noteID === void 0) {
|
|
2887
|
+
if (isWord(result) && result.id !== void 0)
|
|
2888
|
+
result.noteID = result.id;
|
|
2895
2889
|
if (isKanji(result)) result.noteID = result.kanji;
|
|
2896
2890
|
if (isRadical(result)) result.noteID = result.radical;
|
|
2897
2891
|
if (isKana(result)) result.noteID = result.kana;
|
|
2898
|
-
if (isGrammar(result) && result.id
|
|
2892
|
+
if (isGrammar(result) && result.id !== void 0)
|
|
2893
|
+
result.noteID = result.id;
|
|
2899
2894
|
}
|
|
2900
|
-
if (typeof
|
|
2901
|
-
result.noteTypeName =
|
|
2902
|
-
if (typeof
|
|
2903
|
-
result.deckPath =
|
|
2904
|
-
if (!hasHeader.guid && result.noteID) {
|
|
2895
|
+
if (typeof noteInfo.noteType === "string" && result.noteTypeName === void 0)
|
|
2896
|
+
result.noteTypeName = noteInfo.noteType;
|
|
2897
|
+
if (typeof noteInfo.deckPath === "string" && result.deckPath === void 0)
|
|
2898
|
+
result.deckPath = noteInfo.deckPath;
|
|
2899
|
+
if (!hasHeader.guid && result.noteID !== void 0) {
|
|
2905
2900
|
headers.push(`${noteHeaderKeys.guid}${++headerCount}`);
|
|
2906
2901
|
hasHeader.guid = true;
|
|
2907
2902
|
}
|
|
2908
|
-
if (!hasHeader.noteType && result.noteTypeName) {
|
|
2903
|
+
if (!hasHeader.noteType && result.noteTypeName !== void 0) {
|
|
2909
2904
|
headers.push(`${noteHeaderKeys.notetype}${++headerCount}`);
|
|
2910
2905
|
hasHeader.noteType = true;
|
|
2911
2906
|
}
|
|
2912
|
-
if (!hasHeader.deckPath && result.deckPath) {
|
|
2907
|
+
if (!hasHeader.deckPath && result.deckPath !== void 0) {
|
|
2913
2908
|
headers.push(`${noteHeaderKeys.deck}${++headerCount}`);
|
|
2914
2909
|
hasHeader.deckPath = true;
|
|
2915
2910
|
}
|
|
@@ -2918,7 +2913,7 @@ function generateAnkiNotesFile(list, defaultNoteInfo) {
|
|
|
2918
2913
|
headers.push(`${noteHeaderKeys.tags}${note.length + headerCount}`);
|
|
2919
2914
|
hasHeader.tags = true;
|
|
2920
2915
|
}
|
|
2921
|
-
return `${result.noteID ? `${result.noteID} ` : ""}${result.noteTypeName ? `${result.noteTypeName} ` : ""}${result.deckPath ? `${result.deckPath} ` : ""}${note.join(" ")}`;
|
|
2916
|
+
return `${result.noteID !== void 0 ? `${result.noteID} ` : ""}${result.noteTypeName !== void 0 ? `${result.noteTypeName} ` : ""}${result.deckPath !== void 0 ? `${result.deckPath} ` : ""}${note.join(" ")}`;
|
|
2922
2917
|
}).join("\n").trim();
|
|
2923
2918
|
}
|
|
2924
2919
|
return `${headers.join("\n")}
|
|
@@ -2944,6 +2939,7 @@ export {
|
|
|
2944
2939
|
getWord,
|
|
2945
2940
|
getWordDefinitions,
|
|
2946
2941
|
getWordDefinitionsWithFurigana,
|
|
2942
|
+
hiraganaToKatakana,
|
|
2947
2943
|
isGrammar,
|
|
2948
2944
|
isKana,
|
|
2949
2945
|
isKanji,
|
|
@@ -2952,9 +2948,11 @@ export {
|
|
|
2952
2948
|
isStringArray,
|
|
2953
2949
|
isValidArrayWithFirstElement,
|
|
2954
2950
|
isWord,
|
|
2951
|
+
katakanaToHiragana,
|
|
2955
2952
|
notSearchedForms,
|
|
2956
2953
|
noteHeaderKeys,
|
|
2957
2954
|
noteMap,
|
|
2955
|
+
posList,
|
|
2958
2956
|
regexps,
|
|
2959
2957
|
shuffleArray
|
|
2960
2958
|
};
|