diff options
| author | aarne <aarne@chalmers.se> | 2010-03-26 22:07:17 +0000 |
|---|---|---|
| committer | aarne <aarne@chalmers.se> | 2010-03-26 22:07:17 +0000 |
| commit | 691620346ccdae242ce8b203fc04d3ffeeea6247 (patch) | |
| tree | c480f98b2615bf16236d0a89e052f0dd0c59712a /examples | |
| parent | c24440d1346a01d660f83359d8ef72a2ef1b0c13 (diff) | |
change Food to Words in Phrasebook, since it's unpractical to have many small modules; added syntactic forms and words
Diffstat (limited to 'examples')
27 files changed, 554 insertions, 40 deletions
diff --git a/examples/phrasebook/DiffPhrasebook.gf b/examples/phrasebook/DiffPhrasebook.gf index 8be58bb7e..27076323b 100644 --- a/examples/phrasebook/DiffPhrasebook.gf +++ b/examples/phrasebook/DiffPhrasebook.gf @@ -3,6 +3,7 @@ interface DiffPhrasebook = open Syntax in { oper want_V2 : V2 ; like_V2 : V2 ; - + cost_V2 : V2 ; -- it costs five euros + cost_V : V ; -- how much does it cost } diff --git a/examples/phrasebook/DiffPhrasebookEng.gf b/examples/phrasebook/DiffPhrasebookEng.gf index 435ca1603..40c802459 100644 --- a/examples/phrasebook/DiffPhrasebookEng.gf +++ b/examples/phrasebook/DiffPhrasebookEng.gf @@ -1,10 +1,12 @@ instance DiffPhrasebookEng of DiffPhrasebook = open SyntaxEng, - ParadigmsEng + ParadigmsEng, + IrregEng in { oper want_V2 = mkV2 (mkV "want") ; like_V2 = mkV2 (mkV "like") ; - + cost_V2 = mkV2 IrregEng.cost_V ; + cost_V = IrregEng.cost_V ; } diff --git a/examples/phrasebook/DiffPhrasebookFin.gf b/examples/phrasebook/DiffPhrasebookFin.gf index 3865c9091..c90820e06 100644 --- a/examples/phrasebook/DiffPhrasebookFin.gf +++ b/examples/phrasebook/DiffPhrasebookFin.gf @@ -9,4 +9,6 @@ oper want_V2 = mkV2 (mkV "haluta") ; like_V2 = mkV2 (mkV "pitää") elative ; + cost_V2 = mkV2 (mkV "maksaa") ; + cost_V = mkV "maksaa" ; } diff --git a/examples/phrasebook/DiffPhrasebookFre.gf b/examples/phrasebook/DiffPhrasebookFre.gf index 039258776..7a83a4f88 100644 --- a/examples/phrasebook/DiffPhrasebookFre.gf +++ b/examples/phrasebook/DiffPhrasebookFre.gf @@ -10,4 +10,7 @@ oper want_V2 = vouloir_V2 ; like_V2 = mkV2 (mkV "aimer") ; + cost_V2 = mkV2 (mkV "coûter") ; + cost_V = mkV "coûter" ; + } diff --git a/examples/phrasebook/DiffPhrasebookRon.gf b/examples/phrasebook/DiffPhrasebookRon.gf index 0b842bd81..060b8301d 100644 --- a/examples/phrasebook/DiffPhrasebookRon.gf +++ b/examples/phrasebook/DiffPhrasebookRon.gf @@ -10,4 +10,7 @@ oper want_V2 = dirV2 (lin V want_VV) ; -- mkVV (v_besch74 "vrea") like_V2 = dirV2 (v_besch71 "plăcea") ; + cost_V2 = dirV2 (mkV "costa") ; ---- ? + cost_V = mkV "costa" ; ---- ? + } diff --git a/examples/phrasebook/Greetings.gf b/examples/phrasebook/Greetings.gf index 11d0f9cc1..bdbc1b5bc 100644 --- a/examples/phrasebook/Greetings.gf +++ b/examples/phrasebook/Greetings.gf @@ -26,7 +26,6 @@ fun GImTired : Greeting ; GImScared : Greeting ; GIdontUnderstand : Greeting ; - GWheresTheBathroom : Greeting ; GTheCheck : Greeting ; GYes : Greeting ; diff --git a/examples/phrasebook/GreetingsEng.gf b/examples/phrasebook/GreetingsEng.gf index 5f3cc23e7..b89fdabab 100644 --- a/examples/phrasebook/GreetingsEng.gf +++ b/examples/phrasebook/GreetingsEng.gf @@ -26,7 +26,6 @@ lin GImTired = ss "I'm tired" ; GImScared = ss "I'm scared" ; GIdontUnderstand = ss "I don't understand" ; - GWheresTheBathroom = ss "where's the bathroom" ; GTheCheck = ss "the bill" ; GYes = ss "yes" ; diff --git a/examples/phrasebook/GreetingsFin.gf b/examples/phrasebook/GreetingsFin.gf index 2b7b5568f..220d1312b 100644 --- a/examples/phrasebook/GreetingsFin.gf +++ b/examples/phrasebook/GreetingsFin.gf @@ -28,7 +28,6 @@ lin GImTired = ss "minä olen väsynyt" ; GImScared = ss "minua pelottaa" ; GIdontUnderstand = ss "en ymmärrä" ; - GWheresTheBathroom = ss "missä on vessa" ; GTheCheck = ss "lasku" ; GYes = ss "kyllä" ; diff --git a/examples/phrasebook/GreetingsFre.gf b/examples/phrasebook/GreetingsFre.gf index 32f422f3c..bc5b8e9a5 100644 --- a/examples/phrasebook/GreetingsFre.gf +++ b/examples/phrasebook/GreetingsFre.gf @@ -29,7 +29,6 @@ lin GImTired = speakerDistinct "je suis fatigué" "je suis fatiguée" ; GImScared = roleNeutral "j'ai peur" ; GIdontUnderstand = roleNeutral "je ne comprends pas" ; - GWheresTheBathroom = roleNeutral "où est la toilette" ; GTheCheck = roleNeutral "l'addition" ; GYes = roleNeutral "oui" ; ---- si diff --git a/examples/phrasebook/GreetingsRon.gf b/examples/phrasebook/GreetingsRon.gf index acc0f5241..14aec6020 100644 --- a/examples/phrasebook/GreetingsRon.gf +++ b/examples/phrasebook/GreetingsRon.gf @@ -28,7 +28,6 @@ lin GImTired = ss "mi-e somn" ; GImScared = ss "mi-e frică" ; GIdontUnderstand = ss "nu înÅ£eleg" ; - GWheresTheBathroom = ss "unde e toaleta" ; GTheCheck = ss "nota de plată" ; GYes = ss "da" ; diff --git a/examples/phrasebook/Phrasebook.gf b/examples/phrasebook/Phrasebook.gf index f5f5a4663..001b250f5 100644 --- a/examples/phrasebook/Phrasebook.gf +++ b/examples/phrasebook/Phrasebook.gf @@ -1,6 +1,6 @@ abstract Phrasebook = Greetings, - Food + Words ** { flags startcat = Phrase ; @@ -11,6 +11,7 @@ cat fun PNumeral : Numeral -> Phrase ; PSentence : Sentence -> Phrase ; + PQuestion : Question -> Phrase ; PGreeting : Greeting -> Phrase ; ---- PGreeting : Politeness -> Gender -> Gender -> Greeting -> Phrase ; diff --git a/examples/phrasebook/PhrasebookEng.gf b/examples/phrasebook/PhrasebookEng.gf index 4d4b26781..5aa946bf0 100644 --- a/examples/phrasebook/PhrasebookEng.gf +++ b/examples/phrasebook/PhrasebookEng.gf @@ -2,19 +2,20 @@ concrete PhrasebookEng of Phrasebook = GreetingsEng, - FoodEng ** open + WordsEng ** open (R = Roles), SyntaxEng, ResEng, ---- for Num to Utt Prelude in { lincat - Phrase = Utt ; + Phrase = Text ; lin PNumeral n = mkPhrase ((SyntaxEng.mkCard <n : Numeral>).s ! Nom) ; ---- - PSentence s = s ; + PSentence s = mkText s ; + PQuestion s = mkText s ; PGreeting g = mkPhrase g.s ; ---- PGreeting p s h g = mkPhrase (g.s ++ p.s ++ s.s ++ h.s) ; diff --git a/examples/phrasebook/PhrasebookFin.gf b/examples/phrasebook/PhrasebookFin.gf index 340d1c075..2144d90fe 100644 --- a/examples/phrasebook/PhrasebookFin.gf +++ b/examples/phrasebook/PhrasebookFin.gf @@ -2,19 +2,20 @@ concrete PhrasebookFin of Phrasebook = GreetingsFin, - FoodFin ** open + WordsFin ** open SyntaxFin, ResFin, ---- for Num to Utt Prelude in { lincat - Phrase = Utt ; + Phrase = Text ; lin PNumeral n = mkPhrase (ss ((SyntaxFin.mkCard <n : Numeral>).s ! Sg ! Nom)) ; ---- PGreeting g = mkPhrase g ; - PSentence s = s ; + PSentence s = mkText s ; + PQuestion s = mkText s ; oper diff --git a/examples/phrasebook/PhrasebookFre.gf b/examples/phrasebook/PhrasebookFre.gf index 7cf812466..5df0c0c86 100644 --- a/examples/phrasebook/PhrasebookFre.gf +++ b/examples/phrasebook/PhrasebookFre.gf @@ -2,7 +2,7 @@ concrete PhrasebookFre of Phrasebook = GreetingsFre, - FoodFre + WordsFre ** open (R = Roles), SyntaxFre, @@ -11,13 +11,14 @@ concrete PhrasebookFre of Phrasebook = Prelude in { lincat - Phrase = Utt ; + Phrase = Text ; Gender = {s : Str ; g : R.Gender} ; Politeness = {s : Str ; p : R.Politeness} ; lin PNumeral n = mkPhrase ((mkCard <n : Numeral>).s ! masculine) ; ---- - PSentence s = s ; + PSentence s = mkText s ; + PQuestion s = mkText s ; PGreeting g = mkPhrase (g.s ! R.Polite ! R.Male ! R.Male) ; ---- PGreeting p s h g = mkPhrase (g.s ! p.p ! s.g ! h.g ++ p.s ++ s.s ++ h.s) ; diff --git a/examples/phrasebook/PhrasebookRon.gf b/examples/phrasebook/PhrasebookRon.gf index 5dd15b04b..40cdf1eda 100644 --- a/examples/phrasebook/PhrasebookRon.gf +++ b/examples/phrasebook/PhrasebookRon.gf @@ -2,19 +2,20 @@ concrete PhrasebookRon of Phrasebook = GreetingsRon, - FoodRon + WordsRon ** open SyntaxRon, ResRon, ---- for Num to Utt Prelude in { lincat - Phrase = Utt ; + Phrase = Text ; lin PNumeral n = mkPhrase (ss ((mkCard <n : Numeral>).sp ! Masc)) ; ---- PGreeting g = mkPhrase g ; - PSentence s = s ; + PSentence s = mkText s ; + PQuestion s = mkText s ; oper mkPhrase : SS -> Utt = \s -> lin Utt s ; diff --git a/examples/phrasebook/Sentences.gf b/examples/phrasebook/Sentences.gf index 7afd69435..d1f79498b 100644 --- a/examples/phrasebook/Sentences.gf +++ b/examples/phrasebook/Sentences.gf @@ -1,7 +1,8 @@ abstract Sentences = Numeral ** { cat - Sentence ; Object ; Item ; Kind ; Quality ; + Sentence ; Question ; Object ; Item ; Kind ; Quality ; + Place ; PlaceKind ; Currency ; Price ; fun Is : Item -> Quality -> Sentence ; @@ -9,13 +10,22 @@ abstract Sentences = Numeral ** { IWant : Object -> Sentence ; ILike : Item -> Sentence ; - DoYouHave : Kind -> Sentence ; - WhetherIs : Item -> Quality -> Sentence ; + DoYouHave : Kind -> Question ; + WhetherIs : Item -> Quality -> Question ; + WhereIs : Place -> Question ; + + HowMuchCost : Item -> Question ; + ItCost : Item -> Price -> Sentence ; + AmountCurrency : Numeral -> Currency -> Price ; + ObjItem : Item -> Object ; ObjNumber : Numeral -> Kind -> Object ; - This, That, These, Those : Kind -> Item ; + This, That, These, Those, The, Thes : Kind -> Item ; SuchKind : Quality -> Kind -> Kind ; Very : Quality -> Quality ; + Too : Quality -> Quality ; + + ThePlace : PlaceKind -> Place ; } diff --git a/examples/phrasebook/SentencesFre.gf b/examples/phrasebook/SentencesFre.gf index 46c57b19c..d4415e74a 100644 --- a/examples/phrasebook/SentencesFre.gf +++ b/examples/phrasebook/SentencesFre.gf @@ -1,3 +1,9 @@ -concrete SentencesFre of Sentences = NumeralFre ** SentencesI with - (DiffPhrasebook = DiffPhrasebookFre), - (Syntax = SyntaxFre) ; +concrete SentencesFre of Sentences = NumeralFre ** SentencesI - [WhetherIs] + with + (DiffPhrasebook = DiffPhrasebookFre), + (Syntax = SyntaxFre) ** open SyntaxFre, ExtraFre in { + + lin WhetherIs item quality = + lin QS {s = \\_ => (EstcequeS (mkS (mkCl item quality))).s} ; + +} diff --git a/examples/phrasebook/SentencesI.gf b/examples/phrasebook/SentencesI.gf index 73c0c9e97..09096dea5 100644 --- a/examples/phrasebook/SentencesI.gf +++ b/examples/phrasebook/SentencesI.gf @@ -4,19 +4,30 @@ incomplete concrete SentencesI of Sentences = Numeral ** Syntax in { lincat - Sentence = Utt ; + Sentence = S ; + Question = QS ; Item = NP ; Kind = CN ; Quality = AP ; Object = NP ; + Place = NP ; + PlaceKind = CN ; + Currency = CN ; + Price = NP ; lin - Is item quality = mkUtt (mkCl item quality) ; - IsNot item quality = mkUtt (mkS negativePol (mkCl item quality)) ; - WhetherIs item quality = mkUtt (mkQCl (mkCl item quality)) ; - IWant obj = mkUtt (mkCl (mkNP i_Pron) want_V2 obj) ; - ILike item = mkUtt (mkCl (mkNP i_Pron) like_V2 item) ; + Is item quality = mkS (mkCl item quality) ; + IsNot item quality = mkS negativePol (mkCl item quality) ; + WhetherIs item quality = mkQS (mkQCl (mkCl item quality)) ; + WhereIs place = mkQS (mkQCl where_IAdv place) ; + IWant obj = mkS (mkCl (mkNP i_Pron) want_V2 obj) ; + ILike item = mkS (mkCl (mkNP i_Pron) like_V2 item) ; DoYouHave kind = - mkUtt (mkQCl (mkCl (mkNP youPol_Pron) have_V2 (mkNP kind))) ; + mkQS (mkQCl (mkCl (mkNP youPol_Pron) have_V2 (mkNP kind))) ; + + HowMuchCost item = mkQS (mkQCl how8much_IAdv (mkCl item cost_V)) ; + ItCost item price = mkS (mkCl item cost_V2 price) ; + AmountCurrency num curr = mkNP <num : Numeral> curr ; + ObjItem i = i ; ObjNumber n k = mkNP <n : Numeral> k ; @@ -24,6 +35,12 @@ incomplete concrete SentencesI of Sentences = Numeral ** That kind = mkNP that_Quant kind ; These kind = mkNP this_Quant plNum kind ; Those kind = mkNP that_Quant plNum kind ; + The kind = mkNP the_Quant kind ; + The kind = mkNP the_Quant kind ; + Thes kind = mkNP the_Quant plNum kind ; SuchKind quality kind = mkCN quality kind ; Very quality = mkAP very_AdA quality ; + Too quality = mkAP too_AdA quality ; + ThePlace kind = mkNP the_Quant kind ; + } diff --git a/examples/phrasebook/Food.gf b/examples/phrasebook/Words.gf index c0ee9077e..dec6358ac 100644 --- a/examples/phrasebook/Food.gf +++ b/examples/phrasebook/Words.gf @@ -1,8 +1,13 @@ -- (c) 2009 Aarne Ranta under LGPL -abstract Food = Sentences ** { +abstract Words = Sentences ** { fun Wine, Cheese, Fish, Pizza : Kind ; Fresh, Warm, Italian, Expensive, Delicious, Boring : Quality ; + + Bar, Restaurant, Toilet : PlaceKind ; + + Euro, Dollar, Lei : Currency ; + } diff --git a/examples/phrasebook/FoodEng.gf b/examples/phrasebook/WordsEng.gf index 45e13813c..017d8aebc 100644 --- a/examples/phrasebook/FoodEng.gf +++ b/examples/phrasebook/WordsEng.gf @@ -1,6 +1,6 @@ -- (c) 2009 Aarne Ranta under LGPL -concrete FoodEng of Food = SentencesEng ** +concrete WordsEng of Words = SentencesEng ** open SyntaxEng, ParadigmsEng in { lin Wine = mkCN (mkN "wine") ; @@ -14,4 +14,12 @@ concrete FoodEng of Food = SentencesEng ** Delicious = mkAP (mkA "delicious") ; Boring = mkAP (mkA "boring") ; + Restaurant = mkCN (mkN "restaurant") ; + Bar = mkCN (mkN "bar") ; + Toilet = mkCN (mkN "toilet") ; + + Euro = mkCN (mkN "euro" "euros") ; -- to prevent euroes + Dollar = mkCN (mkN "dollar") ; + Lei = mkCN (mkN "leu" "lei") ; + } diff --git a/examples/phrasebook/FoodFin.gf b/examples/phrasebook/WordsFin.gf index 59e15b039..d26b7f797 100644 --- a/examples/phrasebook/FoodFin.gf +++ b/examples/phrasebook/WordsFin.gf @@ -1,6 +1,6 @@ -- (c) 2009 Aarne Ranta under LGPL -concrete FoodFin of Food = SentencesFin ** +concrete WordsFin of Words = SentencesFin ** open SyntaxFin, ParadigmsFin in { lin Wine = mkCN (mkN "viini") ; @@ -18,6 +18,14 @@ concrete FoodFin of Food = SentencesFin ** Delicious = mkAP (mkA "herkullinen") ; Boring = mkAP (mkA "tylsä") ; + Restaurant = mkCN (mkN "ravintola") ; + Bar = mkCN (mkN "baari") ; + Toilet = mkCN (mkN "vessa") ; + + Euro = mkCN (mkN "euro") ; + Dollar = mkCN (mkN "dollari") ; + Lei = mkCN (mkN "lei") ; + -- oper ---- optimization lasts forever -- mkCNN : Str -> CN = \s -> mkCN (mkN s) ; -- mkAPA : Str -> AP = \s -> mkAP (mkA s) ; diff --git a/examples/phrasebook/FoodFre.gf b/examples/phrasebook/WordsFre.gf index 0c7c1af1c..733038ce3 100644 --- a/examples/phrasebook/FoodFre.gf +++ b/examples/phrasebook/WordsFre.gf @@ -1,6 +1,6 @@ -- (c) 2009 Ramona Enache and Aarne Ranta under LGPL
-concrete FoodFre of Food = SentencesFre ** open
+concrete WordsFre of Words = SentencesFre ** open
SyntaxFre,
ParadigmsFre in
{
@@ -20,6 +20,14 @@ Expensive = mkAPA "cher" ; Delicious = mkAPA "délicieux" ;
Boring = mkAPA "ennuyeux" ;
+ Restaurant = mkCN (mkN "restaurant") ;
+ Bar = mkCN (mkN "bar") ;
+ Toilet = mkCN (mkN "toilette") ;
+
+ Euro = mkCN (mkN "euro") ;
+ Dollar = mkCN (mkN "dollar") ;
+ Lei = mkCN (mkN "lei") ; ---- ?
+
oper
mkAPA : (_ : Str) -> AP = \x -> mkAP (mkA x) ;
diff --git a/examples/phrasebook/FoodRon.gf b/examples/phrasebook/WordsRon.gf index 76cc3753f..673eead8f 100644 --- a/examples/phrasebook/FoodRon.gf +++ b/examples/phrasebook/WordsRon.gf @@ -1,6 +1,6 @@ -- (c) 2009 Ramona Enache under LGPL
-concrete FoodRon of Food = SentencesRon ** open
+concrete WordsRon of Words = SentencesRon ** open
SyntaxRon,
ParadigmsRon in
{
@@ -20,6 +20,14 @@ Expensive = mkAPA "scump" "scumpă" "scumpi" "scumpe" ; Delicious = mkAPA "delicios" "delcioasă" "delicioşi" "delicioase" ;
Boring = mkAPA "plictisitor" "plictisitoare" "plictisitori" "plictisitoare" ;
+ Restaurant = mkCN (mkN "restaurant") ;
+ Bar = mkCN (mkN "bar") ;
+ Toilet = mkCN (mkN "toaleta") ;
+
+ Euro = mkCN (mkN "euro") ;
+ Dollar = mkCN (mkN "dollar") ;
+ Lei = mkCN (mkN "leu" "lei") ;
+
oper
mkAPA : (_,_,_,_ : Str) -> AP = \x,y,z,u -> mkAP (mkA x y z u) ;
diff --git a/examples/phrasebook/www/phrasebook.css b/examples/phrasebook/www/phrasebook.css new file mode 100644 index 000000000..17d7350c9 --- /dev/null +++ b/examples/phrasebook/www/phrasebook.css @@ -0,0 +1,37 @@ +body { + background: #ccc url("http://www.grammaticalframework.org:41296/fridge/se.chalmers.cs.gf.gwt.FridgeApp/brushed-metal.png"); +} + +h1, h2, h3, small, th { font-family: sans-serif; } + +th, td { vertical-align: baseline; text-align: left; } + +div#surface { + min-height: 3ex; + margin: 5px; + padding: 5px; + border: 3px dashed #e0e0e0; +} + +div#words { + min-height: 3ex; + margin: 5px; + padding: 6px; + border: 3px solid #e0e0e0; +} + +div.word, span.word, div#words div { + display: inline-block; + font-family: sans-serif; + background-color: white; + border: 1px solid black; + padding: 3px; + margin: 3px; +} + +.invalid { color: red; } + +div.modtime { float: right; } +.modtime { color: #444; white-space: nowrap; } + +ul.space>li { margin-top: 0.5ex; } diff --git a/examples/phrasebook/www/phrasebook.html b/examples/phrasebook/www/phrasebook.html new file mode 100644 index 000000000..7d34a27fa --- /dev/null +++ b/examples/phrasebook/www/phrasebook.html @@ -0,0 +1,28 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> <head> +<title>Phrasebook</title> +<link rel=stylesheet type="text/css" href="phrasebook.css"> +<script type="text/JavaScript" src="support.js"></script> +<script type="text/JavaScript" src="phrasebook.js"></script> +</head> + +<body onload="start_minibar()"> + +<div id=minibar> +</div> +<hr> + +<small> + +Based on +<a href="http://www.cs.chalmers.se/~hallgren/minibar/minibar.html">minibar</a>, +powered by +<a href="http://www.grammaticalframework.org">GF</a> + + +</body> + +</html> + + + diff --git a/examples/phrasebook/www/phrasebook.js b/examples/phrasebook/www/phrasebook.js new file mode 100644 index 000000000..bbbcfd061 --- /dev/null +++ b/examples/phrasebook/www/phrasebook.js @@ -0,0 +1,211 @@ + +//var server="http://www.grammaticalframework.org:41296" +//var server="http://tournesol.cs.chalmers.se:41296"; +var server="http://localhost:41296"; +var grammars_url=server+"/grammars/"; +var current_grammar_url=grammars_url+"Foods.pgf"; + +var tree_icon=server+"/translate/se.chalmers.cs.gf.gwt.TranslateApp/tree-btn.png"; + +function start_minibar() { + var minibar=element("minibar"); + minibar.appendChild(div_id("menubar")); + minibar.appendChild(div_id("surface")); + minibar.appendChild(div_id("words")); + minibar.appendChild(div_id("translations")); + /// jsonp(grammars_url+"grammars.cgi",""); // calls show_grammarlist + show_grammarlist(["Phrasebook.pgf","Foods.pgf", "ResourceDemo.pgf"]) ; +} + +function show_grammarlist(grammars) { + var menu=empty("select"); + for(var i=0;i<grammars.length;i++) { + var opt=empty("option"); + opt.setAttribute("value",grammars[i]); + opt.innerHTML=grammars[i]; + menu.appendChild(opt); + } + menu.setAttribute("onchange","new_grammar(this)"); + var menubar=element("menubar"); + // menubar.innerHTML="Grammar: "; + // menubar.appendChild(menu); + menubar.appendChild(text("From: ")); + menubar.appendChild(empty_id("select","language_menu")); + menubar.appendChild(button("Del","delete_last()")); + menubar.appendChild(button("Clear","clear_all()")); + menubar.appendChild(button("Random","generate_random()")); + select_grammar(grammars[0]); +} + +function new_grammar(menu) { + select_grammar(menu.options[menu.selectedIndex].value); +} + +function select_grammar(grammar_name) { + current_grammar_url=grammars_url+grammar_name; + jsonp(current_grammar_url,"show_languages"); +} + +function show_languages(grammar) { + var r=""; + var lang=grammar.languages; + var menu=element("language_menu"); + menu.setAttribute("onchange","new_language(this)"); + menu.grammar=grammar; + menu.innerHTML=""; + for(var i=0; i<lang.length; i++) { + if(lang[i].canParse) { + var opt=empty("option"); + opt.setAttribute("value",""+i); + opt.innerHTML=short_name(lang[i].name); + menu.appendChild(opt); + } + } + new_language(menu); +} + +function short_name(cnc) { + var s = "" ; + for (var c = cnc.length - 3 ; c < cnc.length ; c++) + s = s + cnc[c] ; + return s ; +} + +function new_language(menu) { + var ix=menu.options[menu.selectedIndex].value; + var langname=menu.grammar.languages[ix].name; + menu.current={from: langname, input: ""}; + clear_all(); +} + +function clear_all1() { + var menu=element("language_menu"); + menu.current.input=""; + menu.previous=null; + element("surface").innerHTML=""; + element("translations").innerHTML=""; + return menu; +} + +function clear_all() { + get_completions(clear_all1()); +} + +function delete_last() { + var menu=element("language_menu"); + if(menu.previous) { + menu.current.input=menu.previous.input; + menu.previous=menu.previous.previous; + var s=element("surface"); + s.removeChild(s.lastChild); + element("translations").innerHTML=""; + get_completions(menu); + } +} + +function generate_random() { + jsonp(current_grammar_url+"?command=random&random="+Math.random(),"lin_random"); + +} + +function lin_random(abs) { + var menu=element("language_menu"); + var lang=menu.current.from; + jsonp(current_grammar_url+"?command=linearize&tree="+encodeURIComponent(abs[0].tree) + +"&to="+lang, + "show_random") + +} + +function show_random(random) { + var menu=clear_all1(); + var words=random[0].text.split(" "); + for(var i=0;i<words.length;i++) + add_word1(menu,words[i]+" "); + element("words").innerHTML="..."; + get_completions(menu); +} + +function get_completions(menu) { + var c=menu.current; + jsonp(current_grammar_url + +"?command=complete" + +"&from="+encodeURIComponent(c.from) + +"&input="+encodeURIComponent(c.input), + "show_completions"); +} + +function word(s) { + var w=div_class("word",text(s)); + w.setAttribute("onclick",'add_word("'+s+'")'); + return w; +} + +function add_word1(menu,s) { + menu.previous={ input: menu.current.input, previous: menu.previous }; + menu.current.input+=s; + element("surface").appendChild(span_class("word",text(s))); +} + +function add_word(s) { + var menu=element("language_menu"); + add_word1(menu,s); + element("words").innerHTML="..."; + get_completions(menu); +} + +function show_completions(completions) { + var box=element("words"); + var menu=element("language_menu"); + var prefixlen=menu.current.input.length; + var emptycnt=0; + box.innerHTML=""; + for(var i=0;i<completions.length;i++) { + var s=completions[i].text.substring(prefixlen); + if(s.length>0) box.appendChild(word(s)); + else emptycnt++; + } + if(emptycnt>0) + //setTimeout(function(){get_translations(menu);},200); + get_translations(menu); +} + +function get_translations(menu) { + jsonp(current_grammar_url + +"?command=translategroup" + // +"?command=translate" + +"&from="+encodeURIComponent(menu.current.from) + +"&input="+encodeURIComponent(menu.current.input), + "show_translations") +} + +function show_translations(translations) { + var trans=element("translations"); + var cnt=translations.length; + trans.innerHTML=""; + for(p=0;p<cnt;p++) { + var t=translations[p]; + var lin=t.linearizations; + var tbody=empty("tbody"); + tbody.appendChild(tr([th(text(t.to+":"))])); + for(var i=0;i<lin.length;i++) + tbody.appendChild(tr([(text(lin[i].text))])); + trans.appendChild(wrap("table",tbody)); + } +} + + +function toggle_img(i) { + var tmp=i.src; + i.src=i.other; + i.other=tmp; +} + + +/* +se.chalmers.cs.gf.gwt.TranslateApp/align-btn.png + +GET /grammars/Foods.pgf?&command=abstrtree&tree=Pred+(This+Fish)+(Very+Fresh) +GET /grammars/Foods.pgf?&command=parsetree&tree=Pred+(This+Fish)+Expensive&from=FoodsAfr +GET /grammars/Foods.pgf?&command=alignment&tree=Pred+(This+Fish)+Expensive +*/ diff --git a/examples/phrasebook/www/support.js b/examples/phrasebook/www/support.js new file mode 100644 index 000000000..15ccc38d0 --- /dev/null +++ b/examples/phrasebook/www/support.js @@ -0,0 +1,157 @@ +function element(id) { + return document.getElementById(id); +} + +// Inspired by the function jsonp from +// http://www.west-wind.com/Weblog/posts/107136.aspx +// See also http://niryariv.wordpress.com/2009/05/05/jsonp-quickly/ +// http://en.wikipedia.org/wiki/JSON#JSONP +function jsonp(url,callback) +{ + if (url.indexOf("?") > -1) + url += "&jsonp=" + else + url += "?jsonp=" + url += callback + "&"; + //url += new Date().getTime().toString(); // prevent caching + + var script = empty("script"); + script.setAttribute("src",url); + script.setAttribute("type","text/javascript"); + document.body.appendChild(script); +} + +/* --- HTML construction ---------------------------------------------------- */ +function text(s) { return document.createTextNode(s); } + +function empty(tag,name,value) { + var el=document.createElement(tag); + if(name && value) el.setAttribute(name,value); + return el; +} + +function empty_id(tag,id) { return empty(tag,"id",id); } +function empty_class(tag,cls) { return empty(tag,"class",cls); } + +function div_id(id) { return empty_id("div",id); } + +function wrap(tag,contents) { + var el=empty(tag); + el.appendChild(contents); + return el; +} + +function wrap_class(tag,cls,contents) { + var el=empty_class(tag,cls); + if(contents) el.appendChild(contents); + return el; +} + +function span_class(cls,contents) { return wrap_class("span",cls,contents); } +function div_class(cls,contents) { return wrap_class("div",cls,contents); } + +function p(contents) { return wrap("p",contents); } +function dt(contents) { return wrap("dt",contents); } + +function th(contents) { return wrap("th",contents); } +function td(contents) { return wrap("td",contents); } + +function tr(cells) { + var tr=empty("tr"); + for(var i=0;i<cells.length;i++) + tr.appendChild(cells[i]); + return tr; +} + +function button(label,action) { + var el=empty("input"); + el.setAttribute("type","button"); + el.setAttribute("value",label); + el.setAttribute("onclick",action); + return el; +} + +function appendChildren(el,cs) { + for(var i=0;i<cs.length;i++) + el.appendChild(cs[i]); + return el; +} + +function tda(cs) { return appendChildren(empty("td"),cs); } + +function img(src) { return empty("img","src",src); } + +/* --- Debug ---------------------------------------------------------------- */ + +function show_props(obj, objName) { + var result = ""; + for (var i in obj) { + result += objName + "." + i + " = " + obj[i] + "<br>"; + } + return result; +} + +function field_names(obj) { + var result = ""; + for (var i in obj) { + result += " " + i; + } + return result; +} + +/* --- Data manipulation ---------------------------------------------------- */ +function swap(a,i,j) { // Note: this doesn't work on strings. + var tmp=a[i]; + a[i]=a[j]; + a[j]=tmp; + return a; +} + +function sort(a) { // Note: this doesn't work on strings. + for(var i=0;i<a.length-1;i++) { + var min=i; + for(var j=i+1;j<a.length;j++) + if(a[j]<a[min]) min=j; + if(min!=i) swap(a,i,min); + } + return a; +} + +function filter(p,xs) { + var ys=[]; + for(var i=0;i<xs.length;i++) + if(p(xs[i])) ys[ys.length]=xs[i]; + return ys; +} + +function implode(cs) { + /* + var s=""; + for(var i=0;i<cs.length;i++) + s+=cs[i]; + return s; + */ + return cs.join(""); +} +/* +function all(p,xs) { + for(var i=0;i<xs.length;i++) + if(!p(xs[i])) return false; + return true; +} +*/ + +function map(f,xs) { + var ys=[]; + for(var i=0;i<xs.length;i++) ys[i]=f(xs[i]); + return ys; +} + +function mapc_from(f,xs,i,ys,cont) { + if(i<xs.length) + f(xs[i],function(y){ys[i]=y;mapc_from(f,xs,i+1,ys,cont)}); + else + cont(ys); +} + +function mapc(f,xs,cont) { mapc_from(f,xs,0,[],cont); } |
