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 @@ + + +PGF online server example + + + + + + + + +

PGF online server example

+ +
+Input: + + + +

+Output: + +

+ + +

Documentation

+ + +
+
+ Last modified: Tue Nov 9 21:54:50 CET 2010 + 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 @@ + + + +GF web services API examples + + + + +

GF web services API examples

+ +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. + +

+The +GF +Web Service API 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 +pgf_online.js. + +

+Note 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... + +

+
These boxes show what the calls look like in the JavaScript + API defined in pgf_online.js. +
These boxes show the corresponding URLs sent to the PGF server. +
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. +
+ +

Initialization

+
+
+ // Select which server and grammars to use: +
var server_options = { +
  grammars_url: "http://www.grammaticalframework.org/grammars/", +
  grammar_list: ["Foods.pgf"] // It's ok to skip this +
} +
var server = pgf_online(server_options); +
+ +

Examples

+ +
+
// Get the list of available grammars +
server.get_grammarlist(callback) +
http://localhost:41296/grammars/grammars.cgi +
["Foods.pgf","Phrasebook.pgf"] +
// Select which grammar to use +
server.switch_grammar("Foods.pgf") +
// Get grammar info (this method could be renamed) +
server.get_languages(callback) +
http://localhost:41296/grammars/Foods.pgf +
{"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"}, + ...] +} +
// Get a random syntax tree +
server.get_random(callback) +
http://localhost:41296/grammars/Foods.pgf?command=random +
[{"tree":"Pred (That Pizza) (Very Boring)"}] +
// Linearize a syntax tree +
server.linearize("Pred (That Pizza) (Very Boring)","FoodsEng",callback) +
http://localhost:41296/grammars/Foods.pgf?command=linearize&tree=Pred+(That+Pizza)+(Very+Boring)&to=FoodsEng +
[{"to":"FoodsEng","text":"that pizza is very boring"}] +
http://localhost:41296/grammars/Foods.pgf?command=linearize&tree=Pred+(That+Pizza)+(Very+Boring) +
[{"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"}, + ... +] +
// Parse a string +
server.parse("FoodEng","that pizza is very boring",callback) +
http://localhost:41296/grammars/Foods.pgf?command=parse&input=that+pizza+is+very+boring&from=FoodsEng +
[{"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)"]}] +
// Translate to all available langauges +
server.translate("FoodEng","that pizza is very boring",callback) +
... +
// Translate to one language +
http://localhost:41296/grammars/Foods.pgf?command=translate&input=that+pizza+is+very+boring&from=FoodsEng&to=FoodsSwe +
[{"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"}]}]}] +
// Get completions (what words could come next) +
server.complete("FoodEng","that pizza is very ",callback) +
http://localhost:41296/grammars/Foods.pgf?command=complete&input=that+pizza+is+very+&from=FoodsEng +
[{"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":""}] +
+
+ Last modified: Tue Nov 9 21:57:49 CET 2010 +
+