fix some minor issues involving what to do with the main spelling of an entry

This commit is contained in:
wareya committed 2017-12-19 21:37:55 -05:00
1 parent e36dab2aec
commit 9f671adf0e
2 files changed
+125 -58

No files matched your search

+57 -14
View File
@@ -111,12 +111,38 @@ function clip(str)
return str.substring(1, str.length-1); return str.substring(1, str.length-1);
} }
function getfromdict(indexes) function getfromdict(indexes, text)
{ {
let ret = []; let ret = [];
for(let i = 0; i < indexes.length; i++) for(let i = 0; i < indexes.length; i++)
{ {
let entry = dict[indexes[i]]; let entry = {};
Object.assign(entry, dict[indexes[i]]);
entry.from = text;
if(entry.k_ele)
{
for(let spelling of entry.k_ele)
{
if(spelling.keb == entry.from)
{
entry.found = spelling;
break;
}
}
}
if(!entry.found && entry.r_ele)
{
for(let spelling of entry.r_ele)
{
if(spelling.reb == entry.from)
{
entry.found = spelling;
break;
}
}
}
let lastpos = []; let lastpos = [];
// JMdict tags part-of-speech for senses sparsely // JMdict tags part-of-speech for senses sparsely
// e.g. if 1. and 2. share the same list of POSs, only 1. will have a POS list // e.g. if 1. and 2. share the same list of POSs, only 1. will have a POS list
@@ -169,9 +195,9 @@ function replace_kata_with_hira(text)
function search_inner(text) function search_inner(text)
{ {
if (lookup_kan.has(text)) if (lookup_kan.has(text))
return getfromdict(lookup_kan.get(text)); return getfromdict(lookup_kan.get(text), text);
else if (lookup_kana.has(text)) else if (lookup_kana.has(text))
return getfromdict(lookup_kana.get(text)); return getfromdict(lookup_kana.get(text), text);
else else
return; return;
} }
@@ -675,8 +701,8 @@ function build_lookup_comb (forms)
{ {
for(let r = 0; r < result.length; r++) for(let r = 0; r < result.length; r++)
{ {
let entry = {}; let entry = result[r];
Object.assign(entry, result[r]); //Object.assign(entry, result[r]);
entry.deconj = undefined; // clear if something set it before, we need this later entry.deconj = undefined; // clear if something set it before, we need this later
// store all the parts of speech that this dictionary entry can apply to // store all the parts of speech that this dictionary entry can apply to
// normally, they're scattered across its senses // normally, they're scattered across its senses
@@ -846,21 +872,24 @@ function has_pri(object)
return false; return false;
} }
function filter_kana_ish_results(results) function weird_lookup(entry)
{ {
if(results == undefined) return; if(entry.found && entry.found.inf)
let newresults = [];
for(let entry of results)
{ {
if(is_kana(entry) || prefers_kana(entry)) for(let info of entry.found.inf)
newresults.push(entry); {
if(["ik", "iK", "io"].includes(clip(info)))
{
entry.priority -= 50;
break;
}
}
} }
return newresults;
} }
function sort_results(text, results) function sort_results(text, results)
{ {
if(results == undefined) return undefined; if(results == undefined) return;
let reading_kana = is_kana(text); let reading_kana = is_kana(text);
@@ -869,6 +898,8 @@ function sort_results(text, results)
let result_kana = is_kana(entry); let result_kana = is_kana(entry);
entry.priority = (entry.seq-1000000)/-10000000; // divided by one more order of magnitude entry.priority = (entry.seq-1000000)/-10000000; // divided by one more order of magnitude
if(weird_lookup(entry))
entry.priority -= 50;
if(reading_kana == result_kana) if(reading_kana == result_kana)
entry.priority += 100; entry.priority += 100;
if(has_pri(entry)) if(has_pri(entry))
@@ -896,6 +927,18 @@ function sort_results(text, results)
return results; return results;
} }
function filter_kana_ish_results(results)
{
if(results == undefined) return;
let newresults = [];
for(let entry of results)
{
if(is_kana(entry) || prefers_kana(entry))
newresults.push(entry);
}
return newresults;
}
function skip_rereferenced_entries(results) function skip_rereferenced_entries(results)
{ {
let newresults = []; let newresults = [];
+68 -44
View File
@@ -17,12 +17,6 @@
'use strict'; 'use strict';
function print_object(message)
{
//console.log(JSON.stringify(message));
console.log(message);
}
let settings = { let settings = {
enabled: false, enabled: false,
compact: true, compact: true,
@@ -205,45 +199,44 @@ function build_div_inner (text, result)
temp.appendChild(style); temp.appendChild(style);
// lookups can have multiple results (e.g. する -> 為る, 刷る, 掏る, 剃る, 擦る) // lookups can have multiple results (e.g. する -> 為る, 刷る, 掏る, 剃る, 擦る)
// FIXME: A bunch of code here depends on the literal text used to run the search instead of the text with which the search succeeded.
// The search can convert between hiragana and katakana to find a valid match, so we should know what text it actually used.
for(let i = 0; i < result.length; i++) for(let i = 0; i < result.length; i++)
{ {
let term = result[i]; let term = result[i];
// shouldn't happen but just in case of broken data
if(!term.found)
continue;
let container = document.createElement("div"); let container = document.createElement("div");
container.className = "nazeka_word_container"; container.className = "nazeka_word_container";
container.style.marginBottom = "3px"; container.style.marginBottom = "3px";
container.setAttribute("nazeka_seq", term.seq); container.setAttribute("nazeka_seq", term.seq);
if(term.deconj && term.deconj.length > 0)
text = term.deconj.values().next().value.text; let text = "";
//print_object(term); if(term.found.keb)
text = term.found.keb;
else if(term.found.reb)
text = term.found.reb;
else
continue; // shouldn't happen, but again, just in case of broken data
let temptag = document.createElement("span"); let temptag = document.createElement("span");
temptag.className = "nazeka_word"; temptag.className = "nazeka_word";
let found_kanji = true; let found_kanji = true;
if(term.k_ele) if(term.k_ele)
{ {
// pick out which index has the kanji we looked up if we looked up kanji let looked_up_kanji = !!(term.found.keb);
let which = 0;
let looked_up_kanji = true;
while(which < term.k_ele.length && term.k_ele[which].keb != text) which += 1;
if(which >= term.k_ele.length)
{
which = 0;
looked_up_kanji = false;
}
let whichkana = 0;
let r_restr = []; let r_restr = [];
// if we didn't look up kanji, look for the first fitting kanji in the entry (they're ordered sensibly)
if(!looked_up_kanji) if(!looked_up_kanji)
{ {
while(whichkana < term.r_ele.length && term.r_ele[whichkana].reb != text) whichkana += 1; if(term.found.restr && term.found.restr.length > 0)
if(whichkana >= term.r_ele.length) r_restr = term.found.restr;
whichkana = 0; if(!r_restr)
r_restr = [];
whichkana = term.r_ele[whichkana];
if(whichkana.restr && whichkana.restr.length > 0)
r_restr = whichkana.restr;
// find the first kanji that isn't restricted to readings that aren't the one we looked up
for(let j = 0; j < term.k_ele.length; j++) for(let j = 0; j < term.k_ele.length; j++)
{ {
if(term.k_ele[j].restr) if(term.k_ele[j].restr)
@@ -252,9 +245,11 @@ function build_div_inner (text, result)
{ {
if(term.k_ele[j].restr[l] == text) if(term.k_ele[j].restr[l] == text)
{ {
if(!r_restr || r_restr.indexOf(term.k_ele[j].keb) > -1) if(r_restr.length == 0 || r_restr.indexOf(term.k_ele[j].keb) > -1)
{ {
which = j; term.found = term.k_ele[j];
//console.log("reassigned found")
//console.log(term.found);
found_kanji = true; found_kanji = true;
break; break;
} }
@@ -263,9 +258,11 @@ function build_div_inner (text, result)
} }
else else
{ {
if(!r_restr || r_restr.indexOf(term.k_ele[j].keb) > -1) if(r_restr.length == 0 || r_restr.indexOf(term.k_ele[j].keb) > -1)
{ {
which = j; term.found = term.k_ele[j];
//console.log("reassigned found")
//console.log(term.found);
found_kanji = true; found_kanji = true;
break; break;
} }
@@ -276,7 +273,8 @@ function build_div_inner (text, result)
found_kanji = true; found_kanji = true;
if(found_kanji) if(found_kanji)
{ {
let kanji_text = term.k_ele[which].keb; let k_ele = term.found;
let kanji_text = k_ele.keb;
let keb = document.createElement("span"); let keb = document.createElement("span");
keb.className = "nazeka_main_keb"; keb.className = "nazeka_main_keb";
keb.textContent = kanji_text; keb.textContent = kanji_text;
@@ -332,6 +330,21 @@ function build_div_inner (text, result)
} }
temptag.appendChild(document.createTextNode(deconj)); temptag.appendChild(document.createTextNode(deconj));
} }
if(k_ele.inf)
{
let maininfos = document.createElement("span");
maininfos.className = "nazeka_main_infos";
for(let info of k_ele.inf)
{
let keb_inf = document.createElement("span");
keb_inf.className = "nazeka_main_inf";
keb_inf.textContent += "(";
keb_inf.textContent += clip(info);
keb_inf.textContent += ")";
maininfos.appendChild(keb_inf);
}
temptag.appendChild(maininfos);
}
temptag.appendChild(document.createTextNode(" 《")); temptag.appendChild(document.createTextNode(" 《"));
let e_readings = document.createElement("span"); let e_readings = document.createElement("span");
e_readings.className = "nazeka_readings"; e_readings.className = "nazeka_readings";
@@ -371,7 +384,7 @@ function build_div_inner (text, result)
if(k.restr[l] == text) if(k.restr[l] == text)
invalid = false; invalid = false;
} }
if(!looked_up_kanji && r_restr !== [] && r_restr.length > 0 && r_restr.indexOf(k.keb) < 0) if(!looked_up_kanji && r_restr.indexOf(k.keb) < 0)
invalid = true; invalid = true;
if(!invalid) if(!invalid)
alternatives.push(term.k_ele[j]); alternatives.push(term.k_ele[j]);
@@ -409,7 +422,7 @@ function build_div_inner (text, result)
{ {
let main_reb = document.createElement("span"); let main_reb = document.createElement("span");
main_reb.className = "nazeka_main_reb"; main_reb.className = "nazeka_main_reb";
main_reb.textContent = text; main_reb.textContent = term.found.reb;
temptag.appendChild(main_reb); temptag.appendChild(main_reb);
// FIXME: show inf for located reb // FIXME: show inf for located reb
if(term.deconj) if(term.deconj)
@@ -444,6 +457,19 @@ function build_div_inner (text, result)
} }
temptag.appendChild(document.createTextNode(deconj)); temptag.appendChild(document.createTextNode(deconj));
} }
// FIXME wrapper span
if(term.found.inf)
{
for(let info of term.found.inf)
{
let reb_inf = document.createElement("span");
reb_inf.className = "nazeka_reb_inf";
reb_inf.textContent += "(";
reb_inf.textContent += clip(info);
reb_inf.textContent += ")";
temptag.appendChild(reb_inf);
}
}
// list alternatives // list alternatives
let alternatives = []; let alternatives = [];
@@ -964,7 +990,7 @@ async function mine_to_storage(object)
let cards = (await browser.storage.local.get("cards")).cards; let cards = (await browser.storage.local.get("cards")).cards;
if(!cards) if(!cards)
cards = []; cards = [];
console.log(cards); //console.log(cards);
cards.push(object); cards.push(object);
browser.storage.local.set({cards:cards}); browser.storage.local.set({cards:cards});
} }
@@ -980,10 +1006,10 @@ function mine(highlight)
let definitions = word.getElementsByClassName("nazeka_definitions")[0].textContent; let definitions = word.getElementsByClassName("nazeka_definitions")[0].textContent;
let seq = word.getAttribute("nazeka_seq"); let seq = word.getAttribute("nazeka_seq");
console.log(front); //console.log(front);
console.log(readings); //console.log(readings);
console.log(definitions); //console.log(definitions);
console.log(seq); //console.log(seq);
mine_to_storage({front: front, readings: readings, definitions: definitions, seq: seq}); mine_to_storage({front: front, readings: readings, definitions: definitions, seq: seq});
} }
@@ -994,11 +1020,9 @@ function keytest(event)
return; return;
if(!exists_div()) if(!exists_div())
return; return;
console.log("key");
console.log(event.key);
if(event.key == "m") if(event.key == "m")
{ {
console.log("mining request"); //console.log("mining request");
let mydiv = document.body.getElementsByClassName(div_class)[0].cloneNode(true); let mydiv = document.body.getElementsByClassName(div_class)[0].cloneNode(true);
delete_div(); delete_div();
mydiv.style.position = "fixed"; mydiv.style.position = "fixed";