diff options
| author | hallgren <hallgren@chalmers.se> | 2014-01-21 16:47:23 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2014-01-21 16:47:23 +0000 |
| commit | 14ce8509f8058f3d278b4b90193723ee68843149 (patch) | |
| tree | d80bb414cee66f75eb49b2f2ea1baa468f06c64f /src/www/js | |
| parent | 9d71ffc831164c7cba260d1bb3f0a968cca8c3e7 (diff) | |
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.
Diffstat (limited to 'src/www/js')
| -rw-r--r-- | src/www/js/gftranslate.js | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/www/js/gftranslate.js b/src/www/js/gftranslate.js new file mode 100644 index 000000000..0043fce61 --- /dev/null +++ b/src/www/js/gftranslate.js @@ -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) +} |
