From 031ae7c5c62a7994c0e8322e415ee4f3a6dc3965 Mon Sep 17 00:00:00 2001 From: wareya Date: Tue, 30 Jan 2018 20:33:17 -0500 Subject: [PATCH] fix epwing lookup reading priority --- background-script.js | 111 ++++++++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 32 deletions(-) diff --git a/background-script.js b/background-script.js index 851aa39..ed0f6d5 100644 --- a/background-script.js +++ b/background-script.js @@ -9,6 +9,7 @@ // Seriously. let epwing = [ +// Fill this out with some testing data from a json file generated by zero-epwing so that it looks something like this screenshot: https://i.imgur.com/waTYH1i.png ]; let lookup_epwing_kan = new Map(); let lookup_epwing_kana = new Map(); @@ -41,6 +42,7 @@ function add_epwing_id(id, i) } } +// FIXME: this is almost certainly only the format of the kenkyuusha epwing dictionary. others might be completely different. for (let i = 0; i < epwing.length; i++) { let heading = epwing[i]["heading"]; @@ -272,15 +274,6 @@ function search_inner(text) else 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) { @@ -838,30 +831,8 @@ function build_lookup_comb (forms) { for(let entry of result) { - //console.log("testing A"); - //print_object(entry); 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); } } @@ -873,6 +844,82 @@ function build_lookup_comb (forms) return; } +function add_epwing_info(lookups) +{ + for(let lookup of lookups) + { + for(let entry of lookup.result) + { + // look for an epwing entry that matches this lookup and jmdict entry + let epwing_data = ""; + let foundtext = undefined; + if(entry.orig_found.keb) + foundtext = entry.orig_found.keb; + else + foundtext = entry.orig_found.reb; + + let exact = false; + if(entry.k_ele) + { + for(let spelling of entry.k_ele) + { + let text = spelling.keb; + if (lookup_epwing_kan.has(text)) + { + let possibilities = lookup_epwing_kan.get(text); + for(let wing of possibilities) + { + if(epwing[wing] && epwing[wing]["text"]) + { + if(epwing_data == "") + { + epwing_data = epwing[wing]["text"]; + // FIXME: using .includes() is too loose. just simpler than adding real arrays of spellings/readings to the epwing data on load. + exact = (epwing[wing]["heading"].includes(foundtext) || epwing[wing]["text"].includes(foundtext)); + } + else if(!exact && (epwing[wing]["heading"].includes(foundtext) || epwing[wing]["text"].includes(foundtext))) + { + epwing_data = epwing[wing]["text"]; + exact = true; + } + } + } + } + } + } + if(epwing_data == "" && entry.r_ele) + { + for(let spelling of entry.r_ele) + { + let text = spelling.reb; + if (lookup_epwing_kana.has(text)) + { + let possibilities = lookup_epwing_kana.get(text); + for(let wing of possibilities) + { + if(epwing[wing] && epwing[wing]["text"]) + { + if(epwing_data == "") + { + epwing_data = epwing[wing]["text"]; + exact = (epwing[wing]["heading"].includes(foundtext) || epwing[wing]["text"].includes(foundtext)); + } + else if(!exact && (epwing[wing]["heading"].includes(foundtext) || epwing[wing]["text"].includes(foundtext))) + { + epwing_data = epwing[wing]["text"]; + exact = true; + } + } + } + } + } + } + entry.epwing = epwing_data; + } + } + return lookups; +} + function is_kana(object) @@ -1223,7 +1270,7 @@ function skip_rereferenced_entries(results) if(newlookup.length > 0) newresults.push({text:lookup.text, result:newlookup}); } - return newresults; + return add_epwing_info(newresults); // add epwing entries now } let last_lookup = "";