simple translator: Replaced 'GF Robust Parser' with 'GF Wide Coverage Translation'

The interface to the wide coverage translation is in js/gftranslate.js
and it assumes that the grammar is installed on the cloud server
as /robust/Translate8.pgf.

The list of supported languages is hardwired in gftranslate.js, since
there is no support for obtaining this info from the C run-time system
at the moment.
This commit is contained in:
hallgren
2014-01-21 16:47:23 +00:00
parent 9d71ffc831
commit 14ce8509f8
3 changed files with 46 additions and 10 deletions

34
src/www/js/gftranslate.js Normal file
View File

@@ -0,0 +1,34 @@
/* --- GF wide coverage translation interface ------------------------------- */
var gftranslate = {}
gftranslate.jsonurl="/robust/Translate8.pgf"
gftranslate.grammar="Translate" // the name of the grammar
gftranslate.languages="Bul Chi Eng Fin Fre Ger Hin Swe".split(" ")
// hardwired for now
gftranslate.call=function(querystring,cont) {
http_get_json(gftranslate.jsonurl+querystring,cont)
}
// Translate a sentence to the given target language
gftranslate.translate=function(source,from,to,cont) {
var encsrc=encodeURIComponent(source)
var g=gftranslate.grammar
function extract(result) {
cont(result[0].translations[0].linearizations[0].text)
}
if(encsrc.length<200) // match limit in runtime/c/utils/pgf-server.c
gftranslate.call("?command=c-translate&input="+encsrc
+"&from="+g+from+"&to="+g+to+"&limit=1",extract)
else cont("[GF robust parser: sentence too long]")
}
// Get functions to test which source and target langauges are supported
gftranslate.get_support=function(cont) {
if(!gftranslate.targets) gftranslate.targets=toSet(gftranslate.languages)
function ssupport(code) { return gftranslate.targets[code] }
function tsupport(code) { return gftranslate.targets[code] }
cont(ssupport,tsupport)
}