forked from GitHub/gf-core
Wide Coverage Translation Demo: add a way to obtain inflection tables
Too see inflection tables, click on a translated sentense, then click on a blue function name in the textual representation of the abstract syntax tree.
This commit is contained in:
@@ -6,6 +6,10 @@ var gftranslate = {}
|
||||
gftranslate.jsonurl="/robust/App14.pgf"
|
||||
gftranslate.grammar="App" // the name of the grammar
|
||||
|
||||
gftranslate.documented_classes=
|
||||
["N", "N2", "N3", "A", "A2", "V", "V2", "VV", "VS", "VQ", "VA", "V3", "V2V",
|
||||
"V2S", "V2Q", "V2A", "Adv", "Prep"]
|
||||
|
||||
gftranslate.call=function(querystring,cont,errcont) {
|
||||
http_get_json(gftranslate.jsonurl+querystring,cont,errcont)
|
||||
}
|
||||
|
||||
@@ -106,6 +106,27 @@ wc.translate=function() {
|
||||
[text("Google Translate")])))
|
||||
*/
|
||||
}
|
||||
function treetext(tree) {
|
||||
function inflect(w,wcls) {
|
||||
function show_inflections(lins) {
|
||||
if(wc.e2) wc.e2.innerHTML=lins[0].text
|
||||
}
|
||||
function get_inflections() {
|
||||
var tree="MkDocument+%22%22+(Inflection"+wcls+" "+w+") %22%22"
|
||||
var l=gftranslate.grammar+f.to.value
|
||||
gftranslate.call("?command=c-linearize&to="+l+"&tree="+tree,show_inflections)
|
||||
}
|
||||
var wn=wrap_class("span","inflect",text(w))
|
||||
if(wc.e2) wn.onclick=get_inflections
|
||||
return wn
|
||||
}
|
||||
function word(w) {
|
||||
var ps=w.split("_")
|
||||
return ps.length==2 && elem(ps[1],gftranslate.documented_classes)
|
||||
? inflect(w,ps[1]) : text(w)
|
||||
}
|
||||
return tree.split(/([ ()]+)/).map(word)
|
||||
}
|
||||
function show_more() {
|
||||
wc.selected=so
|
||||
var r=so.rs[so.current_pick]
|
||||
@@ -113,7 +134,8 @@ wc.translate=function() {
|
||||
if(e) {
|
||||
e.innerHTML=prob+"<br>"
|
||||
if(r.tree) {
|
||||
var t=wrap("span",text(r.tree))
|
||||
wc.e2=empty_class("div","e2")
|
||||
var t=wrap("span",treetext(r.tree))
|
||||
e.appendChild(t)
|
||||
var g=gftranslate.jsonurl
|
||||
var u="format=svg&tree="+encodeURIComponent(r.tree)
|
||||
@@ -130,8 +152,8 @@ wc.translate=function() {
|
||||
}
|
||||
else if(r.img.src!=r.imgurls[r.img_ix]) // language change?
|
||||
r.img.src=r.imgurls[r.img_ix]
|
||||
e.appendChild(empty("br"))
|
||||
e.appendChild(r.img)
|
||||
wc.e2.appendChild(r.img)
|
||||
e.appendChild(wc.e2)
|
||||
}
|
||||
}
|
||||
if(wc.p /*&& so.rs.length>1*/) show_picks()
|
||||
|
||||
@@ -24,6 +24,8 @@ small { color: #666; }
|
||||
.colors .bad_quality { background-color: #f89; }
|
||||
.placeholder { color: #999; }
|
||||
.error { color: #c00; }
|
||||
div.e2 { background: white; }
|
||||
span.inflect { color: blue; }
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -89,7 +91,7 @@ small { color: #666; }
|
||||
</div>
|
||||
<hr>
|
||||
<div class=modtime><small>
|
||||
<!-- hhmts start -->Last modified: Fri Jun 20 20:21:52 CEST 2014 <!-- hhmts end -->
|
||||
<!-- hhmts start -->Last modified: Sun Mar 22 23:30:45 CET 2015 <!-- hhmts end -->
|
||||
</small></div>
|
||||
<a href="http://www.grammaticalframework.org/demos/translation.html">About</a>
|
||||
<script src="js/support.js"></script>
|
||||
|
||||
Reference in New Issue
Block a user