(* ATTENZIONE: ci sono problemi con i .ind e i .var!!!! *) open MathQL;; open Mathql_semantics;; (* estrae il fid dalla uri(str) e toglie le virgole, es: ",1,1,1,1" -> "1111" *) let extract_fid str = let pos = String.index str ',' in Str.string_after str (pos+1) ;; (* * valuta il preambolo *) let preeval p = match p with Some s -> s | None -> "[^/]*" ;; (* FUNZIONE DI MATCHING: prende il descrittore del file delle uri e il path da matchare formato stringa e restituisce la lista dei path che fanno match in formato stringa !! TAIL-RECURSIVE !! *) let pmatch inp pre path fi = let rec aux inp pre path fi acc = let s= try Some (Str.string_after (input_line(inp)) 57) with End_of_file -> None in match s with | Some s -> if (String.get s 0) != ' ' then begin let cpos = String.index s ':' in let apre = Str.string_before s cpos in (* prendo il pre in s *) let s2 = Str.string_after s (cpos+1) in let p = (String.length s2)-2 (* NON capisco perche' con 3 non vada bene !!!!*) in let sok = Str.string_before s2 p in if fi = "" (* CASO fi VUOTO*) then if pre = "[^/]*" (* CASO pre QUALSIASI*) then if (Str.string_match (Str.regexp path) sok 0) then begin (*let sokg = Str.replace_first (Str.regexp ",") "#" sok in let sokgs = Str.global_replace (Str.regexp ",") "/" sokg *) let pos= String.index sok '"' in let sokv= Str.string_before sok pos in (* let sokve = sokv ^ ".xml" in*) aux inp pre path fi (sokv::acc) end else (aux inp pre path fi acc) else (* CASO pre SPECIFICO *) begin (*print_endline ("sok:" ^ sok); print_endline ("path:" ^ path);*) if (Str.string_match (Str.regexp path) sok 0) && (apre = pre) then begin (*let sokg = Str.replace_first (Str.regexp ",") "#" sok in let sokgs = Str.global_replace (Str.regexp ",") "/" sokg in*) let pos= String.index sok '"' in let sokv= Str.string_before sok pos in (*let sokve = sokv ^ ".xml" in*) aux inp pre path fi (sokv::acc) end else (aux inp pre path fi acc) end else (* CASO fi ESISTENTE *) if pre = "[^/]*" (* CASO pre QUALSIASI*) then if String.contains sok ',' then let pos = String.index sok ',' in let sokwfi = Str.string_before sok pos in if (Str.string_match (Str.regexp path) sokwfi 0) && (Str.string_match (Str.regexp fi) (extract_fid sok) 0) then begin (*let sokg = Str.replace_first (Str.regexp ",") "#" sok in let sokgs = Str.global_replace (Str.regexp ",") "/" sokg in*) let pos= String.index sok '"' in let sokv= Str.string_before sok pos in (* let sokve = sokv ^ ".xml" in*) aux inp pre path fi (sokv::acc) end else (aux inp pre path fi acc) else (aux inp pre path fi acc) else (* CASO pre SPECIFICO *) if String.contains sok ',' then let pos = String.index sok ',' in let sokwfi = Str.string_before sok pos in if (Str.string_match (Str.regexp path) sokwfi 0) && (Str.string_match (Str.regexp fi) (extract_fid sok) 0) && (apre = pre) then begin (*let sokg = Str.replace_first (Str.regexp ",") "#" sok in let sokgs = Str.global_replace (Str.regexp ",") "/" sokg in*) let pos= String.index sok '"' in let sokv= Str.string_before sok pos in (*let sokve = sokv ^ ".xml" in*) aux inp pre path fi (sokv::acc) end else (aux inp pre path fi acc) else (aux inp pre path fi acc) end else (aux inp pre path fi acc) | None -> List.rev acc in aux inp pre path fi [] ;; (* Data una lista di token restituisce la stringa formata da tutti i token ----> DA TESTARE!!!! *) let rec token_to_str p = match p with [] -> "" | head::tail -> let h = match head with MQBC s -> Str.global_replace (Str.regexp "\.") "." s | MQBD -> "/" | MQBQ -> "[^/#]?" | MQBS -> "[^/#]*" | MQBSS -> "[^#]*" in h ^ (token_to_str tail) ;; let rec fieval fi = match fi with [] -> "" | MQFC i :: tail -> "/" ^ (string_of_int i) ^ (fieval tail) | MQFS :: tail -> "[^/]*" ^ (fieval tail) | MQFSS :: tail -> ".*" ^ (fieval tail) ;; (* * conversione di un fragment identifier *) let fieval fi = if fi = [] then "" else "#xpointer\\\\(1" ^ fieval fi ^ "\\\\)" (* NON MI E' CHIARO IL PERCHE'!!!! *) ;; let rec attul uril = match uril with head::tail -> let uril_hd = List.hd uril in { uri = uril_hd; attributes = []; extra = ""}::attul (List.tl uril); | [] -> []; ;; (* prende preambolo, body (lista di token con "/"), fi (lista di token senza "/") e restituisce la lista di uri (LISTA DI attributed_uri), contenuti nel file getallrdfuris.xml, che fanno match con l'espressione regolare ricavata da body e con quella ricavata da fi.. tutto chiamando la "pmatch()" ATTENZIONE: il tag in getallrdfuris.xml deve essere piu' lungo, altrimenti "string_match()" da' errore! *) let pattern_ex (apreamble, apattern, afragid) = let path = token_to_str apattern in let fi = fieval afragid in let pre = preeval apreamble in let inp = open_in "./getallrdfuris.xml" in seek_in inp 146; let uril = pmatch inp pre path fi in attul uril; ;;