initial work on supporting the kenkyusha epwing dictionary - format should be what zero-epwing spits out, but entries only
This commit is contained in:
1 parent
4b0fb07762
commit
6fc55999de
3 files changed
+113
-3
No files matched your search
+106
-2
@@ -8,6 +8,79 @@
|
|||||||
// We have to send an HTTP request and store the result in a string before parsing it into an object.
|
// We have to send an HTTP request and store the result in a string before parsing it into an object.
|
||||||
// Seriously.
|
// Seriously.
|
||||||
|
|
||||||
|
let epwing = [
|
||||||
|
];
|
||||||
|
let lookup_epwing_kan = new Map();
|
||||||
|
let lookup_epwing_kana = new Map();
|
||||||
|
|
||||||
|
|
||||||
|
function string_is_kana(str)
|
||||||
|
{
|
||||||
|
for(let i = 0; i < str.length; i++)
|
||||||
|
{
|
||||||
|
let codepoint = str.codePointAt(i);
|
||||||
|
if(!(codepoint >= 0x3040 && codepoint <= 0x30FF))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function add_epwing_id(id, i)
|
||||||
|
{
|
||||||
|
if(string_is_kana(id))
|
||||||
|
{
|
||||||
|
if (!lookup_epwing_kana.has(id))
|
||||||
|
lookup_epwing_kana.set(id, [i]);
|
||||||
|
else
|
||||||
|
lookup_epwing_kana.get(id).push(i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!lookup_epwing_kan.has(id))
|
||||||
|
lookup_epwing_kan.set(id, [i]);
|
||||||
|
else
|
||||||
|
lookup_epwing_kan.get(id).push(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < epwing.length; i++)
|
||||||
|
{
|
||||||
|
let heading = epwing[i]["heading"];
|
||||||
|
let text = epwing[i]["text"];
|
||||||
|
if(heading.startsWith("¶"))
|
||||||
|
{
|
||||||
|
let id = heading.match(/¶([^<]*)/)[1].trim();
|
||||||
|
// there's stuff inside the brackets but it doesn't represent this dictionary entry, just another one where it appears
|
||||||
|
add_epwing_id(id, i);
|
||||||
|
}
|
||||||
|
else if(heading.includes("<") && heading.includes("【"))
|
||||||
|
{
|
||||||
|
let useful = heading.match(/<(.*)>/)[1].trim();
|
||||||
|
let kana = useful.match(/([^【]*)/)[1].trim();
|
||||||
|
let kanji = useful.match(/【([^】]*)/)[1].trim();
|
||||||
|
add_epwing_id(kanji, i);
|
||||||
|
add_epwing_id(kana, i);
|
||||||
|
}
|
||||||
|
else if(heading.includes("<") && !heading.includes("【"))
|
||||||
|
{
|
||||||
|
let kana = heading.match(/([^<]*)/)[1].trim();
|
||||||
|
let kanji = heading.match(/<(.*)>/)[1].trim();
|
||||||
|
add_epwing_id(kanji, i);
|
||||||
|
add_epwing_id(kana, i);
|
||||||
|
}
|
||||||
|
else if(text.split(/\\n/)[0].includes("【"))
|
||||||
|
{
|
||||||
|
let useful = text.match(/([^】]*】)/)[1].trim();
|
||||||
|
let kana = useful.match(/([^【]*)/)[1].trim();
|
||||||
|
let kanji = useful.match(/【([^】]*)/)[1].trim();
|
||||||
|
add_epwing_id(kanji, i);
|
||||||
|
add_epwing_id(kana, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
console.log(`Unknown kind of entry at index ${i} in epwing dictionary`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let dict = [];
|
let dict = [];
|
||||||
let lookup_kan = new Map();
|
let lookup_kan = new Map();
|
||||||
let lookup_kana = new Map();
|
let lookup_kana = new Map();
|
||||||
@@ -200,6 +273,15 @@ function search_inner(text)
|
|||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
function search_inner_epwing(text)
|
||||||
|
{
|
||||||
|
if (lookup_epwing_kan.has(text))
|
||||||
|
return epwing[lookup_epwing_kan.get(text)];
|
||||||
|
else if (lookup_epwing_kana.has(text))
|
||||||
|
return epwing[lookup_epwing_kana.get(text)];
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function search(text)
|
function search(text)
|
||||||
{
|
{
|
||||||
@@ -760,7 +842,29 @@ function build_lookup_comb (forms)
|
|||||||
//console.log("testing A");
|
//console.log("testing A");
|
||||||
//print_object(entry);
|
//print_object(entry);
|
||||||
if(entry.deconj)
|
if(entry.deconj)
|
||||||
|
{
|
||||||
|
let epwing_data = "";
|
||||||
|
if(entry.k_ele)
|
||||||
|
{
|
||||||
|
for(let spelling of entry.k_ele)
|
||||||
|
{
|
||||||
|
let res = search_inner_epwing(spelling.keb);
|
||||||
|
if(res && res["text"])
|
||||||
|
epwing_data = res["text"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(epwing_data == "" && entry.r_ele)
|
||||||
|
{
|
||||||
|
for(let spelling of entry.r_ele)
|
||||||
|
{
|
||||||
|
let res = search_inner_epwing(spelling.reb);
|
||||||
|
if(res && res["text"])
|
||||||
|
epwing_data = res["text"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
entry.epwing = epwing_data;
|
||||||
merger.push(entry);
|
merger.push(entry);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//print_object(merger);
|
//print_object(merger);
|
||||||
@@ -943,11 +1047,11 @@ function skip_rereferenced_entries(results)
|
|||||||
let newresults = [];
|
let newresults = [];
|
||||||
let seenseq = new Set();
|
let seenseq = new Set();
|
||||||
|
|
||||||
console.log(results);
|
//console.log(results);
|
||||||
for(let lookup of results)
|
for(let lookup of results)
|
||||||
{
|
{
|
||||||
let newlookup = [];
|
let newlookup = [];
|
||||||
console.log(lookup);
|
//console.log(lookup);
|
||||||
for(let entry of lookup.result)
|
for(let entry of lookup.result)
|
||||||
{
|
{
|
||||||
if(seenseq.has(entry.seq))
|
if(seenseq.has(entry.seq))
|
||||||
|
|||||||
+2
-1
@@ -8,7 +8,8 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class=panel>
|
<div class=panel>
|
||||||
<p>View the tutorial <a href="https://github.com/wareya/nazeka/blob/master/tutorial.md">here!</a></p>
|
<!-- target=_blank prevents firefox mobile from opening the link inside the about:addons page and hitting a CSP error -->
|
||||||
|
<p>View the tutorial <a href="https://github.com/wareya/nazeka/blob/master/tutorial.md" target="_blank">here!</a></p>
|
||||||
|
|
||||||
<form name=optform>
|
<form name=optform>
|
||||||
<div id=optionsection>
|
<div id=optionsection>
|
||||||
|
|||||||
@@ -697,6 +697,11 @@ function build_div_inner (text, result)
|
|||||||
definition.appendChild(document.createElement("br"));
|
definition.appendChild(document.createElement("br"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if(term.epwing)
|
||||||
|
{
|
||||||
|
definition.appendChild(document.createElement("br"));
|
||||||
|
definition.appendChild(document.createTextNode(term.epwing));
|
||||||
|
}
|
||||||
container.appendChild(definition);
|
container.appendChild(definition);
|
||||||
if(settings.corner == 2 || settings.corner == 3)
|
if(settings.corner == 2 || settings.corner == 3)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in new issue
Block a user