fixup bananza

This commit is contained in:
wareya committed 2019-01-17 23:10:40 -05:00
1 parent bdb7c02b9d
commit 14892beed9
5 files changed
+104 -173

No files matched your search

+18 -23
View File
@@ -379,18 +379,9 @@ load_deconjugation_rules("dict/deconjugator.json");
// return deconjugated form if stdrule applies to form, return otherwise // return deconjugated form if stdrule applies to form, return otherwise
function stdrule_deconjugate_inner(my_form, my_rule) function stdrule_deconjugate_inner(my_form, my_rule)
{ {
// can't deconjugate nothingness
if(my_form.text == "")
return;
// ending doesn't match // ending doesn't match
if(!my_form.text.endsWith(my_rule.con_end)) if(!my_form.text.endsWith(my_rule.con_end))
return; return;
// deconjugated form too much longer than conjugated form
if(my_form.text.length > my_form.original_text.length+10)
return;
// impossibly information-dense
if(my_form.tags.length > my_form.original_text.length+6)
return;
// tag doesn't match // tag doesn't match
if(my_form.tags.length > 0 && my_form.tags[my_form.tags.length-1] != my_rule.con_tag) if(my_form.tags.length > 0 && my_form.tags[my_form.tags.length-1] != my_rule.con_tag)
return; return;
@@ -421,6 +412,19 @@ function stdrule_deconjugate_inner(my_form, my_rule)
}; };
function stdrule_deconjugate(my_form, my_rule) function stdrule_deconjugate(my_form, my_rule)
{ {
// can't deconjugate nothingness
if(my_form.text == "")
return;
// deconjugated form too much longer than conjugated form
if(my_form.text.length > my_form.original_text.length+10)
return;
// impossibly information-dense
if(my_form.tags.length > my_form.original_text.length+6)
return;
// blank detail mean it can't be the last (first applied, but rightmost) rule
if(my_rule.detail == "" && my_form.tags.length == 0)
return;
let array = undefined; let array = undefined;
// pick the first one that is an array // pick the first one that is an array
// FIXME: use minimum length for safety reasons? assert all arrays equal length? // FIXME: use minimum length for safety reasons? assert all arrays equal length?
@@ -496,19 +500,11 @@ neverfinalrule: neverfinalrule_deconjugate,
contextrule: contextrule_deconjugate, contextrule: contextrule_deconjugate,
}; };
function adjspecial_check(my_form, my_rule) function v1inftrap_check(my_form, my_rule)
{ {
if(my_form.tags.length != 2) return true; if(my_form.tags.length != 1) return true;
let my_tag = my_form.tags[my_form.tags.length-2]; let my_tag = my_form.tags[0];
if(my_tag == "stem-adj-base") if(my_tag == "stem-ren")
return false;
return true;
};
function tetrap_check(my_form, my_rule)
{
if(my_form.tags.length < 2) return true;
let my_tag = my_form.tags[my_form.tags.length-2];
if(my_tag == "stem-te")
return false; return false;
return true; return true;
}; };
@@ -523,8 +519,7 @@ function saspecial_check(my_form, my_rule)
}; };
let context_functions = { let context_functions = {
adjspecial: adjspecial_check, v1inftrap: v1inftrap_check,
tetrap: tetrap_check,
saspecial: saspecial_check, saspecial: saspecial_check,
}; };
+73 -31
View File
@@ -83,7 +83,9 @@
"る", "る",
"る", "る",
"う", "う",
"く" "く",
"くる",
"来る"
], ],
"con_end": [ "con_end": [
"け", "け",
@@ -99,7 +101,9 @@
"ろ", "ろ",
"よ", "よ",
"え", "え",
"け" "け",
"こい",
"来い"
], ],
"dec_tag": [ "dec_tag": [
"v5k", "v5k",
@@ -115,7 +119,9 @@
"v1", "v1",
"v1", "v1",
"v5u-s", "v5u-s",
"v5k-s" "v5k-s",
"vk",
"vk"
], ],
"con_tag": "uninflectable", "con_tag": "uninflectable",
"detail": "imperative" "detail": "imperative"
@@ -275,8 +281,7 @@
}, },
"ones that need the te trap", "ones that need the te trap",
{ {
"type": "contextrule", "type": "stdrule",
"contextrule": "tetrap",
"dec_end": [ "dec_end": [
"す", "す",
"る" "る"
@@ -297,15 +302,22 @@
"type": "neverfinalrule", "type": "neverfinalrule",
"dec_end": [ "dec_end": [
"", "",
"る" "る",
"くる",
"来る"
], ],
"con_end": [ "con_end": [
"", "",
"" "",
"こ",
"来"
], ],
"dec_tag": [ "dec_tag": [
"stem-a", "stem-a",
"v1" "v1",
"vk",
"vk",
"vk"
], ],
"con_tag": "stem-mizenkei", "con_tag": "stem-mizenkei",
"detail": "(mizenkei)" "detail": "(mizenkei)"
@@ -473,8 +485,8 @@
"tag alias", "tag alias",
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "", "dec_end": ["て", "で"],
"con_end": "", "con_end": ["て", "で"],
"dec_tag": "stem-te-verbal", "dec_tag": "stem-te-verbal",
"con_tag": "stem-te", "con_tag": "stem-te",
"detail": "" "detail": ""
@@ -516,8 +528,7 @@
}, },
"negatives", "negatives",
{ {
"type": "contextrule", "type": "stdrule",
"contextrule": "adjspecial",
"dec_end": "", "dec_end": "",
"con_end": "ない", "con_end": "ない",
"dec_tag": "stem-mizenkei", "dec_tag": "stem-mizenkei",
@@ -557,8 +568,7 @@
"detail": "archaic negative" "detail": "archaic negative"
}, },
{ {
"type": "contextrule", "type": "stdrule",
"contextrule": "adjspecial",
"dec_end": "", "dec_end": "",
"con_end": "ない", "con_end": "ない",
"dec_tag": "stem-ku", "dec_tag": "stem-ku",
@@ -794,6 +804,15 @@
"con_tag": "v1", "con_tag": "v1",
"detail": "teiru" "detail": "teiru"
}, },
{
"type": "contextrule",
"contextrule": "v1inftrap",
"dec_end": "",
"con_end": "る",
"dec_tag": "stem-te",
"con_tag": "v1",
"detail": "teru (teiru)"
},
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "", "dec_end": "",
@@ -802,6 +821,14 @@
"con_tag": "v5r", "con_tag": "v5r",
"detail": "teoru" "detail": "teoru"
}, },
{
"type": "stdrule",
"dec_end": ["て", "で"],
"con_end": ["とる", "どる"],
"dec_tag": "stem-te",
"con_tag": "v5r",
"detail": "toru (teoru)"
},
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "", "dec_end": "",
@@ -818,6 +845,14 @@
"con_tag": "v5k-s", "con_tag": "v5k-s",
"detail": "teiku" "detail": "teiku"
}, },
{
"type": "stdrule",
"dec_end": "",
"con_end": "く",
"dec_tag": "stem-te",
"con_tag": "v5k-s",
"detail": "teku (teiku)"
},
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "", "dec_end": "",
@@ -834,22 +869,30 @@
"con_tag": "v5k", "con_tag": "v5k",
"detail": "for now" "detail": "for now"
}, },
{
"type": "stdrule",
"dec_end": ["て", "で"],
"con_end": ["とく", "どく"],
"dec_tag": "stem-te",
"con_tag": "v5k",
"detail": "toku (for now)"
},
"nonverbal functions of the te form", "nonverbal functions of the te form",
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "", "dec_end": "",
"con_end": "は", "con_end": "は",
"dec_tag": "stem-te", "dec_tag": "stem-te",
"con_tag": "uninflectable", "con_tag": "topic-condition",
"detail": "topic" "detail": "topic/condition"
}, },
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "", "dec_end": "",
"con_end": "は", "con_end": "は",
"dec_tag": "stem-te-defective", "dec_tag": "stem-te-defective",
"con_tag": "uninflectable", "con_tag": "topic-condition",
"detail": "topic" "detail": "topic/condition"
}, },
"TODO: ても too?", "TODO: ても too?",
"===ren'youkei based forms===", "===ren'youkei based forms===",
@@ -902,8 +945,7 @@
"detail": "tari" "detail": "tari"
}, },
{ {
"type": "contextrule", "type": "stdrule",
"contextrule": "adjspecial",
"dec_end": "", "dec_end": "",
"con_end": "たい", "con_end": "たい",
"dec_tag": "stem-ren", "dec_tag": "stem-ren",
@@ -925,7 +967,7 @@
"con_end": "ちゃう", "con_end": "ちゃう",
"dec_tag": "v5u", "dec_tag": "v5u",
"con_tag": "v5u", "con_tag": "v5u",
"detail": "(contraction)" "detail": "contracted"
}, },
{ {
"type": "stdrule", "type": "stdrule",
@@ -933,7 +975,7 @@
"con_end": "じゃう", "con_end": "じゃう",
"dec_tag": "v5u", "dec_tag": "v5u",
"con_tag": "v5u", "con_tag": "v5u",
"detail": "(contraction)" "detail": "contracted"
}, },
{ {
"type": "stdrule", "type": "stdrule",
@@ -941,7 +983,7 @@
"con_end": "ちまう", "con_end": "ちまう",
"dec_tag": "v5u", "dec_tag": "v5u",
"con_tag": "v5u", "con_tag": "v5u",
"detail": "(contraction)" "detail": "contracted"
}, },
{ {
"type": "stdrule", "type": "stdrule",
@@ -949,23 +991,23 @@
"con_end": "じまう", "con_end": "じまう",
"dec_tag": "v5u", "dec_tag": "v5u",
"con_tag": "v5u", "con_tag": "v5u",
"detail": "(contraction)" "detail": "contracted"
}, },
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "ては", "dec_end": "ては",
"con_end": "ちゃ", "con_end": "ちゃ",
"dec_tag": "stem-te", "dec_tag": "topic-condition",
"con_tag": "uninflectable", "con_tag": "uninflectable",
"detail": "(contraction)" "detail": "contracted"
}, },
{ {
"type": "stdrule", "type": "stdrule",
"dec_end": "では", "dec_end": "では",
"con_end": "じゃ", "con_end": "じゃ",
"dec_tag": "stem-te", "dec_tag": "topic-condition",
"con_tag": "uninflectable", "con_tag": "uninflectable",
"detail": "(contraction)" "detail": "contracted"
}, },
{ {
"type": "onlyfinalrule", "type": "onlyfinalrule",
@@ -973,7 +1015,7 @@
"con_end": "けりゃ", "con_end": "けりゃ",
"dec_tag": "uninflectable", "dec_tag": "uninflectable",
"con_tag": "uninflectable", "con_tag": "uninflectable",
"detail": "(contraction)" "detail": "contracted"
}, },
{ {
"type": "onlyfinalrule", "type": "onlyfinalrule",
@@ -981,7 +1023,7 @@
"con_end": "きゃ", "con_end": "きゃ",
"dec_tag": "uninflectable", "dec_tag": "uninflectable",
"con_tag": "uninflectable", "con_tag": "uninflectable",
"detail": "(contraction)" "detail": "contracted"
}, },
"other", "other",
{ {
@@ -1016,5 +1058,5 @@
"con_tag": "uninflectable", "con_tag": "uninflectable",
"detail": "slurred" "detail": "slurred"
}, },
"// TODO: a bunch of missing contractions, and support for other verb types like vk (くる), vs_i (true する verbs), v5aru (なさる, くださる, etc), v4r (ござる, etc), ..." "// TODO: support for other verb types like vk (くる) (started, incomplete), vs_i (true する verbs), v5aru (なさる, くださる, etc), v4r (ござる, etc), ..."
] ]
-76
View File
@@ -1,76 +0,0 @@
{
"manifest_version": 2,
"name": "nazeka",
"version": "0.2.5.0",
"author": "Wareya",
"homepage_url": "https://github.com/wareya/nazeka",
"description": "A rikai replacement.",
"permissions": [
"contextMenus",
"storage",
"tabs",
"clipboardRead",
"https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?*"
],
"background": {
"page": "background.html"
},
"web_accessible_resources": [
"include/browser-polyfill.min.js",
"img/closebutton24.png",
"img/leftarrow24.png",
"img/rightarrow24.png",
"dict/JMdict1.json",
"dict/JMdict2.json",
"dict/JMdict3.json",
"dict/JMdict4.json",
"dict/JMdict5.json",
"dict/JMdict6.json",
"dict/JMdict7.json",
"dict/JMdict8.json",
"dict/JMdict9.json",
"dict/JMdict10.json",
"dict/JMdict11.json",
"dict/jdic audio.txt",
"dict/deconjugator.json",
"reader.js",
"reader.html",
"mining.js",
"mining.html",
"livemining.js",
"livemining.html",
"jmdictabbreviations.html"
],
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*", "ftp://*/*", "file:///*"],
"js": ["include/browser-polyfill.min.js", "texthook.js"],
"all_frames": true
}
],
"options_ui": {
"page": "options.html"
},
"browser_action": {
"browser_style": false,
"default_icon": {
"16": "img/action16.png",
"32": "img/action32.png",
"512": "img/action512.png"
},
"default_title": "Nazeka (disabled)",
"default_area": "navbar"
},
"icons": {
"16": "img/enabled16.png",
"32": "img/enabled32.png",
"512": "img/enabled512.png"
}
}
File renamed without changes.
+13 -43
View File
@@ -3,14 +3,9 @@
/* /*
* TODO: * TODO:
* *
* ! Finish porting the underlay's deconjugation rules
* - Add an option for "hide unfitting senses/spellings/readings" vs "show everything but with details about what can be what"
* - Fix katakana-hiragana matching (only happens in lookups right now, not display generation) * - Fix katakana-hiragana matching (only happens in lookups right now, not display generation)
* - More configurability
* - VNstats frequency data * - VNstats frequency data
* - Integrate frequency into priority handling * - Integrate frequency into priority handling
* - Load deconjugation rules from an advanced setting, with a reset button
* ? Export/import settings with json
* *
*/ */
@@ -686,8 +681,11 @@ function build_div_inner(text, result, moreText, index, first_of_many = false)
// deconjugations // deconjugations
if(term.deconj) if(term.deconj)
{ {
console.log(term.deconj);
let deconj = ""; let deconj = "";
let first = true; let first = true;
for(let form of term.deconj) for(let form of term.deconj)
@@ -702,7 +700,7 @@ function build_div_inner(text, result, moreText, index, first_of_many = false)
if(info.startsWith("(") && info.endsWith(")") && f != 0) if(info.startsWith("(") && info.endsWith(")") && f != 0)
continue; continue;
if(added > 0) if(added > 0)
formtext += "―"; formtext += "→";
added++; added++;
formtext += info; formtext += info;
} }
@@ -735,6 +733,7 @@ function build_div_inner(text, result, moreText, index, first_of_many = false)
temptag.appendChild(main_reb); temptag.appendChild(main_reb);
if(term.deconj) if(term.deconj)
{ {
console.log(term.deconj);
let deconj = ""; let deconj = "";
let first = true; let first = true;
for(let form of term.deconj) for(let form of term.deconj)
@@ -749,7 +748,7 @@ function build_div_inner(text, result, moreText, index, first_of_many = false)
if(info.startsWith("(") && info.endsWith(")") && f != 0) if(info.startsWith("(") && info.endsWith(")") && f != 0)
continue; continue;
if(added > 0) if(added > 0)
formtext += "―"; formtext += "→";
added++; added++;
formtext += info; formtext += info;
} }
@@ -1075,11 +1074,9 @@ browser.storage.onChanged.addListener((updates, storageArea) =>
let last_lookup = undefined; let last_lookup = undefined;
let last_manual_interaction = Date.now(); let last_manual_interaction = Date.now();
let lookup_last_time = Date.now();
async function send_lookup(lookup) async function send_lookup(lookup)
{ {
lookup_last_time = Date.now();
last_lookup = lookup; last_lookup = lookup;
let response = await browser.runtime.sendMessage( let response = await browser.runtime.sendMessage(
@@ -1113,12 +1110,9 @@ async function send_lookup(lookup)
lookup_cancel(); lookup_cancel();
} }
function lookup_enqueue(text, x, y, x2, y2, moreText, index) function lookup_enqueue(text, x, y, x2, y2, moreText, index)
{
if(lookup_last_time+settings.lookuprate < Date.now())
{ {
send_lookup([text, x, y, x2, y2, moreText, index]); send_lookup([text, x, y, x2, y2, moreText, index]);
} }
}
function lookup_cancel() function lookup_cancel()
{ {
@@ -1359,8 +1353,8 @@ function update(event)
if((settings.popup_requires_key == 2 && !shift_down) if((settings.popup_requires_key == 2 && !shift_down)
|| (settings.popup_requires_key == 1 && !ctrl_down)) || (settings.popup_requires_key == 1 && !ctrl_down))
{ {
function sqr(n) {return n*n;} function sq(n) {return n*n;}
if(Math.sqrt(sqr(last_display_x-event.pageX) + sqr(last_display_y-event.pageY)) > 20) if(Math.sqrt(sq(last_display_x-event.pageX) + sq(last_display_y-event.pageY)) > 20)
lookup_cancel(); lookup_cancel();
return; return;
} }
@@ -1420,10 +1414,9 @@ function update(event)
yoffset = searchoffset; yoffset = searchoffset;
else else
xoffset = searchoffset; xoffset = searchoffset;
// firefox
if (document.caretPositionFromPoint)
{
let caretdata = document.caretPositionFromPoint(x+xoffset, y+yoffset); let caretdata = document.caretPositionFromPoint(x+xoffset, y+yoffset);
if(caretdata) if(caretdata)
{ {
textNode = caretdata.offsetNode; textNode = caretdata.offsetNode;
@@ -1434,30 +1427,6 @@ function update(event)
hitrect = range.getBoundingClientRect(); hitrect = range.getBoundingClientRect();
range.detach(); range.detach();
} }
}
// chrome
else if (document.caretRangeFromPoint)
{
let range = document.caretRangeFromPoint(x+xoffset, y+yoffset);
if(range)
{
try
{
range.setEnd(range.endContainer, range.endOffset+1);
}
catch(err)
{
try
{
range.setEnd(true_next_sibling(range.endContainer), 0);
}
catch(err){}
}
textNode = range.startContainer;
offset = range.startOffset;
hitrect = range.getBoundingClientRect();
}
}
// sticky mode and android need to break out on parent detection // sticky mode and android need to break out on parent detection
if(ele && !ele.contains(textNode) && platform != "android" && (!settings.sticky || get_doc().body.getElementsByClassName("nazeka_mining_ui").length != 0)) if(ele && !ele.contains(textNode) && platform != "android" && (!settings.sticky || get_doc().body.getElementsByClassName("nazeka_mining_ui").length != 0))
{ {
@@ -1487,7 +1456,7 @@ function update(event)
return; return;
} }
if(textNode !== undefined) if(false && textNode !== undefined)
{ {
// we hit an node, see if it's a transparent element and try to move it under everything temporarily if it is // we hit an node, see if it's a transparent element and try to move it under everything temporarily if it is
try try
@@ -1496,7 +1465,8 @@ function update(event)
{ {
let style = getComputedStyle(textNode) let style = getComputedStyle(textNode)
let bg_color = style.getPropertyValue("background-color"); let bg_color = style.getPropertyValue("background-color");
if(bg_color == "rgba(0, 0, 0, 0)") let position = style.getPropertyValue("position");
if(bg_color == "rgba(0, 0, 0, 0)" && (position == "absolute" || (position != "static" && textNode.tagName == "A")))
{ {
nodeIsBad = true; nodeIsBad = true;
nodeResetList.unshift([textNode, style.getPropertyValue("z-index")]); nodeResetList.unshift([textNode, style.getPropertyValue("z-index")]);