Simple Translator: remove punctuation before wide coverage translation

This gives better translations with Translate11.pgf and is how the Wide
Coverage Demo App works.
This commit is contained in:
hallgren
2014-04-24 11:28:15 +00:00
parent 0b801b71d2
commit 54a77ee7d9

View File

@@ -216,7 +216,7 @@ Translator.prototype.update_translation=function(i) {
function upd2(trans,punct) { function upd2(trans,punct) {
if(trans.length==0) upd3s("[no translation]") if(trans.length==0) upd3s("[no translation]")
else if(trans[0].error) else if(trans[0].error!=undefined)
upd3s("[GF robust translation problem: "+trans[0].error+"]") upd3s("[GF robust translation problem: "+trans[0].error+"]")
else { else {
var ts=[] var ts=[]
@@ -247,7 +247,8 @@ Translator.prototype.update_translation=function(i) {
if(!eq_options(segment.options,want)) { if(!eq_options(segment.options,want)) {
//console.log("Updating "+i) //console.log("Updating "+i)
//lexgfrobust(segment.source,upd0) //lexgfrobust(segment.source,upd0)
upd0(segment.source,"") var sp=rmpunct(segment.source)
upd0(sp.txt,sp.punct)
} }
//else console.log("No update ",want,segment.options) //else console.log("No update ",want,segment.options)
} }
@@ -1223,6 +1224,26 @@ function lexgfrobust(txt,cont) {
lextext(txt,rmpunct) lextext(txt,rmpunct)
} }
*/ */
function rmpunct(txt) {
function ispunct(c) {
switch(c) {
case ' ':
case '\t':
case '\n':
case '.':
case '?':
case '!':
return true
default:
return false
}
}
var i=txt.length-1
while(i>=0 && ispunct(txt[i])) i--
i++
return {txt:txt.substr(0,i),punct:txt.substr(i)}
}
/* --- DOM Support ---------------------------------------------------------- */ /* --- DOM Support ---------------------------------------------------------- */
function a(url,linked) { return node("a",{href:url},linked); } function a(url,linked) { return node("a",{href:url},linked); }