X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2Frelation.ml;h=ea4fb9cc3525061ff92a2bfd67fe82780e46f271;hb=a96d91e43e25d3d5b36e7c3646831bcf8a401c9d;hp=159369ad2b55fe0469dcc41e158f16a1b0619613;hpb=ba824e867afc3eaf081ed1a1d6526d421242a6a0;p=helm.git diff --git a/helm/ocaml/mathql_interpreter/relation.ml b/helm/ocaml/mathql_interpreter/relation.ml index 159369ad2..ea4fb9cc3 100644 --- a/helm/ocaml/mathql_interpreter/relation.ml +++ b/helm/ocaml/mathql_interpreter/relation.ml @@ -39,16 +39,14 @@ open Utility;; let get_prop_id propl = - let prop = List.hd propl in + let prop = fst propl in if prop="refObj" then "F" else if prop="backPointer" then "B" else assert false ;; -let relation_ex rop path rset attl = - if path = [] then [] - else +let relation_ex inv rop path rset attl = let usek = get_prop_id path in let vvar = if attl = [] then "position" else List.hd attl @@ -57,11 +55,11 @@ let relation_ex rop path rset attl = let rset_list = (* lista di singoletti:resource_set di un elemento *) (List.fold_left (fun acc (uri,l) -> let tv = pgresult_to_string (c#exec ("select id from registry where uri='" ^ uri ^ "'")) in - let qq = "select uri, context from t" ^ tv ^ " where prop_id='" ^ usek ^ "' order by uri asc" in + let qq = "select uri, position from t" ^ tv ^ " where prop_id='" ^ usek ^ "' order by uri asc" in let res = c#exec qq in (List.map (function - [uri;context] -> [(uri,[[(vvar,[context])]])] + [uri;context] -> [(uri,[[((vvar, []),[context])]])] | _ -> assert false ) res#get_list) @ acc ) @@ -74,3 +72,74 @@ let relation_ex rop path rset attl = in edup rset_list ;; + + + +(**** IMPLEMENTAZIONE DELLA RELATION PER GALAX ****) + + +(* trasforma un uri in un filename *) +let tofname uri = + if String.contains uri ':' then + (let len = String.length uri in + let scuri = String.sub uri 4 (len-4) in (*tolgo cic:*) + if String.contains scuri '#' then + (let pos = String.index scuri '#' in + let s1 = Str.string_before scuri pos in + let xp = Str.string_after scuri pos in + let xp = Str.global_replace (Str.regexp "#xpointer(1") "" xp in + let xp = Str.global_replace (Str.regexp "\/") "," xp in + let xp = Str.global_replace (Str.regexp ")") "" xp in + let fname = (s1 ^ xp) in + fname) + else + scuri) + else uri + + +(* prende una lista di uri (contenente alternativamente uri e pos) e costruisce una lista di resource *) +let rec rsetl uril vvar = + match uril with + | uri::tl -> let scuri = (*tofname*) uri in + [(scuri, [[((vvar, []), [(List.hd tl)])]])]::(rsetl (List.tl tl) vvar) + | [] -> [] + + +(* prende una resource e una vvar e restituisce la lista delle resource in relazione (refObj o backPointer in base al parametro "path") con tale resource e associa alla proprieta' il nome della vvar contenuto in "attl" *) +let muse path attl r = + let vvar = if attl = [] then "position" + else List.hd attl + in + let uri = fst r in + let furi = tofname uri in + let dtag = fst path in + let dir = + match dtag with + "refObj" -> "/projects/helm/metadata/create4/forward" + | _ -> "/projects/helm/metadata/create4/backward" + in + let xq ="namespace h=\"http://www.cs.unibo.it/helm/schemas/mattone.rdf#\" + namespace rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" + for $i in document(" ^ "\"" ^ dir ^ furi ^ ".xml" ^ "\"" ^ + ")/rdf:RDF/h:Object/h:" ^ dtag ^ "/h:Occurrence + return ($i/h:occurrence, $i/h:position)" + + in + let uril = Toputils.eval_query_string xq in (* e' una lista di liste di stringhe*) + let hd_uril = List.hd uril in(*prendo la testa che contiene altern. lista di uri e pos. *) + let rset_list = rsetl hd_uril vvar in (* da hd_uril costruisco una lista di resource_set(singoletti)*) + let rec edup = function + [] -> [] + | rs1::tl -> union_ex rs1 (edup tl) + in + edup rset_list + + + + +(* prende un resource_set, una vvar (primo el. di attl) a cui associare la posizione, e la relazione (refObj o backPointer) e per ogni resource chiama la muse +NOTA: "rop" per ora non viene usato perche' vale sempre "ExactOp" *) +let relation_galax_ex inv rop path rset attl = + List.stable_sort (fun (uri1,l1) (uri2,l2) -> compare uri1 uri2) (List.concat (List.map (muse path attl) rset)) + +