]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql_interpreter_galax/use.ml
commit of galax mathql interpreter
[helm.git] / helm / ocaml / mathql_interpreter_galax / use.ml
1 open Mathql_semantics;;
2
3
4 (* prende una lista di uri (contenente alternativamente uri e pos) e costruisce una lista di attributed_uri *)
5 let rec attl uril svar = 
6             match uril with                   
7               | head::tail ->  let suri = List.hd uril in
8                                 let len = String.length suri in
9                                  let scuri = String.sub suri 4 (len-4) in
10                                    if String.contains scuri '#' then
11                                     let pos = String.index scuri '#' in
12                                      let s1 = Str.string_before scuri pos in
13                                       let xp = Str.string_after scuri pos in
14                                        let xp = Str.global_replace (Str.regexp "#xpointer(1") "" xp in
15                                         let xp = Str.global_replace (Str.regexp "\/") "," xp in
16                                          let xp = Str.global_replace (Str.regexp ")") "" xp in
17                                           let scuri = (s1 ^ xp) in
18
19                                            let uril_tl = List.tl uril in
20                                             {uri = scuri; attributes = [(svar, (List.hd
21                                              uril_tl))]; extra = ""} :: (attl (List.tl uril_tl) svar) 
22                                    else
23                                     let uril_tl = List.tl uril in
24                                      {uri = scuri; attributes = [(svar, (List.hd
25                                       uril_tl))]; extra = ""} :: (attl (List.tl uril_tl) svar)
26               | [] -> [] 
27
28
29
30
31
32 (* prende un attributed_uri e una svar e  restituisce la lista degli
33 attributed_uri (backward o forward in base al parametro "d") associando
34 la posizione alla var passata *)
35
36 let muse svar d path =
37         let dir =
38           match d with
39               "F" -> "/projects/helm/metadata/create4/forward"
40             | _ -> "/projects/helm/metadata/create4/backward"
41         in 
42           let dtag =
43             match d with
44               "F" -> "refObj"
45             | _ -> "backPointer" in
46
47           let xq ="namespace h=\"http://www.cs.unibo.it/helm/schemas/mattone.rdf#\"
48                    namespace rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
49                 for $i in document(" ^ "\"" ^ dir ^ path.uri ^ ".xml" ^ "\"" ^
50                 ")/rdf:RDF/h:Object//h:" ^ dtag ^ "/h:Occurrence
51                 return ($i/h:occurrence, $i/h:position)"
52         
53           in 
54             let uril = Toputils.eval_query_string xq in (* e' una lista di liste di stringhe*)
55              let  hd_uril = List.hd uril in(*prendo l'elemento in testa che e' quello
56                                       che contiene la lista di uri*)
57               attl hd_uril svar (* adesso dalla lista di uri(hd_uril) costruisco una lista di attributed_uri*)
58
59             
60
61
62 (* prende una lista di uri (Mathql_semantics.result), una variabile (a cui
63 associare la posizione), e la direzione (forward o backward) e per ogni uri chiama la muse *)
64 let use_ex ulist svar d =
65       List.stable_sort (fun {uri = uri1} {uri = uri2} -> compare uri1 uri2) (List.concat (List.map (muse svar d) ulist))
66 ;;
67
68
69