diff options
| author | hallgren <hallgren@chalmers.se> | 2013-04-12 12:47:13 +0000 |
|---|---|---|
| committer | hallgren <hallgren@chalmers.se> | 2013-04-12 12:47:13 +0000 |
| commit | 40e9fe30c32401dc9e00442970b263baa4306417 (patch) | |
| tree | a634c77106f171426f875ab8d6bdd387ad643f19 /src/www/js | |
| parent | 59f9f9dd1742e5b50a0f6893fb88325d4e3bc1ea (diff) | |
gfrobust.js: adding a JavaScript API to the GF Robust Parser translation service
Factored out from the Simple Translation Tool.
Diffstat (limited to 'src/www/js')
| -rw-r--r-- | src/www/js/gfrobust.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/src/www/js/gfrobust.js b/src/www/js/gfrobust.js new file mode 100644 index 000000000..327c77a98 --- /dev/null +++ b/src/www/js/gfrobust.js @@ -0,0 +1,35 @@ + +/* --- GF robust parser interface ------------------------------------------- */ + +var gfrobust = {} + +gfrobust.url="http://www.grammaticalframework.org:41296/robust-parser.cgi" +gfrobust.grammar="Parse" // the name of the grammar +gfrobust.targetlist=[] // do not use, exposed only for debugging + +gfrobust.call=function(querystring,cont) { + http_get_json(gfrobust.url+querystring,cont) +} + +// Translate a sentence to the given target language +gfrobust.translate=function(source,to,cont) { + var enc=encodeURIComponent + gfrobust.call("?sentence="+enc(source)+"&to="+gfrobust.grammar+to,cont) +} + +// Get functions to test which source and target langauges are supports +gfrobust.get_support=function(cont) { + function ssupport(code) { return code=="Eng" } + function tsupport(code) { return gfrobust.targets[code] } + function init2(langstr) { + var ls=langstr.split(" "); // ls probably contains an empty string here + var langs=[], pre=gfrobust.grammar, n=pre.length + for(var i=0;i<ls.length;i++) + if(ls[i].substr(0,n)==pre) langs.push(ls[i].substr(n)) + gfrobust.targetlist=langs + gfrobust.targets=toSet(langs) + cont(ssupport,tsupport) + } + if(gfrobust.target) cont(ssupport,tsupport) + else gfrobust.call("",init2) // retrieve list of supported target languages +} |
