From 9543a355016ed3c2abc5e75e4e5d24e8f4d9bb3a Mon Sep 17 00:00:00 2001 From: Claudio Sacerdoti Coen Date: Thu, 10 Apr 2003 15:26:17 +0000 Subject: [PATCH 1/1] 1) fromdos on any html/* file 2) added a new method ask_uwobo to copy to the user a document that is asked to UWOBO (i.e. given a URL, it checks that it is a request to a trusted server) 3) templateambipdq?.html changed in such a way that no character that needs XML escaping happears. In this way we can apply stylesheets on them and what we get is valid HTML + JavaScript 4) All the functions that used to print the result as ASCII have been changed to generate an HELM Theory File. 5) The JavaScript code now asks the searchEngine to ask_uwobo an URL that is obtained by asking UWOBO to apply the stylesheets from theory files to HTML. The UWOBO URL (and parameters) are now hard-coded in JavaScript ;-(( As a result, we now have a very pretty rendering of the results. The hyperlinks are enabled and fully working. Well done! --- helm/searchEngine/Makefile | 2 +- helm/searchEngine/html/editor.html | 2 +- helm/searchEngine/html/editorpdq.html | 4 +- helm/searchEngine/html/index.html | 135 ++++++++++++++++++ helm/searchEngine/html/loc_obj.html | 2 +- helm/searchEngine/html/templateambigpdq1.html | 80 ++--------- helm/searchEngine/html/templateambigpdq2.html | 63 ++------ helm/searchEngine/html/templateambigpdq3.html | 23 ++- helm/searchEngine/searchEngine.ml | 72 +++++++--- 9 files changed, 221 insertions(+), 162 deletions(-) diff --git a/helm/searchEngine/Makefile b/helm/searchEngine/Makefile index 1ae4681e9..7145312c0 100644 --- a/helm/searchEngine/Makefile +++ b/helm/searchEngine/Makefile @@ -1,6 +1,6 @@ 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) diff --git a/helm/searchEngine/html/editor.html b/helm/searchEngine/html/editor.html index c2733a3c9..1e6afe7d0 100644 --- a/helm/searchEngine/html/editor.html +++ b/helm/searchEngine/html/editor.html @@ -4,7 +4,7 @@ qbf=/[[^\[\]<>]*|||]*/ 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() { diff --git a/helm/searchEngine/html/editorpdq.html b/helm/searchEngine/html/editorpdq.html index 07aa2b775..27f070964 100644 --- a/helm/searchEngine/html/editorpdq.html +++ b/helm/searchEngine/html/editorpdq.html @@ -37,8 +37,8 @@ function invia() 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.")} } diff --git a/helm/searchEngine/html/index.html b/helm/searchEngine/html/index.html index 7e09b91f3..879bdd646 100644 --- a/helm/searchEngine/html/index.html +++ b/helm/searchEngine/html/index.html @@ -42,6 +42,10 @@ function initialize() 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(); @@ -398,6 +402,137 @@ var topurl=document.location.protocol+'//'+document.location.host; //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[i]+"
"); + } + } + +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 "+labels[i]+"
"); + } + } + +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 diff --git a/helm/searchEngine/html/templateambigpdq1.html b/helm/searchEngine/html/templateambigpdq1.html index d5fa12260..395283ae3 100644 --- a/helm/searchEngine/html/templateambigpdq1.html +++ b/helm/searchEngine/html/templateambigpdq1.html @@ -1,80 +1,22 @@ @TITLE@ +

-
Please select one or more of the following. -
+
Please select one or more of the following. +
-
- - - - +
+ + + +
diff --git a/helm/searchEngine/html/templateambigpdq2.html b/helm/searchEngine/html/templateambigpdq2.html index 525e69459..ad58e7f1f 100644 --- a/helm/searchEngine/html/templateambigpdq2.html +++ b/helm/searchEngine/html/templateambigpdq2.html @@ -1,64 +1,19 @@ +

There are more than one possible interpretations.

-
Please choose one of the following. -
+
Please choose one of the following. +
-
- - - +
+ + +
diff --git a/helm/searchEngine/html/templateambigpdq3.html b/helm/searchEngine/html/templateambigpdq3.html index 6a6a17b96..851326495 100644 --- a/helm/searchEngine/html/templateambigpdq3.html +++ b/helm/searchEngine/html/templateambigpdq3.html @@ -1,16 +1,11 @@ - - - - -
@RESULTS@
- + + + + + + @RESULTS@ + diff --git a/helm/searchEngine/searchEngine.ml b/helm/searchEngine/searchEngine.ml index 109baa45c..9bc3ef2c9 100644 --- a/helm/searchEngine/searchEngine.ml +++ b/helm/searchEngine/searchEngine.ml @@ -25,8 +25,12 @@ 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 = @@ -51,12 +55,26 @@ let final_results_TPL = pages_dir ^ "/templateambigpdq3.html";; 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 ; + "" ^ string_of_int !idx ^ "." ^ i + ) result "" + in + "

Query Results:

" ^ results ^ "
" + else + "

Query Results:

No results found!

" +;; + +let pp_result result = + "\nQuery Results\n" ^ theory_of_result result ^ "" ;; (** chain application of Pcre substitutions *) @@ -85,6 +103,7 @@ let (title_tag_RE, choices_tag_RE, msg_tag_RE, id_to_uris_RE, id_RE, 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 @@ -95,11 +114,6 @@ let port = 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 "\n\n\n\n
%s
\n\n" - res_string) -in let pp_error = sprintf "

Error: %s

" in let bad_request body outchan = Http_daemon.respond_error ~status:(`Client_error `Bad_request) ~body outchan @@ -123,11 +137,8 @@ let callback (req: Http_types.request) 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 "
%s
" 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 @@ -142,6 +153,19 @@ let callback (req: Http_types.request) outchan = 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 @@ -174,6 +198,8 @@ let callback (req: Http_types.request) outchan = | ""::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 @@ -213,6 +239,8 @@ let callback (req: Http_types.request) outchan = (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 = @@ -228,7 +256,7 @@ let callback (req: Http_types.request) outchan = id_RE, id] line in - output_string outchan processed_line) + output_string outchan (processed_line ^ "\n")) interactive_user_uri_choice_TPL; raise Chat_unfinished)) @@ -262,6 +290,8 @@ let callback (req: Http_types.request) outchan = "\"") interpretations) in + Http_daemon.send_basic_headers ~code:200 outchan ; + Http_daemon.send_CRLF outchan ; iter_file (fun line -> let processed_line = @@ -270,7 +300,7 @@ let callback (req: Http_types.request) outchan = 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 @@ -289,6 +319,8 @@ let callback (req: Http_types.request) outchan = 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 = @@ -311,11 +343,11 @@ let callback (req: Http_types.request) outchan = 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 -- 2.39.2