mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-25 10:48:54 -06:00
Simple Translator: initial support for translation with the GF robust parser
This commit is contained in:
@@ -31,6 +31,8 @@ The tool supports two machine translation services:
|
|||||||
<li>The <a href="http://www.grammaticalframework.org/">GF</a> web service.
|
<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.
|
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 <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>
|
</ul>
|
||||||
|
|
||||||
<p>If an unsatisfactory automatic translation is
|
<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>
|
<hr>
|
||||||
<div class=modtime><small>
|
<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>
|
</small></div>
|
||||||
<address>
|
<address>
|
||||||
<a href="http://www.cse.chalmers.se/~hallgren/">TH</a>
|
<a href="http://www.cse.chalmers.se/~hallgren/">TH</a>
|
||||||
|
|||||||
@@ -60,6 +60,7 @@
|
|||||||
<tr><td><span onclick="">Default translation method</span>
|
<tr><td><span onclick="">Default translation method</span>
|
||||||
<dl id=methods>
|
<dl id=methods>
|
||||||
<dt><label><input name=method value=Manual type=radio onchange="translator.change(this)">Manual</label>
|
<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>
|
</dl>
|
||||||
</table>
|
</table>
|
||||||
<dt><label><input name=cloud type=checkbox onchange="translator.change(this)"> Save in the cloud</label>
|
<dt><label><input name=cloud type=checkbox onchange="translator.change(this)"> Save in the cloud</label>
|
||||||
@@ -76,7 +77,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<hr>
|
<hr>
|
||||||
<div class=modtime><small>HMTL
|
<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>
|
</small></div>
|
||||||
<a href="about.html">About</a>
|
<a href="about.html">About</a>
|
||||||
|
|
||||||
|
|||||||
@@ -117,6 +117,9 @@ Translator.prototype.update_language_menus=function() {
|
|||||||
case "Manual":
|
case "Manual":
|
||||||
mark_menus(yes,yes)
|
mark_menus(yes,yes)
|
||||||
break;
|
break;
|
||||||
|
case "GFRobust":
|
||||||
|
mark_menus(gfrobust_ssupport,gfrobust_tsupport)
|
||||||
|
break;
|
||||||
case "Apertium":
|
case "Apertium":
|
||||||
function ssupport(code) {
|
function ssupport(code) {
|
||||||
return apertium.isTranslatable(alangcode(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) {
|
Translator.prototype.gf_supported=function(grammar,langcode) {
|
||||||
var t=this;
|
var t=this;
|
||||||
var concname=t.grammar_info[grammar].name+langcode
|
var concname=t.grammar_info[grammar].name+langcode
|
||||||
@@ -198,6 +205,42 @@ Translator.prototype.update_translation=function(i) {
|
|||||||
else
|
else
|
||||||
upd3(["[Apertium does not support "+show_translation(o)+"]"])
|
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) {
|
function update_gf_translation(grammar,gfrom,gto) {
|
||||||
var server=t.servers[grammar]
|
var server=t.servers[grammar]
|
||||||
@@ -243,6 +286,7 @@ Translator.prototype.update_translation=function(i) {
|
|||||||
switch(m) {
|
switch(m) {
|
||||||
case "Manual": /* Nothing to do */ break;
|
case "Manual": /* Nothing to do */ break;
|
||||||
case "Apertium": update_apertium_translation(); break;
|
case "Apertium": update_apertium_translation(); break;
|
||||||
|
case "GFRobust": update_gfrobust_translation(); break;
|
||||||
default: // GF
|
default: // GF
|
||||||
function upd00(grammar_info) {
|
function upd00(grammar_info) {
|
||||||
var gname=grammar_info.name
|
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 DocOptions = Options & { view:View, cloud:Bool }
|
||||||
type Options = {from: Lang, to: Lang, method:Method}
|
type Options = {from: Lang, to: Lang, method:Method}
|
||||||
type Lang = String // Eng, Swe, Ita, etc
|
type Lang = String // Eng, Swe, Ita, etc
|
||||||
type Method = "Manual" | "Apertium" | GFGrammarName
|
type Method = "Manual" | "Apertium" | "GFRobust" | GFGrammarName
|
||||||
type View = "segmentbysegment" | "paralleltexts"
|
type View = "segmentbysegment" | "paralleltexts"
|
||||||
type GFGrammarName = String // e.g. "Foods.pgf"
|
type GFGrammarName = String // e.g. "Foods.pgf"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user