initial adaptation to the new runtime

This commit is contained in:
Krasimir Angelov
2022-08-19 17:26:59 +02:00
parent 743c473526
commit bcd9184ede
4 changed files with 6 additions and 64 deletions
+4 -23
View File
@@ -3,8 +3,8 @@
var gftranslate = {}
gftranslate.jsonurl="/robust/App16.pgf"
gftranslate.grammar="App" // the name of the grammar
gftranslate.jsonurl="/robust/Parse.ngf"
gftranslate.grammar="Parse" // the name of the grammar
gftranslate.documented_classes=
["N", "N2", "N3", "A", "A2", "V", "V2", "VV", "VS", "VQ", "VA", "V3", "V2V",
@@ -67,31 +67,12 @@ gftranslate.translate=function(source,from,to,start,limit,cont) {
var too_long=check_limit(from,source)
if(too_long) cont([{error:too_long}])
else
gftranslate.call("?command=c-translate&jsontree=true&input="
gftranslate.call("?command=translate&jsontree=true&input="
+encodeURIComponent(source)
+lexer+"&unlexer=text&from="+g+from+"&to="+enc_langs(g,to)
+"&start="+start+"&limit="+limit,extract,errcont)
}
// Translate a sentence word for word (if all else fails...)
gftranslate.wordforword=function(source,from,to,cont) {
var g=gftranslate.grammar
var lexer="&lexer=text"
if(from=="Chi") lexer="",source=source.split("").join(" ")
function errcont(text,code) { cont([{error:code+" "+text}]) }
function extract(result) {
cont(unspace_translations(g,result[0].translations))
}
var enc_to = enc_langs(g,to)
var too_long=check_limit(from,source)
if(too_long) cont([{error:too_long}])
else
gftranslate.call("?command=c-wordforword&input="
+encodeURIComponent(source)
+lexer+"&unlexer=text&from="+g+from+"&to="+enc_to
,extract,errcont)
}
// Get list of supported languages
gftranslate.waiting=[]
gftranslate.get_languages=function(cont,errcont) {
@@ -118,7 +99,7 @@ gftranslate.get_languages=function(cont,errcont) {
else {
gftranslate.waiting.push({cont:cont,errcont:errcont})
if(gftranslate.waiting.length<2)
gftranslate.call("?command=c-grammar",init2,init2error)
gftranslate.call("?command=grammar",init2,init2error)
}
}
+1 -17
View File
@@ -214,29 +214,13 @@ wc.translate=function(redo) {
//disable(false)
}
function word_for_word(text,cont) {
function step3(tra) {
if(tra.length>=1) {
var r=tra[0]
r.prob = -1
if(r.linearizations) showit(r,gftranslate.grammar)
else if(r.error!=undefined)
show_error(r.error)
}
else if(so.rs.length==0)
show_error("Unable to translate")
}
gftranslate.wordforword(text,f.from.value,wc.languages || f.to.value,step3)
}
function trans(text,i,count) {
function step3(tra) {
if(tra.length>=1) {
var r=tra[0]
if(r.error!=undefined) {
if(i==0 && so.rs.length==0) {
//show_error(r.error)
word_for_word(text)
show_error(r.error)
}
}
else {