]> matita.cs.unibo.it Git - helm.git/blob - helm/searchEngine/mooglePp.ml
added URI printing in the result page (so that mouse-over is not the
[helm.git] / helm / searchEngine / mooglePp.ml
1
2 open Printf
3
4 let pp_request (req: Http_types.request) =
5   match req#path with
6   | "/elim" -> "Elim"
7   | "/match" -> "Match"
8   | "/hint" -> "Hint"
9   | "/locate" -> "Locate"
10   | _ -> assert false
11
12 let pp_error title msg =
13   sprintf "<hr size='1' /><div><b class='error'>%s:</b> %s</div>" title msg
14
15 let paginate ~size ~page l =
16   let min = 1 + (page-1) * size in
17   let max = page * size in
18   let rec aux i l =
19     match (i, l) with
20     | _, [] -> []
21     | i, hd :: tl when i < min -> aux (i+1) tl
22     | i, hd :: tl when i >= min && i <= max -> hd :: aux (i+1) tl
23     | i, hd :: tl -> []
24   in
25   assert (size > 0 && page > 0);
26   aux 1 l
27
28   (** pretty print a list of URIs to an HELM theory file *)
29 let theory_of_result (req: Http_types.request) page result =
30   let results_per_page =
31     Helm_registry.get_int "search_engine.results_per_page"
32   in
33   let results_no = List.length result in
34   let result = paginate ~size:results_per_page ~page result in
35   let query_kind = pp_request req in
36   let template query_kind summary results =
37     sprintf
38       "<div class='resultsbar'>
39         <table width='100%%'>
40          <tr>
41           <td class='left'><b class='query_kind'>%s</b></td>
42           <td class='right'>%s</td>
43          </tr>
44         </table>
45        </div>
46        <br />
47        <div>
48        %s
49        </div>"
50        query_kind summary results
51   in
52   if results_no > 0 then
53    let mode = "typeonly" in
54    let results =
55     let idx = ref ((page - 1) * results_per_page + List.length result + 1) in
56      List.fold_right
57       (fun uri i ->
58         decr idx ;
59         sprintf
60           "<tr>
61            <td valign=\"top\">%d.</td>
62            <td><span class=\"uri\">%s</span></td>
63            </tr>
64            <tr>
65            <td />
66            <td><ht:OBJECT uri=\"%s\" mode=\"%s\"/></td>
67            </tr>%s"
68           !idx uri uri mode i)
69       result ""
70    in
71    template query_kind
72     (sprintf "<b>%d</b> result%s found"
73       results_no (if results_no > 1 then "s" else ""))
74     (sprintf
75       "<table xmlns:ht=\"http://www.cs.unibo.it/helm/namespaces/helm-theory\">
76         %s
77        </table>"
78        results)
79   else
80     template query_kind "no results found" ""
81
82 let html_of_interpretations interps =
83   let radio_button n = 
84     sprintf "<input type=\"radio\" name=\"param.interp\" value=\"%d\" />" n
85   in
86   let text interp =
87     String.concat "<br />" 
88       (List.map
89          (fun (id, value) -> sprintf "<span>%s = %s</span>" id value)
90          interp)
91   in
92   let rec aux n = function
93     | [] -> []
94     | interp::tl -> ((radio_button n)^(text interp))::(aux (n+1) tl)
95   in
96   String.concat "<br />" (aux 0 interps)
97