diff options
Diffstat (limited to 'src/runtime/javascript')
| -rw-r--r-- | src/runtime/javascript/minibar/example.html | 51 | ||||
| -rw-r--r-- | src/runtime/javascript/minibar/gf-web-api-examples.html | 126 |
2 files changed, 177 insertions, 0 deletions
diff --git a/src/runtime/javascript/minibar/example.html b/src/runtime/javascript/minibar/example.html new file mode 100644 index 000000000..57c1ddd5c --- /dev/null +++ b/src/runtime/javascript/minibar/example.html @@ -0,0 +1,51 @@ +<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> +<html> <head> +<title>PGF online server example</title> +<style type="text/css"> +body { background: #ddd; } +</style> +<script type="text/JavaScript" src="http://www.grammaticalframework.org/src/runtime/javascript/minibar/support.js"></script> +<script type="text/JavaScript" src="http://www.grammaticalframework.org/src/runtime/javascript/minibar/pgf_online.js"></script> +<script type="text/JavaScript"> + +var server_options={ + grammars_url: "http://www.grammaticalframework.org/grammars/", + grammar_list: ["Syllogism.pgf"] +} +var pgf_server = pgf_online(server_options); + +function call_server() { + pgf_server.parse("SyllogismEng",document.forms[0].input.value,show_output) +} + +function show_output(parsed) { + document.getElementById("output").innerHTML=parsed[0].trees[0] +} + +</script> + +</head> + +<body> +<h1>PGF online server example</h1> + +<form onsubmit="call_server(); return false"> +Input: +<input name=input size=50 value="some humans are not human"> +<input type=submit value=Parse> + +<p> +Output: +<span id=output></span> +</form> + + +<h2>Documentation</h2> +<ul> + <li><a href="http://www.grammaticalframework.org/~hallgren/gf-web-api-examples.html">GF Web API examples</a> +</ul> + +<hr> +<address></address> +<!-- hhmts start --> Last modified: Tue Nov 9 21:54:50 CET 2010 <!-- hhmts end --> +</body> </html> diff --git a/src/runtime/javascript/minibar/gf-web-api-examples.html b/src/runtime/javascript/minibar/gf-web-api-examples.html new file mode 100644 index 000000000..9ae8cc124 --- /dev/null +++ b/src/runtime/javascript/minibar/gf-web-api-examples.html @@ -0,0 +1,126 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<title>GF web services API examples</title> +<meta http-equiv="Content-type" content="text/html;charset=UTF-8"> +<style type="text/css"> +body { background: #ddd; } + +dt { background: #ffc; } +dt.js { background: #cef; margin-bottom: 1ex; } +dd { background: white; margin-top: 1ex; margin-bottom: 1ex; } + +dl.apiexamples>dt, dl.apiexamples>dd { font-family: monospace; } +dl.apiexamples>dd { white-space: pre; } + +</style> + +<body> +<h1>GF web services API examples</h1> + +GF can be used interactively from the GF Shell. Some of the functionality +availiable in the GF shell is also available via the GF web services API. + +<p> +The +<a href="http://code.google.com/p/grammatical-framework/wiki/GFWebServiceAPI">GF +Web Service API</a> page describes the calls supported by the GF web service +API. Below, we illustrate these calls by examples, and also shows +how to make these calls from JavaScript using the API defined in +<a href="http://www.grammaticalframework.org/src/runtime/javascript/minibar/pgf_online.js">pgf_online.js</a>. + +<p> +<em>Note</em> that pgf_online.js was developed with +one particular web application in mind, so the server API provided is +incomplete and might be made more complete in a future version... + +<dl> + <dt class=js>These boxes show what the calls look like in the JavaScript + API defined in pgf_online.js. + <dt>These boxes show the corresponding URLs sent to the PGF server. + <dd>These boxes show the JSON (JavaScript data structures) returned by the PGF + server. This will be passed to the callback function supplied in the + call. +</dl> + +<h2>Initialization</h2> +<dl class=apiexamples> + <dt class=js> + // Select which server and grammars to use: + <br>var server_options = { + <br> grammars_url: "http://www.grammaticalframework.org/grammars/", + <br> grammar_list: ["Foods.pgf"] // It's ok to skip this + <br>} + <br>var server = pgf_online(server_options); +</dl> + +<h2>Examples</h2> + +<dl class=apiexamples> + <dt class=js> // Get the list of available grammars + <br>server.get_grammarlist(callback) + <dt>http://localhost:41296/grammars/grammars.cgi + <dd>["Foods.pgf","Phrasebook.pgf"] + <dt class=js> // Select which grammar to use + <br>server.switch_grammar("Foods.pgf") + <dt class=js>// Get grammar info (this method could be renamed) + <br>server.get_languages(callback) + <dt>http://localhost:41296/grammars/Foods.pgf + <dd>{"name":"Foods", + "userLanguage":"FoodsEng", + "categories":["Comment","Float","Int","Item","Kind","Quality","String"], + "functions":["Boring","Cheese","Delicious","Expensive","Fish","Fresh", + "Italian","Mod","Pizza","Pred","That","These","This","Those","Very", + "Warm","Wine"], + "languages":[{"name":"FoodsBul","languageCode":""}, + {"name":"FoodsEng","languageCode":"en-US"}, + {"name":"FoodsFin","languageCode":""}, + {"name":"FoodsSwe","languageCode":"sv-SE"}, + ...] +} + <dt class=js>// Get a random syntax tree + <br>server.get_random(callback) + <dt>http://localhost:41296/grammars/Foods.pgf?command=random + <dd>[{"tree":"Pred (That Pizza) (Very Boring)"}] + <dt class=js>// Linearize a syntax tree + <br>server.linearize("Pred (That Pizza) (Very Boring)","FoodsEng",callback) + <dt>http://localhost:41296/grammars/Foods.pgf?command=linearize&tree=Pred+(That+Pizza)+(Very+Boring)&to=FoodsEng + <dd>[{"to":"FoodsEng","text":"that pizza is very boring"}] + <dt>http://localhost:41296/grammars/Foods.pgf?command=linearize&tree=Pred+(That+Pizza)+(Very+Boring) + <dd>[{"to":"FoodsBul","text":"онази пица е много еднообразна"}, + {"to":"FoodsEng","text":"that pizza is very boring"}, + {"to":"FoodsFin","text":"tuo pizza on erittäin tylsä"}, + {"to":"FoodsSwe","text":"den där pizzan är mycket tråkig"}, + ... +] + <dt class=js>// Parse a string + <br>server.parse("FoodEng","that pizza is very boring",callback) + <dt>http://localhost:41296/grammars/Foods.pgf?command=parse&input=that+pizza+is+very+boring&from=FoodsEng + <dd>[{"from":"FoodsEng", + "brackets":{"cat":"Comment","fid":10,"index":0,"children":[{"cat":"Item","fid":7,"index":0,"children":[{"token":"that"},{"cat":"Kind","fid":6,"index":0,"children":[{"token":"pizza"}]}]},{"token":"is"},{"cat":"Quality","fid":9,"index":0,"children":[{"token":"very"},{"cat":"Quality","fid":8,"index":0,"children":[{"token":"boring"}]}]}]}, + "trees":["Pred (That Pizza) (Very Boring)"]}] + <dt class=js>// Translate to all available langauges + <br>server.translate("FoodEng","that pizza is very boring",callback) + <dd>... + <dt class=js>// Translate to one language + <dt>http://localhost:41296/grammars/Foods.pgf?command=translate&input=that+pizza+is+very+boring&from=FoodsEng&to=FoodsSwe + <dd>[{"from":"FoodsEng", + "brackets":{"cat":"Comment","fid":10,"index":0,"children":[{"cat":"Item","fid":7,"index":0,"children":[{"token":"that"},{"cat":"Kind","fid":6,"index":0,"children":[{"token":"pizza"}]}]},{"token":"is"},{"cat":"Quality","fid":9,"index":0,"children":[{"token":"very"},{"cat":"Quality","fid":8,"index":0,"children":[{"token":"boring"}]}]}]}, + "translations": + [{"tree":"Pred (That Pizza) (Very Boring)", + "linearizations": + [{"to":"FoodsSwe", + "text":"den där pizzan är mycket tråkig"}]}]}] + <dt class=js>// Get completions (what words could come next) + <br>server.complete("FoodEng","that pizza is very ",callback) + <dt>http://localhost:41296/grammars/Foods.pgf?command=complete&input=that+pizza+is+very+&from=FoodsEng + <dd>[{"from":"FoodsEng", + "brackets":{"cat":"_","fid":0,"index":0,"children":[{"cat":"Item","fid":7,"index":0,"children":[{"token":"that"},{"cat":"Kind","fid":6,"index":0,"children":[{"token":"pizza"}]}]},{"token":"is"},{"token":"very"}]}, + "completions":["boring","delicious","expensive","fresh","Italian","very","warm"], + "text":""}] +</dl> +<hr> +<!-- hhmts start --> Last modified: Tue Nov 9 21:57:49 CET 2010 <!-- hhmts end --> +<address> +<a href="http://www.cse.chalmers.se/~hallgren/>Thomas Hallgren</a> +</address>
\ No newline at end of file |
