add halfwidth to fullwidth number conversion
This commit is contained in:
1 parent
437f93451e
commit
cdfb70bb0e
2 files changed
+101
-2
No files matched your search
+72
-1
@@ -509,12 +509,83 @@ function contextrule_deconjugate(my_form, my_rule)
|
|||||||
return stdrule_deconjugate(my_form, my_rule);
|
return stdrule_deconjugate(my_form, my_rule);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function substitution_inner(my_form, my_rule)
|
||||||
|
{
|
||||||
|
if(!my_form.text.includes(my_rule.con_end))
|
||||||
|
return;
|
||||||
|
let newtext = my_form.text.replace(new RegExp(my_rule.con_end, 'g'), my_rule.dec_end);
|
||||||
|
|
||||||
|
// I hate javascript reeeeeeeeeeeeeee
|
||||||
|
let newform = {};//new Object();
|
||||||
|
newform.text = newtext;
|
||||||
|
newform.original_text = my_form.original_text;
|
||||||
|
newform.tags = my_form.tags.slice();
|
||||||
|
newform.seentext = new Set([...my_form.seentext]);
|
||||||
|
newform.process = my_form.process.slice();
|
||||||
|
|
||||||
|
newform.text = newtext;
|
||||||
|
|
||||||
|
newform.process.push(my_rule.detail);
|
||||||
|
|
||||||
|
if(newform.seentext.size == 0)
|
||||||
|
newform.seentext.add(my_form.text);
|
||||||
|
newform.seentext.add(newtext);
|
||||||
|
|
||||||
|
return newform;
|
||||||
|
};
|
||||||
|
function substitution_deconjugate(my_form, my_rule)
|
||||||
|
{
|
||||||
|
if(my_form.process.length != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// can't deconjugate nothingness
|
||||||
|
if(my_form.text == "")
|
||||||
|
return;
|
||||||
|
|
||||||
|
let array = undefined;
|
||||||
|
// pick the first one that is an array
|
||||||
|
// FIXME: use minimum length for safety reasons? assert all arrays equal length?
|
||||||
|
if(Array.isArray(my_rule.dec_end))
|
||||||
|
array = my_rule.dec_end;
|
||||||
|
else if(Array.isArray(my_rule.con_end))
|
||||||
|
array = my_rule.con_end;
|
||||||
|
|
||||||
|
if(array == undefined)
|
||||||
|
return substitution_inner(my_form, my_rule);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
let collection = new Set();
|
||||||
|
for(let i = 0; i < array.length; i++)
|
||||||
|
{
|
||||||
|
let virtual_rule = {};
|
||||||
|
virtual_rule.type = my_rule.type;
|
||||||
|
|
||||||
|
let index_or_value = function (variable, index)
|
||||||
|
{
|
||||||
|
if(Array.isArray(variable))
|
||||||
|
return variable[index];
|
||||||
|
else
|
||||||
|
return variable;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual_rule.dec_end = index_or_value(my_rule.dec_end, i);
|
||||||
|
virtual_rule.con_end = index_or_value(my_rule.con_end, i);
|
||||||
|
virtual_rule.detail = my_rule.detail;
|
||||||
|
|
||||||
|
let ret = substitution_inner(my_form, virtual_rule);
|
||||||
|
if(ret) collection.add(ret);
|
||||||
|
}
|
||||||
|
return collection;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let rule_functions = {
|
let rule_functions = {
|
||||||
stdrule: stdrule_deconjugate,
|
stdrule: stdrule_deconjugate,
|
||||||
rewriterule: rewriterule_deconjugate,
|
rewriterule: rewriterule_deconjugate,
|
||||||
onlyfinalrule: onlyfinalrule_deconjugate,
|
onlyfinalrule: onlyfinalrule_deconjugate,
|
||||||
neverfinalrule: neverfinalrule_deconjugate,
|
neverfinalrule: neverfinalrule_deconjugate,
|
||||||
contextrule: contextrule_deconjugate,
|
contextrule: contextrule_deconjugate,
|
||||||
|
substitution: substitution_deconjugate
|
||||||
};
|
};
|
||||||
|
|
||||||
function v1inftrap_check(my_form, my_rule)
|
function v1inftrap_check(my_form, my_rule)
|
||||||
@@ -565,7 +636,7 @@ function deconjugate(mytext)
|
|||||||
{
|
{
|
||||||
if(settings.deconjugator_rules_json != "")
|
if(settings.deconjugator_rules_json != "")
|
||||||
myrules = JSON.parse(settings.deconjugator_rules_json);
|
myrules = JSON.parse(settings.deconjugator_rules_json);
|
||||||
} catch(err) {}
|
} catch(err) { console.log(err); }
|
||||||
|
|
||||||
while(novel.size > 0)
|
while(novel.size > 0)
|
||||||
{
|
{
|
||||||
|
|||||||
+29
-1
@@ -1058,5 +1058,33 @@
|
|||||||
"con_tag": "uninflectable",
|
"con_tag": "uninflectable",
|
||||||
"detail": "slurred"
|
"detail": "slurred"
|
||||||
},
|
},
|
||||||
"// TODO: support for other verb types like vk (くる) (started, incomplete), 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), ...",
|
||||||
|
{
|
||||||
|
"type": "substitution",
|
||||||
|
"dec_end": [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9"
|
||||||
|
],
|
||||||
|
"con_end": [
|
||||||
|
"0",
|
||||||
|
"1",
|
||||||
|
"2",
|
||||||
|
"3",
|
||||||
|
"4",
|
||||||
|
"5",
|
||||||
|
"6",
|
||||||
|
"7",
|
||||||
|
"8",
|
||||||
|
"9"
|
||||||
|
],
|
||||||
|
"detail": ""
|
||||||
|
}
|
||||||
]
|
]
|
||||||
Reference in new issue
Block a user