1
0
forked from GitHub/gf-core

Simple Translator: initial support for translation with the GF robust parser

This commit is contained in:
hallgren
2013-04-05 13:25:09 +00:00
parent b6bbe96503
commit e6286fd376
3 changed files with 50 additions and 3 deletions

View File

@@ -31,6 +31,8 @@ The tool supports two machine translation services:
<li>The <a href="http://www.grammaticalframework.org/">GF</a> web service.
The user picks which GF grammar to use from a menu of available grammars.
<li>The <a href="http://www.apertium.org/">Apertium</a> web service.
<li>The GF Robust Parser. This is an exprimental service that supports
translation from English to a few other languages.
</ul>
<p>If an unsatisfactory automatic translation is
@@ -65,7 +67,7 @@ closed and reopened later. Documents can be saved locally or in the cloud.
<hr>
<div class=modtime><small>
<!-- hhmts start -->Last modified: Wed Oct 3 16:26:13 CEST 2012 <!-- hhmts end -->
<!-- hhmts start -->Last modified: Fri Apr 5 15:24:59 CEST 2013 <!-- hhmts end -->
</small></div>
<address>
<a href="http://www.cse.chalmers.se/~hallgren/">TH</a>

View File

@@ -60,6 +60,7 @@
<tr><td><span onclick="">Default translation method</span>
<dl id=methods>
<dt><label><input name=method value=Manual type=radio onchange="translator.change(this)">Manual</label>
<dt><label><input name=method value=GFRobust type=radio onchange="translator.change(this)">GF Robust Parser</label>
</dl>
</table>
<dt><label><input name=cloud type=checkbox onchange="translator.change(this)"> Save in the cloud</label>
@@ -76,7 +77,7 @@
</div>
<hr>
<div class=modtime><small>HMTL
<!-- hhmts start -->Last modified: Wed Apr 3 20:29:44 CEST 2013 <!-- hhmts end -->
<!-- hhmts start -->Last modified: Fri Apr 5 15:09:28 CEST 2013 <!-- hhmts end -->
</small></div>
<a href="about.html">About</a>

View File

@@ -117,6 +117,9 @@ Translator.prototype.update_language_menus=function() {
case "Manual":
mark_menus(yes,yes)
break;
case "GFRobust":
mark_menus(gfrobust_ssupport,gfrobust_tsupport)
break;
case "Apertium":
function ssupport(code) {
return apertium.isTranslatable(alangcode(code))
@@ -136,6 +139,10 @@ Translator.prototype.update_language_menus=function() {
}
}
function gfrobust_ssupport(code) { return code=="Eng" }
var gfrobust_targets=toSet(["Eng","Ger","Fin","Bul","Hin"]) // !!! Get list from server
function gfrobust_tsupport(code) { return gfrobust_targets[code] }
Translator.prototype.gf_supported=function(grammar,langcode) {
var t=this;
var concname=t.grammar_info[grammar].name+langcode
@@ -198,6 +205,42 @@ Translator.prototype.update_translation=function(i) {
else
upd3(["[Apertium does not support "+show_translation(o)+"]"])
}
function update_gfrobust_translation() {
function upd3(txts) { update_segment("GFRobust",txts) }
function upd2(ts) {
switch(ts.length) {
case 0: upd3(["[no translation]"]);break;
default: upd3([ts]); break;
}
}
function upd1(translate_output) {
//console.log(translate_output)
upd2(translate_output)
}
function upd0(source) {
var url="http://www.grammaticalframework.org:41296/robust-parser.cgi"
http_get_json(url+"?sentence="+encodeURIComponent(source)+"&to=Parse"+o.to,upd1)
}
var fls=gfrobust_ssupport(o.from)
var tls=gfrobust_tsupport(o.to)
if(fls && tls) {
var want={from:o.from, to:o.to, method:"GFRobust"}
if(!eq_options(segment.options,want)) {
//console.log("Updating "+i)
//lextext(segment.source,upd0)
upd0(segment.source)
}
//else console.log("No update ",want,segment.options)
}
else {
var fn=" from "+concname(o.from)
var tn=" to "+concname(o.to)
var msg="The GF robust translation service: not supported:"
if(!fls) msg+=fn+(tls ? "." : ", ")
if(!tls) msg+=tn+"."
upd3(["["+msg+"]"])
}
}
function update_gf_translation(grammar,gfrom,gto) {
var server=t.servers[grammar]
@@ -243,6 +286,7 @@ Translator.prototype.update_translation=function(i) {
switch(m) {
case "Manual": /* Nothing to do */ break;
case "Apertium": update_apertium_translation(); break;
case "GFRobust": update_gfrobust_translation(); break;
default: // GF
function upd00(grammar_info) {
var gname=grammar_info.name
@@ -808,7 +852,7 @@ type Segment = { source:String, target:String, options:Options }
type DocOptions = Options & { view:View, cloud:Bool }
type Options = {from: Lang, to: Lang, method:Method}
type Lang = String // Eng, Swe, Ita, etc
type Method = "Manual" | "Apertium" | GFGrammarName
type Method = "Manual" | "Apertium" | "GFRobust" | GFGrammarName
type View = "segmentbysegment" | "paralleltexts"
type GFGrammarName = String // e.g. "Foods.pgf"