Skip to content

Commit 995597a

Browse files
add wiktionary backlinks (#207)
* add wiktionary backlinks * css * try fixing test * write test
1 parent d95bec2 commit 995597a

40 files changed

+743
-52
lines changed

3-tidy-up.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ lr.on('line', (line) => {
126126
* @param {KaikkiLine} parsedLine
127127
*/
128128
function handleLine(parsedLine) {
129-
const { pos, sounds, forms, etymology_number = 0, etymology_text} = parsedLine;
129+
const { pos, sounds, forms, etymology_number = 0, etymology_text, word: backlink} = parsedLine;
130130
if(!pos) return;
131131
const word = getCanonicalWordForm(parsedLine);
132132
if (!word) return;
@@ -253,6 +253,7 @@ function handleLine(parsedLine) {
253253

254254
result.ipa ??= ipa;
255255
result.glossTree = glossTree;
256+
result.backlink = backlink;
256257
}
257258

258259
}

4-make-yomitan.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const { sortTags, writeInBatches, consoleOverwrite,
66

77
const {
88
source_iso,
9+
source_language,
910
target_iso,
1011
DEBUG_WORD,
1112
DICT_NAME,
@@ -274,6 +275,18 @@ function getStructuredPreamble(info) {
274275
};
275276
}
276277

278+
/**string
279+
* @param {string} backlinkWord
280+
* @returns {import('types').TermBank.StructuredContent}
281+
*/
282+
function getStructuredBacklink(backlinkWord) {
283+
return {
284+
"tag": "a",
285+
"href": `https://${target_iso}.wiktionary.org/wiki/${backlinkWord}#${source_language}`,
286+
"content": "Wiktionary",
287+
}
288+
}
289+
277290
/**
278291
* @param {GlossBranch} glossBranch
279292
* @param {string[]} parentTags
@@ -460,6 +473,17 @@ let lastTermBankIndex = 0;
460473
});
461474
}
462475

476+
if (info.backlink) {
477+
const backlink = getStructuredBacklink(info.backlink);
478+
entryContent.push({
479+
"tag": "div",
480+
"data": {
481+
"content": "backlink"
482+
},
483+
content: [backlink]
484+
});
485+
}
486+
463487
/** @type {import('types').TermBank.DetailedDefinition}*/
464488
const structuredEntry = {
465489
"type": "structured-content",

4-make-yomitan.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ for (const dir of ["./data/test/dict", "./data/test/tidy", "./data/test/temp", "
1212
const languages = JSON.parse(readFileSync('languages.json', 'utf8'));
1313

1414

15-
for (const {iso: sourceIso} of languages){
15+
for (const {iso: sourceIso, language: sourceLanguage} of languages){
1616
for (const {iso: targetIso} of languages){
1717
const tidyLemmas = `data/test/tidy/${sourceIso}-${targetIso}-lemmas.json`;
1818
const tidyForms = `data/test/tidy/${sourceIso}-${targetIso}-forms-0.json`;
@@ -27,6 +27,7 @@ for (const {iso: sourceIso} of languages){
2727
env:{
2828
...process.env,
2929
source_iso: sourceIso,
30+
source_language: sourceLanguage,
3031
target_iso: targetIso,
3132
DICT_NAME: 'test',
3233
tidy_folder: `./data/test/tidy`,

data/styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,8 @@ summary[data-sc-content="summary-entry"]:hover {
6868
}
6969
summary[data-sc-content="summary-entry"] ~ div {
7070
margin: 0.5em 0;
71+
}
72+
div[data-sc-content="backlink"] {
73+
font-size: 0.7em;
74+
text-align: right;
7175
}

data/test/dict/cs/en/term_bank_1.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,19 @@
215215
]
216216
}
217217
]
218+
},
219+
{
220+
"tag": "div",
221+
"data": {
222+
"content": "backlink"
223+
},
224+
"content": [
225+
{
226+
"tag": "a",
227+
"href": "https://en.wiktionary.org/wiki/zpráva#Czech",
228+
"content": "Wiktionary"
229+
}
230+
]
218231
}
219232
]
220233
}
@@ -328,6 +341,19 @@
328341
]
329342
}
330343
]
344+
},
345+
{
346+
"tag": "div",
347+
"data": {
348+
"content": "backlink"
349+
},
350+
"content": [
351+
{
352+
"tag": "a",
353+
"href": "https://en.wiktionary.org/wiki/pro#Czech",
354+
"content": "Wiktionary"
355+
}
356+
]
331357
}
332358
]
333359
}
@@ -398,6 +424,19 @@
398424
]
399425
}
400426
]
427+
},
428+
{
429+
"tag": "div",
430+
"data": {
431+
"content": "backlink"
432+
},
433+
"content": [
434+
{
435+
"tag": "a",
436+
"href": "https://en.wiktionary.org/wiki/přít#Czech",
437+
"content": "Wiktionary"
438+
}
439+
]
401440
}
402441
]
403442
}

data/test/dict/de/de/term_bank_1.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,19 @@
119119
]
120120
}
121121
]
122+
},
123+
{
124+
"tag": "div",
125+
"data": {
126+
"content": "backlink"
127+
},
128+
"content": [
129+
{
130+
"tag": "a",
131+
"href": "https://de.wiktionary.org/wiki/Rock#German",
132+
"content": "Wiktionary"
133+
}
134+
]
122135
}
123136
]
124137
}
@@ -190,6 +203,19 @@
190203
]
191204
}
192205
]
206+
},
207+
{
208+
"tag": "div",
209+
"data": {
210+
"content": "backlink"
211+
},
212+
"content": [
213+
{
214+
"tag": "a",
215+
"href": "https://de.wiktionary.org/wiki/Rock#German",
216+
"content": "Wiktionary"
217+
}
218+
]
193219
}
194220
]
195221
}
@@ -548,6 +574,19 @@
548574
]
549575
}
550576
]
577+
},
578+
{
579+
"tag": "div",
580+
"data": {
581+
"content": "backlink"
582+
},
583+
"content": [
584+
{
585+
"tag": "a",
586+
"href": "https://de.wiktionary.org/wiki/Garage#German",
587+
"content": "Wiktionary"
588+
}
589+
]
551590
}
552591
]
553592
}

data/test/dict/de/en/term_bank_1.json

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,19 @@
885885
]
886886
}
887887
]
888+
},
889+
{
890+
"tag": "div",
891+
"data": {
892+
"content": "backlink"
893+
},
894+
"content": [
895+
{
896+
"tag": "a",
897+
"href": "https://en.wiktionary.org/wiki/pflegen#German",
898+
"content": "Wiktionary"
899+
}
900+
]
888901
}
889902
]
890903
}
@@ -1376,6 +1389,19 @@
13761389
]
13771390
}
13781391
]
1392+
},
1393+
{
1394+
"tag": "div",
1395+
"data": {
1396+
"content": "backlink"
1397+
},
1398+
"content": [
1399+
{
1400+
"tag": "a",
1401+
"href": "https://en.wiktionary.org/wiki/Fuchs#German",
1402+
"content": "Wiktionary"
1403+
}
1404+
]
13791405
}
13801406
]
13811407
}
@@ -1507,6 +1533,19 @@
15071533
]
15081534
}
15091535
]
1536+
},
1537+
{
1538+
"tag": "div",
1539+
"data": {
1540+
"content": "backlink"
1541+
},
1542+
"content": [
1543+
{
1544+
"tag": "a",
1545+
"href": "https://en.wiktionary.org/wiki/Herz#German",
1546+
"content": "Wiktionary"
1547+
}
1548+
]
15101549
}
15111550
]
15121551
}
@@ -1599,6 +1638,19 @@
15991638
]
16001639
}
16011640
]
1641+
},
1642+
{
1643+
"tag": "div",
1644+
"data": {
1645+
"content": "backlink"
1646+
},
1647+
"content": [
1648+
{
1649+
"tag": "a",
1650+
"href": "https://en.wiktionary.org/wiki/Fahrer#German",
1651+
"content": "Wiktionary"
1652+
}
1653+
]
16021654
}
16031655
]
16041656
}
@@ -2012,6 +2064,19 @@
20122064
]
20132065
}
20142066
]
2067+
},
2068+
{
2069+
"tag": "div",
2070+
"data": {
2071+
"content": "backlink"
2072+
},
2073+
"content": [
2074+
{
2075+
"tag": "a",
2076+
"href": "https://en.wiktionary.org/wiki/von#German",
2077+
"content": "Wiktionary"
2078+
}
2079+
]
20152080
}
20162081
]
20172082
}
@@ -2149,6 +2214,19 @@
21492214
]
21502215
}
21512216
]
2217+
},
2218+
{
2219+
"tag": "div",
2220+
"data": {
2221+
"content": "backlink"
2222+
},
2223+
"content": [
2224+
{
2225+
"tag": "a",
2226+
"href": "https://en.wiktionary.org/wiki/Base#German",
2227+
"content": "Wiktionary"
2228+
}
2229+
]
21522230
}
21532231
]
21542232
}
@@ -2258,6 +2336,19 @@
22582336
]
22592337
}
22602338
]
2339+
},
2340+
{
2341+
"tag": "div",
2342+
"data": {
2343+
"content": "backlink"
2344+
},
2345+
"content": [
2346+
{
2347+
"tag": "a",
2348+
"href": "https://en.wiktionary.org/wiki/Base#German",
2349+
"content": "Wiktionary"
2350+
}
2351+
]
22612352
}
22622353
]
22632354
}

data/test/dict/en/de/term_bank_1.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,19 @@
2727
]
2828
}
2929
]
30+
},
31+
{
32+
"tag": "div",
33+
"data": {
34+
"content": "backlink"
35+
},
36+
"content": [
37+
{
38+
"tag": "a",
39+
"href": "https://de.wiktionary.org/wiki/choose#English",
40+
"content": "Wiktionary"
41+
}
42+
]
3043
}
3144
]
3245
}

0 commit comments

Comments
 (0)