]> matita.cs.unibo.it Git - helm.git/blob - helm/ocaml/mathql_interpreter_galax/use.ml
No more useful
[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                                      let uril_tl = List.tl uril in
19                                             {uri = scuri; attributes = [(svar, (List.hd
20                                              uril_tl))]; extra = ""} :: (attl (List.tl uril_tl) svar) 
21                                else
22                                     let uril_tl = List.tl uril in
23                                              {uri = scuri; attributes = [(svar, (List.hd
24                                               uril_tl))]; extra = ""} :: (attl (List.tl uril_tl) svar)
25               | [] -> [] 
26
27
28
29
30
31 (* prende un attributed_uri e una svar e  restituisce la lista degli
32 attributed_uri (backward o forward in base al parametro "d") associando
33 la posizione alla var passata *)
34
35 let muse svar d path =
36         let dir =
37           match d with
38               "F" -> "/projects/helm/metadata/create4/forward"
39             | _ -> "/projects/helm/metadata/create4/backward"
40         in 
41           let dtag =
42             match d with
43               "F" -> "refObj"
44             | _ -> "backPointer" in
45
46           let xq ="namespace h=\"http://www.cs.unibo.it/helm/schemas/mattone.rdf#\"
47                    namespace rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\"
48                 for $i in document(" ^ "\"" ^ dir ^ path.uri ^ ".xml" ^ "\"" ^
49                 ")/rdf:RDF/h:Object//h:" ^ dtag ^ "/h:Occurrence
50                 return ($i/h:occurrence, $i/h:position)"
51         
52           in 
53             let uril = Toputils.eval_query_string xq in (* e' una lista di liste di stringhe*)
54              let  hd_uril = List.hd uril in(*prendo l'elemento in testa che e' quello
55                                       che contiene la lista di uri*)
56               attl hd_uril svar (* adesso dalla lista di uri(hd_uril) costruisco una lista di attributed_uri*)
57
58             
59
60
61 (* prende una lista di uri (Mathql_semantics.result), una variabile (a cui
62 associare la posizione), e la direzione (forward o backward) e per ogni uri chiama la muse *)
63 let use_ex ulist svar d =
64       List.stable_sort (fun {uri = uri1} {uri = uri2} -> compare uri1 uri2) (List.concat (List.map (muse svar d) ulist))
65 ;;
66
67
68