mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-09 04:59:31 -06:00
Wide Coverage Translation Demo: use App14.pgf, remove spaces from Chi, Jpn and Tha output
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
|
||||
var gftranslate = {}
|
||||
|
||||
gftranslate.jsonurl="/robust/App13.pgf"
|
||||
gftranslate.jsonurl="/robust/App14.pgf"
|
||||
gftranslate.grammar="App" // the name of the grammar
|
||||
|
||||
gftranslate.call=function(querystring,cont,errcont) {
|
||||
@@ -16,14 +16,32 @@ function enc_langs(g,to) {
|
||||
: g+to
|
||||
}
|
||||
|
||||
function unspace_translations(g,trans) {
|
||||
var langs=[g+"Chi",g+"Jpn",g+"Tha"]
|
||||
for(var i=0;i<trans.length;i++) {
|
||||
var lins=trans[i].linearizations
|
||||
for(var j=0;j<lins.length;j++) {
|
||||
var lin=lins[j]
|
||||
if(elem(lin.to,langs)) {
|
||||
console.log(i,j,"space",lin.to,lin.text)
|
||||
lin.text=lin.text.split(" ").join("")
|
||||
console.log(i,j,"unspace",lin.to,lin.text)
|
||||
}
|
||||
}
|
||||
}
|
||||
return trans
|
||||
}
|
||||
|
||||
// Translate a sentence
|
||||
gftranslate.translate=function(source,from,to,start,limit,cont) {
|
||||
var g=gftranslate.grammar
|
||||
var lexer="&lexer=text"
|
||||
if(from=="Chi" || from=="Jpn") lexer="",source=source.split("").join(" ")
|
||||
if(from=="Chi") lexer="",source=source.split("").join(" ")
|
||||
var encsrc=encodeURIComponent(source)
|
||||
function errcont(text,code) { cont([{error:code+" "+text}]) }
|
||||
function extract(result) { cont(result[0].translations) }
|
||||
function extract(result) {
|
||||
cont(unspace_translations(g,result[0].translations))
|
||||
}
|
||||
if(encsrc.length<500)
|
||||
gftranslate.call("?command=c-translate&input="+encsrc
|
||||
+lexer+"&unlexer=text&from="+g+from+"&to="+enc_langs(g,to)
|
||||
@@ -38,7 +56,9 @@ gftranslate.wordforword=function(source,from,to,cont) {
|
||||
if(from=="Chi") lexer="",source=source.split("").join(" ")
|
||||
var encsrc=encodeURIComponent(source)
|
||||
function errcont(text,code) { cont([{error:code+" "+text}]) }
|
||||
function extract(result) { cont(result[0].translations) }
|
||||
function extract(result) {
|
||||
cont(unspace_translations(g,result[0].translations))
|
||||
}
|
||||
var enc_to = enc_langs(g,to)
|
||||
if(encsrc.length<500)
|
||||
gftranslate.call("?command=c-wordforword&input="+encsrc
|
||||
|
||||
Reference in New Issue
Block a user