1 open Mathql_semantics;;
4 (* prende una lista di uri (contenente alternativamente uri e pos) e costruisce una lista di attributed_uri *)
5 let rec attl uril svar =
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
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)
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)
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 *)
36 let muse svar d path =
39 "F" -> "/projects/helm/metadata/create4/forward"
40 | _ -> "/projects/helm/metadata/create4/backward"
45 | _ -> "backPointer" in
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)"
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*)
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))