swish/commit
Added more clients
author | Jan Wielemaker |
---|---|
Mon Mar 16 09:49:41 2015 +0100 | |
committer | Jan Wielemaker |
Mon Mar 16 09:49:41 2015 +0100 | |
commit | d94c75051253fe9b2127ec77be7413a53be3b8c1 |
tree | b3233aa9d1fb76f123d0f6a78733b732515747ba |
parent | 53b4d5e03d58a9d696854c155c5446d3323031dd |
Diff style: patch stat
diff --git a/Makefile b/Makefile index 095b54a..410a2af 100644 --- a/Makefile +++ b/Makefile @@ -16,7 +16,7 @@ HELP=$(addprefix web/help/, $(notdir $(wildcard src/web/help/*.html))) FONTFILES=glyphicons-halflings-regular.ttf \ glyphicons-halflings-regular.woff FONTS=$(addprefix $(FONTDIR)/, $(FONTFILES)) -CLIENTFILES=swish-ask.sh +CLIENTFILES=swish-ask.sh README.md sin-table.html CLIENTS=$(addprefix client/, $(CLIENTFILES)) all: $(DIRS) $(LIBS) $(JS) $(CSS) $(ICONS) $(HELP) $(FONTS) $(CLIENTS) @@ -27,6 +27,8 @@ $(DIRS): lib/swish/%: src/lib/% rsync -u $< $@ client/%: src/client/% + rsync -u $< $@ +client/swish-ask.sh: src/client/swish-ask.sh sed -e 's/:3050}/:3020}/' -e 's/-prolog}/-rdf}/' $< > $@ chmod +x $@ diff --git a/client/README.md b/client/README.md new file mode 100644 index 0000000..e769a44 --- /dev/null +++ b/client/README.md @@ -0,0 +1,43 @@ +# Programming against SWISH + +SWISH is a Prolog development environment built on top of the SWI-Prolog +[Pengines](http://pengines.swi-prolog.org) library. SWISH allows for +prototyping and sharing query patterns. This _readme_ provides +documentation and utilities to access the query results from remote +systems. + +## Extracting result using the (Unix) shell + +`swish-ask.sh` is a simple Unix shell (bash) script that allows for +asking queries against one or more saved programs and return the result +as CSV. Run `swish-ask.sh` to get basic help. + +`swish-ask.sh` requires [curl](http://curl.haxx.se/) + +## Extracting result using Prolog + +Prolog users can exploit the pengine API, in particular +[pengine_rpc/3](http://www.swi-prolog.org/pldoc/doc_for?object=pengines:pengine_rpc/3). +For example: + +```{prolog} +?- [library(pengines)]. +?- pengine_rpc('http://swish.swi-prolog.org', + sin_table(X,Y), + [ src_text(':- include(sin_table).'), + application(swish) + ]). +X = 0, +Y = 0.0 ; +X = 1, +Y = 0.01745240643728351 ; +X = 2 +... +``` + +## Extracting results using JavaScript + +The Pengines infrastructure is designed to make JavaScript talk to +Prolog servers. The file [sin-table.html](sin-table.html) illustrates +this. + diff --git a/client/sin-table.html b/client/sin-table.html new file mode 100644 index 0000000..a6d2d39 --- /dev/null +++ b/client/sin-table.html @@ -0,0 +1,63 @@ +<!DOCTYPE HTML> + +<html> +<head> + <title>Create sine table using Pengines</title> + <script src="http://swish.swi-prolog.org/pengine/pengines.js" + type="text/javascript"> + </script> + <script src="https://code.jquery.com/jquery-2.1.3.min.js" + type="text/javascript"> + </script> +</head> +<body> + +<h1>Extract results from a Pengine/SWISH server</h1> + +<p> +The table below is filled by running a query against the main SWISH +server at <a +href="http://swish.swi-prolog.org">http://swish.swi-prolog.org</a>, +using the saved script <a +href="http://swish.swi-prolog.org/p/sin_table.pl">sin_table.pl</a>. Note that this +example illustrates that you can write interactive web applications +against one or more Pengine enabled Prolog servers without having +direct access to Prolog. + +<table id="sin"> +<tr><th>X<th>Y</tr> +</table> + +<script type="text/x-prolog"> +% Include a script saved on the server, combine it with your code here. +:- include(sin_table). +</script> + +<script type="text/javascript"> +/* +Create a Prolog engine running the code from the above script and the +query specified in `ask`. Get the results in chunks of max 1,000 entries +and ask for more results if there are more available. +*/ + +$(function() { + new Pengine({ server: "http://swish.swi-prolog.org/pengine", + ask: "sin_table(X,Y)", + chunk: 1000, + application: "swish", + onsuccess: function(result) { + for(var i=0; i<result.data.length; i++) { + var b = result.data[i]; + $("#sin").append("<tr><td>"+b.X+"<td>"+b.Y+"</tr>"); + } + if ( result.more ) + result.pengine.next(); + } + }); +}); +</script> + + + +</body> +</html>