]> matita.cs.unibo.it Git - helm.git/commitdiff
- first (draft) version of searchEngine
authorStefano Zacchiroli <zack@upsilon.cc>
Fri, 22 Nov 2002 13:36:22 +0000 (13:36 +0000)
committerStefano Zacchiroli <zack@upsilon.cc>
Fri, 22 Nov 2002 13:36:22 +0000 (13:36 +0000)
helm/searchEngine/.cvsignore [new file with mode: 0644]
helm/searchEngine/Makefile [new file with mode: 0644]
helm/searchEngine/searchEngine.ml [new file with mode: 0644]

diff --git a/helm/searchEngine/.cvsignore b/helm/searchEngine/.cvsignore
new file mode 100644 (file)
index 0000000..6ecb17c
--- /dev/null
@@ -0,0 +1 @@
+*.cm[ioxa] *.o searchEngine searchEngine.opt
diff --git a/helm/searchEngine/Makefile b/helm/searchEngine/Makefile
new file mode 100644 (file)
index 0000000..3d979cd
--- /dev/null
@@ -0,0 +1,22 @@
+REQUIRES = http helm-cic_textual_parser helm-cic_proof_checking \
+           helm-xml gdome2-xslt helm-cic_unification helm-mathql \
+           helm-mathql_interpreter
+OCAMLOPTIONS = -package "$(REQUIRES)" -pp camlp4o -I ../gTopLevel -thread
+OCAMLC = ocamlfind ocamlc $(OCAMLOPTIONS)
+OCAMLOPT = ocamlfind ocamlopt $(OCAMLOPTIONS)
+
+LIBRARIES =    ../gTopLevel/mQueryGenerator.cmo
+LIBRARIES_OPT =        ../gTopLevel/mQueryGenerator.cmx
+
+all: searchEngine
+opt: searchEngine.opt
+
+searchEngine: $(LIBRARIES) searchEngine.ml
+       $(OCAMLC) -linkpkg -o $@ $^
+searchEngine.opt: $(LIBRARIES_OPT) searchEngine.ml
+       $(OCAMLOPT) -linkpkg -o $@ $^
+
+clean:
+       rm -f *.cm[aiox] *.o searchEngine{,.opt}
+
+.PHONY: all opt clean
diff --git a/helm/searchEngine/searchEngine.ml b/helm/searchEngine/searchEngine.ml
new file mode 100644 (file)
index 0000000..03c0bb3
--- /dev/null
@@ -0,0 +1,102 @@
+
+(* Copyright (C) 2002, HELM Team.
+ * 
+ * This file is part of HELM, an Hypertextual, Electronic
+ * Library of Mathematics, developed at the Computer Science
+ * Department, University of Bologna, Italy.
+ * 
+ * HELM is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ * 
+ * HELM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HELM; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
+ * MA  02111-1307, USA.
+ * 
+ * For details, see the HELM World-Wide-Web page,
+ * http://cs.unibo.it/helm/.
+ *)
+
+let debug = true;;
+let debug_print s = if debug then prerr_endline s;;
+Http_common.debug := debug;;
+
+open Printf;;
+
+let daemon_name = "Search Engine";;
+let default_port = 48085;;
+let port_env_var = "SEARCH_ENGINE_PORT";;
+
+let port =
+  try
+    int_of_string (Sys.getenv port_env_var)
+  with
+  | Not_found -> default_port
+  | Failure "int_of_string" ->
+      prerr_endline "Warning: invalid port, reverting to default";
+      default_port
+in
+let pp_result result =
+  let result_string = MQueryUtil.text_of_result result "\n" in
+  (sprintf "<html><body><pre>%s</pre></body></html>" result_string)
+in
+let pp_error = sprintf "<html><body><h1>Error: %s</h1></body></html>" in
+let callback req outchan =
+  try
+    (* TODO catch exceptions *)
+    (match req#path with
+    | "/execute" ->
+        let query_string = req#param "query" in
+        let lexbuf = Lexing.from_string query_string in
+        let query = MQueryTParser.query MQueryTLexer.query_token lexbuf in
+        let result = MQueryGenerator.execute_query query in
+        let result_string = MQueryUtil.text_of_result result "\n" in
+        Http_daemon.respond
+          ~body:
+            (sprintf
+              "<html><body><pre>%s</pre></body></html>"
+              result_string)
+          outchan
+    | "/locate" ->
+        let id = req#param "id" in
+        let result = MQueryGenerator.locate id in
+        Http_daemon.respond ~body:(pp_result result) outchan
+    | "/searchPattern" ->
+        let term_string = req#param "term" in
+        let precision = int_of_string (req#param "precision") in
+        let lexbuf = Lexing.from_string term_string in
+        let (dom, mkterm) =
+          CicTextualParser.main CicTextualLexer.token lexbuf
+        in
+        (match dom with
+        | [] -> (* no free variables *)
+            let term = mkterm (fun _ -> None) in
+            let result = MQueryGenerator.searchPattern [] [] term precision in
+            Http_daemon.respond ~body:(pp_result result) outchan
+        | _ ->
+            Http_daemon.respond
+              ~body:(pp_error
+                "identifiers resolution in the environment not yet implemented")
+              outchan)
+    | invalid_request ->
+        Http_daemon.respond_error ~status:(`Client_error `Bad_request) outchan)
+  with
+  | Http_request.Param_not_found attr_name ->
+      Http_daemon.respond_error
+        ~status:(`Client_error `Bad_request)
+        ~body:(sprintf "Parameter '%s' is missing" attr_name)
+        outchan
+in
+printf "%s started and listening on port %d\n" daemon_name port;
+printf "current directory is %s\n" (Sys.getcwd ());
+flush stdout;
+Http_daemon.start' ~port callback;
+printf "%s is terminating, bye!\n" daemon_name
+