REQUIRES = http helm-cic_textual_parser helm-cic_proof_checking \
helm-xml gdome2-xslt helm-cic_unification helm-mathql \
- helm-mathql_interpreter helm-mquery_generator
+ helm-mathql_interpreter helm-mquery_generator netclient
OCAMLOPTIONS = -package "$(REQUIRES)" -pp camlp4o -I ../gTopLevel
OCAMLC = ocamlfind ocamlc $(OCAMLOPTIONS)
OCAMLOPT = ocamlfind ocamlopt $(OCAMLOPTIONS)
qbf=/[[^\[\]<>]*|<set>|<val>|<boole>]*/
function invia()
{
- window.open(top.topurl+"/execute?query="+escape(document.edit.qta.value),"cw");
+ window.open(top.ask_uwobo(top.topurl+"/execute?query="+escape(document.edit.qta.value)),"cw");
}
function parse1()
{
top.listaliases=top.listaliases+escape(top.aliasglob[i]+" ");
}
//alert(top.listaliases);
- window.open(top.topurl+"/searchPattern?term="+escape(document.invio.expression.value)+"&aliases="+top.listaliases,"cw");
- }
+ window.open(top.ask_uwobo(top.topurl+"/searchPattern?term="+escape(document.invio.expression.value)+"&aliases="+top.listaliases),"cw");
+ }
//window.open(top.topurl+top.action+"templateambigpdq2.html","bw")}
else {alert("Please complete the query before.")}
}
actinput=0;
numeroazioniannullate=0;
}
+function ask_uwobo(url)
+ {
+ return (top.topurl+"/ask_uwobo?url="+escape("http://mowgli.cs.unibo.it:58080/apply?xmluri=" + escape(url) + "&keys=T1%2CT2%2CL%2CE¶m.processorURL=http%3A//mowgli.cs.unibo.it%3A58080/¶m.getterURL=http%3A//mowgli.cs.unibo.it%3A58081/¶m.proofcheckerURL=http%3A//mowgli.cs.unibo.it%3A58084/¶m.draw_graphURL=http%3A//mowgli.cs.unibo.it%3A58083/¶m.uri_set_queueURL=http%3A//mowgli.cs.unibo.it%3A58082/¶m.UNICODEvsSYMBOL=unicode¶m.keys=d_c%2CC1%2CHC2%2CL¶m.thkeys=T1%2CT2%2CL%2CE¶m.embedkeys=d_c%2CTC1%2CHC2%2CL¶m.doctype-public=-//W3C//DTD%20XHTML%201.0%20Transitional//EN¶m.encoding=iso-8859-1¶m.thencoding=iso-8859-1¶m.media-type=text/html¶m.thmedia-type=text/html¶m.interfaceURL=http%3A//helm.cs.unibo.it/helm/html/cic/index.html¶m.thinterfaceURL=http%3A//helm.cs.unibo.it/helm/html/theory/index.html¶m.CICURI=dummy:query_result¶m.naturalLanguage=yes¶m.annotations=no¶m.topurl=http://helm.cs.unibo.it/helm&prop.method=html"));
+ }
function help(w) // quando invocata, visualizza l' help relativo ad un oggetto. Di solito รจ legata ad un evento onFocus o onMouseOver.
{
hw.document.close();
//var topurl="";
var action="/getpage?url=";
//var action="";
+
+
+// UTILITY FUNCTIONS FOR templateambigpdq1.html
+function templateambigpdq1_armageddon()
+ {
+ top.initialize();
+ top.window.open(top.topurl+top.action+"start.html","qw");
+ top.window.open(top.topurl+top.action+"blank.html","cw");
+ top.window.open(top.topurl+top.action+"blank.html","hw");
+ top.window.open(top.topurl+top.action+"blank.html","gw");
+ top.window.open(top.topurl+top.action+"blank.html","sw");
+ }
+
+function templateambigpdq1_resetta()
+ {
+ if (confirm("This will erase your query and start a new one. Are you sure you want to do this?"))
+ {templateambigpdq1_armageddon();}
+ }
+
+function templateambigpdq1_listauri(document,elenco)
+ {
+ for (i=0;i<elenco.length;i++)
+ {
+ document.write("<input type=checkbox name=uricheck value="+elenco[i]+"> "+elenco[i]+"<br>");
+ }
+ }
+
+function templateambigpdq1_invia(document,top,elenco,ident)
+ {
+ vecchiavlds=top.vlds.length;
+ stringa=top.topurl+"/searchPattern?term="+top.terminecic;
+ stringa=stringa+"&aliases="+top.listaliases;
+ stringa=stringa+"&choices=";
+ var choices = "";
+ top.vlds[top.vlds.length]=ident;
+ for (j=0;j<elenco.length;j++)
+ {
+ if (document.disamb.uricheck[j].checked)
+ {
+ top.vlds[top.vlds.length]=document.disamb.uricheck[j].value;
+ }
+ }
+ top.vlds[top.vlds.length]=";";
+ for (j=0;j<top.vlds.length;j++)
+ {
+ choices=choices+(top.vlds[j]==";"?";":escape(top.vlds[j]))+" ";
+ }
+ choices=choices.substring(0,choices.length-2);
+ stringa=stringa+escape(choices);
+ if (top.vlds.length==vecchiavlds){alert("You must select at least one of the options.");}
+ else
+ {
+ window.open(ask_uwobo(stringa),"cw");
+ }
+ }
+
+ function templateambigpdq1_selezionaCostanti(document,elenco) {
+ for (i=0; i<elenco.length; i++) {
+ if (elenco[i].substring(elenco[i].length-4, elenco[i].length) != ".var") {
+ document.disamb.uricheck[i].checked = true;
+ } else {
+ document.disamb.uricheck[i].checked = false;
+ }
+ }
+ }
+
+
+
+// UTILITY FUNCTIONS FOR templateambigpdq2.html
+function templateambigpdq2_armageddon()
+ {
+ top.initialize();
+ top.window.open(top.topurl+top.action+"start.html","qw");
+ top.window.open(top.topurl+top.action+"blank.html","cw");
+ top.window.open(top.topurl+top.action+"blank.html","hw");
+ top.window.open(top.topurl+top.action+"blank.html","gw");
+ top.window.open(top.topurl+top.action+"blank.html","sw");
+ }
+
+function templateambigpdq2_resetta()
+ {
+ if (confirm("This will erase your query and start a new one. Are you sure you want to do this?"))
+ {templateambigpdq2_armageddon();}
+ }
+
+function templateambigpdq2_listainterpretazioni(document,elenco,labels)
+ {
+ for (i=0;i<elenco.length;i++)
+ {
+ document.write("<input type=radio name=interp value="+elenco[i]+"> "+labels[i]+"<br />");
+ }
+ }
+
+function templateambigpdq2_invia(document,elenco)
+ {
+ stringa=top.topurl+"/searchPattern?term="+top.terminecic;
+ stringa=stringa+"&aliases="+(top.listaliases==""?"":"%20");
+ controllo=stringa.length;
+ for (j=0;j<elenco.length;j++)
+ {
+ if (document.disamb.interp[j].checked)
+ {
+ stringa=stringa+escape(elenco[j]);
+
+ // TODO da implementare nella terza fase
+ //top.aliasglob[top.aliasglob.length]=document.disamb.interp[j].value;
+
+ //for (k=0;k<top.aliasglob.length;k++){alert(top.aliasglob[k])}
+ //top.listaliases=top.listaliases+document.disamb.interp[j].value;//in caso di query ulteriori con la stessa lista di alias
+ }
+
+ }
+ if (stringa.length!=controllo)
+ {
+ window.open(ask_uwobo(stringa),"cw");
+ }
+ else {alert("You must choose one option.");}
+ }
+
+
+
+// UTILITY FUNCTIONS FOR templateambigpdq3.html
+function templateambigpdq3_init(aliases)
+{
+ top.aliasglob = new Array();
+ for (i=0; i<aliases.length; i++) {
+ top.aliasglob[i] = aliases[i];
+ }
+ top.vlds=new Array();
+ top.window.open(top.topurl+top.action+"editorpdq.html", "sw");
+}
</SCRIPT>
</HEAD>
<script>
function invia()
{
top.window.open(top.topurl+top.action+"start.html","qw");
- top.window.open(top.topurl+"/locate?id="+document.locate.oggetto.value,"bw");
+ top.window.open(top.ask_uwobo(top.topurl+"/locate?id="+document.locate.oggetto.value),"bw");
}
</SCRIPT>
</HEAD>
<HTML>
<HEAD>
<TITLE>@TITLE@</TITLE>
+<style> A { text-decoration: none } </style>
<SCRIPT language="Javascript">
-var ambiguousinput="@MSG@";
-var elenco = new Array(@CHOICES@);
-var id = "@ID@";
-function armageddon()
- {
- top.initialize();
- top.window.open(top.topurl+top.action+"start.html","qw");
- top.window.open(top.topurl+top.action+"blank.html","cw");
- top.window.open(top.topurl+top.action+"blank.html","hw");
- top.window.open(top.topurl+top.action+"blank.html","gw");
- top.window.open(top.topurl+top.action+"blank.html","sw");
- }
-function resetta()
- {
- if (confirm("This will erase your query and start a new one. Are you sure you want to do this?"))
- {armageddon();}
- }
-function listauri()
- {
- for (i=0;i<elenco.length;i++)
- {
- document.write("<input type=checkbox name=uricheck value="+elenco[i]+"> "+elenco[i]+"<br>");
- }
- }
-function invia()
- {
- vecchiavlds=top.vlds.length;
- stringa=top.topurl+"/searchPattern?term="+top.terminecic;
- stringa=stringa+"&aliases="+top.listaliases;
- stringa=stringa+"&choices=";
- var choices = "";
- top.vlds[top.vlds.length]=id;
- for (j=0;j<elenco.length;j++)
- {
- if (document.disamb.uricheck[j].checked)
- {
- top.vlds[top.vlds.length]=document.disamb.uricheck[j].value;
- }
- }
- top.vlds[top.vlds.length]=";";
- for (j=0;j<top.vlds.length;j++)
- {
- choices=choices+(top.vlds[j]==";"?";":escape(top.vlds[j]))+" ";
- //if (j!=top.vlds.length-1) {stringa=stringa+","}
- }
- choices=choices.substring(0,choices.length-2);
- stringa=stringa+escape(choices);
- if (top.vlds.length==vecchiavlds){alert("You must select at least one of the options.");}
- else
- {
- window.open(stringa,"cw");
- }
- }
- function selezionaCostanti() {
- for (i=0; i<elenco.length; i++) {
- if (elenco[i].substring(elenco[i].length-4, elenco[i].length) != ".var") {
- document.disamb.uricheck[i].checked = true;
- } else {
- document.disamb.uricheck[i].checked = false;
- }
- }
- }
+ var ambiguousinput="@MSG@";
+ var elenco = new Array(@CHOICES@);
+ var ident = "@ID@";
</SCRIPT>
</HEAD>
<BODY>
<h3><SCRIPT language="Javascript">document.write(ambiguousinput);</SCRIPT></h3>
-<br>Please select one or more of the following.
-<br>
+<br />Please select one or more of the following.
+<br />
<form name="disamb">
-<SCRIPT language="Javascript">listauri();</SCRIPT><br>
-<input type=button value="Ok" onClick="invia();">
-<input type=button value="Constants Only" onClick="selezionaCostanti();">
-<input type=button value=Cancel onClick="resetta();">
-<form>
+<SCRIPT language="Javascript">top.templateambigpdq1_listauri(document,elenco);</SCRIPT><br />
+<input type="button" value="Ok" onClick="top.templateambigpdq1_invia(document,top,elenco,ident);" />
+<input type="button" value="Constants Only" onClick="top.templateambigpdq1_selezionaCostanti(document,elenco);" />
+<input type="button" value="Cancel" onClick="top.templateambigpdq1_resetta();" />
+</form>
</BODY>
</HTML>
<HTML>
<HEAD>
+<style> A { text-decoration: none } </style>
<SCRIPT language="Javascript">
-elenco = new Array(@INTERPRETATIONS@);
-labels = new Array(@INTERPRETATIONS_LABELS@);
-function armageddon()
- {
- top.initialize();
- top.window.open(top.topurl+top.action+"start.html","qw");
- top.window.open(top.topurl+top.action+"blank.html","cw");
- top.window.open(top.topurl+top.action+"blank.html","hw");
- top.window.open(top.topurl+top.action+"blank.html","gw");
- top.window.open(top.topurl+top.action+"blank.html","sw");
- }
-function resetta()
- {
- if (confirm("This will erase your query and start a new one. Are you sure you want to do this?"))
- {armageddon();}
- }
-function listainterpretazioni()
- {
- for (i=0;i<elenco.length;i++)
- {
- document.write("<input type=radio name=interp value="+elenco[i]+"> "+labels[i]+"<br>");
- }
- }
-function invia()
- {
- stringa=top.topurl+"/searchPattern?term="+top.terminecic;
- stringa=stringa+"&aliases="+(top.listaliases==""?"":"%20");
- controllo=stringa.length;
- for (j=0;j<elenco.length;j++)
- {
- if (document.disamb.interp[j].checked)
- {
- stringa=stringa+escape(elenco[j]);
-
- // TODO da implementare nella terza fase
- //top.aliasglob[top.aliasglob.length]=document.disamb.interp[j].value;
-
- //for (k=0;k<top.aliasglob.length;k++){alert(top.aliasglob[k])}
- //top.listaliases=top.listaliases+document.disamb.interp[j].value;//in caso di query ulteriori con la stessa lista di alias
- }
-
- }
- if (stringa.length!=controllo)
- {
- window.open(stringa,"cw");
- }
- else {alert("You must choose one option.");}
- }
+ var elenco = new Array(@INTERPRETATIONS@);
+ var labels = new Array(@INTERPRETATIONS_LABELS@);
</SCRIPT>
</HEAD>
<BODY>
<h3>There are more than one possible interpretations.</h3>
-<br>Please choose one of the following.
-<br>
+<br />Please choose one of the following.
+<br />
<form name="disamb">
-<SCRIPT language="Javascript">listainterpretazioni();</SCRIPT><br>
-<input type=button value="Ok" onClick="invia();">
-<input type=button value=Cancel onClick="resetta();">
-<form>
+<SCRIPT language="Javascript">top.templateambigpdq2_listainterpretazioni(document,elenco,labels);</SCRIPT><br />
+<input type="button" value="Ok" onClick="top.templateambigpdq2_invia(document,elenco);" />
+<input type="button" value="Cancel" onClick="top.templateambigpdq2_resetta();" />
+</form>
</BODY>
</HTML>
<html>
- <head>
- <script>
- aliases = new Array(@NEW_ALIASES@);
- top.aliasglob = new Array();
- for (i=0; i<aliases.length; i++) {
- top.aliasglob[i] = aliases[i];
- }
- top.vlds=new Array();
- top.window.open(top.topurl+top.action+"editorpdq.html", "sw");
- </script>
- </head>
- <body>
- <pre>@RESULTS@</pre>
- </body>
+ <head>
+ <style> A { text-decoration: none } </style>
+ <script>
+ top.templateambigpdq3_init(new Array(@NEW_ALIASES@));
+ </script>
+ </head>
+ <body>
+ @RESULTS@
+ </body>
</html>
let debug = true;;
let debug_print s = if debug then prerr_endline s;;
+Http_common.debug := true;;
(* Http_common.debug := true;; *)
+ (** accepted HTTP servers for ask_uwobo method forwarding *)
+let valid_servers = [ "mowgli.cs.unibo.it:58080" ] ;;
+
open Printf;;
let postgresConnectionString =
exception Chat_unfinished
- (** pretty print a MathQL query result to a string *)
-let text_of_result result sep =
- let res_string = ref "" in
- let app = function s -> res_string := !res_string ^ s in
- MQueryUtil.text_of_result app result sep ;
- !res_string
+ (** pretty print a MathQL query result to an HELM theory file *)
+let theory_of_result result =
+ let results_no = List.length result in
+ if results_no > 0 then
+ let mode = if results_no > 10 then "linkonly" else "typeonly" in
+ let results =
+ let idx = ref (results_no + 1) in
+ List.fold_right
+ (fun (uri,attrs) i ->
+ decr idx ;
+ "<tr><td valign=\"top\">" ^ string_of_int !idx ^ ".</td><td><ht:OBJECT uri=\"" ^ uri ^ "\" mode=\"" ^ mode ^ "\"/></td></tr>" ^ i
+ ) result ""
+ in
+ "<h1>Query Results:</h1><table xmlns:ht=\"http://www.cs.unibo.it/helm/namespaces/helm-theory\">" ^ results ^ "</table>"
+ else
+ "<h1>Query Results:</h1><p>No results found!</p>"
+;;
+
+let pp_result result =
+ "<html xmlns:ht=\"http://www.cs.unibo.it/helm/namespaces/helm-theory\">\n<head><title>Query Results</title><style> A { text-decoration: none } </style></head>\n<body>" ^ theory_of_result result ^ "</body></html>"
;;
(** chain application of Pcre substitutions *)
Pcre.regexp "@ID_TO_URIS@", Pcre.regexp "@ID@",
Pcre.regexp "@INTERPRETATIONS@", Pcre.regexp "@INTERPRETATIONS_LABELS@",
Pcre.regexp "@RESULTS@", Pcre.regexp "@NEW_ALIASES@")
+let server_and_port_url_RE = Pcre.regexp "^http://([^/]+)/.*$"
let port =
try
prerr_endline "Warning: invalid port, reverting to default";
default_port
in
-let pp_result result =
- let res_string = text_of_result result "\n" in
- (sprintf "<html>\n<head>\n</head>\n<body>\n<pre>%s</pre>\n</body>\n</html>"
- res_string)
-in
let pp_error = sprintf "<html><body><h1>Error: %s</h1></body></html>" in
let bad_request body outchan =
Http_daemon.respond_error ~status:(`Client_error `Bad_request) ~body outchan
let lexbuf = Lexing.from_string query_string in
let query = MQueryUtil.query_of_text lexbuf in
let result = MQueryGenerator.execute_query query in
- let result_string = text_of_result result "\n" in
- Http_daemon.respond
- ~body:
- (sprintf "<html><body><pre>%s</pre></body></html>" result_string)
- ~headers:[contype] outchan
+ let result_string = pp_result result in
+ Http_daemon.respond ~body:result_string ~headers:[contype] outchan
| "/locate" ->
let id = req#param "id" in
let result = MQueryGenerator.locate id in
Http_daemon.respond_file
~fname:(sprintf "%s/%s" pages_dir (remove_fragment page)) outchan
| page -> Http_daemon.respond_forbidden ~url:page outchan)
+ | "/ask_uwobo" ->
+ let url = req#param "url" in
+ let server_and_port =
+ (Pcre.extract ~rex:server_and_port_url_RE url).(1)
+ in
+ if List.mem server_and_port valid_servers then
+ Http_daemon.respond
+ ~body:(Http_client.Convenience.http_get url)
+ outchan
+ else
+ Http_daemon.respond
+ ~body:(pp_error ("Invalid UWOBO server: " ^ server_and_port))
+ outchan
| "/searchPattern" ->
let term_string = req#param "term" in
let lexbuf = Lexing.from_string term_string in
| ""::id::tail
| id::tail when id<>"" ->
(fun id' ->
+prerr_endline ("#### " ^ id ^ " :=");
+List.iter (fun u -> prerr_endline ("<" ^ Netencoding.Url.decode u ^ ">")) tail;
if id = id' then
Some (List.map (fun u -> Netencoding.Url.decode u) tail)
else
(match selection_mode with
| `SINGLE -> assert false
| `EXTENDED ->
+ Http_daemon.send_basic_headers ~code:200 outchan ;
+ Http_daemon.send_CRLF outchan ;
iter_file
(fun line ->
let formatted_choices =
id_RE, id]
line
in
- output_string outchan processed_line)
+ output_string outchan (processed_line ^ "\n"))
interactive_user_uri_choice_TPL;
raise Chat_unfinished))
"\"")
interpretations)
in
+ Http_daemon.send_basic_headers ~code:200 outchan ;
+ Http_daemon.send_CRLF outchan ;
iter_file
(fun line ->
let processed_line =
interpretations_labels_RE, html_interpretations_labels]
line
in
- output_string outchan processed_line)
+ output_string outchan (processed_line ^ "\n"))
interactive_interpretation_choice_TPL;
raise Chat_unfinished
let must = MQueryLevels2.get_constraints term' in
let must',only = refine_constraints must in
let results = MQueryGenerator.searchPattern must' only in
+ Http_daemon.send_basic_headers ~code:200 outchan ;
+ Http_daemon.send_CRLF outchan ;
iter_file
(fun line ->
let new_aliases =
in
let processed_line =
apply_substs
- [results_RE, text_of_result results "\n";
+ [results_RE, theory_of_result results ;
new_aliases_RE, new_aliases]
line
in
- output_string outchan processed_line)
+ output_string outchan (processed_line ^ "\n"))
final_results_TPL
| _ -> (* unable to instantiate some implicit variable *)
Http_daemon.respond