X-Git-Url: http://matita.cs.unibo.it/gitweb/?p=helm.git;a=blobdiff_plain;f=helm%2Focaml%2Fmathql_interpreter%2FmQIProperty.ml;fp=helm%2Focaml%2Fmathql_interpreter%2FmQIProperty.ml;h=be559adc7f107bb7dda849d4ebb7a4480c252bde;hp=026e11b488b608831620785a245c70a7934b065c;hb=1c7fb836e2af4f2f3d18afd0396701f2094265ff;hpb=2122459392680c4b53e32a2cf1d4792405f118ce diff --git a/helm/ocaml/mathql_interpreter/mQIProperty.ml b/helm/ocaml/mathql_interpreter/mQIProperty.ml index 026e11b48..be559adc7 100644 --- a/helm/ocaml/mathql_interpreter/mQIProperty.ml +++ b/helm/ocaml/mathql_interpreter/mQIProperty.ml @@ -30,6 +30,7 @@ module M = MathQL module P = MQIPostgres module C = MQIConn module U = MQIUtil +module A = MQIMap let not_supported s = raise (Failure ("MQIProperty: feature not supported: " ^ s)) @@ -112,53 +113,16 @@ let pg_result distinct subj el res = in compose mk_avs res -let get_table mc ct cfl el = - let fst = function - | [] -> None - | head :: tail -> Some head - in - let comp n1 n2 = match n1, n2 with - | None, _ -> n2 - | Some h, Some k when h = k -> n2 - | _, None -> n1 - | _ -> not_supported "comp" - in - let rec get_c prev = function - | [] -> prev - | (_, p, _) :: tail -> get_c (comp prev (fst p)) tail - in - let rec get_e prev = function - | [] -> prev - | (p, _) :: tail -> get_e (comp prev (fst p)) tail - in - get_e (get_c (get_c (fst mc) ct) (List.concat cfl)) el - -let rec decolon s = - let l = String.length s in - try - let i = String.index s ':' in - String.sub s 0 i ^ "_" ^ decolon (String.sub s (succ i) (l - succ i)) - with Not_found -> s - -let conv_bp = function - | [] -> "h_occurrence" - | [t] -> "" - | [_; "h:occurrence"] -> "source" - | [_; t] -> decolon t - | _ -> not_supported "conv_bp" - -let conv_gen = function - | [] -> "source" - | ["objectName"] -> "value" - | [t] -> "" - | [_; t] -> decolon t - | _ -> not_supported "conv" - -let exec_single h mc ct cfl el t = - let table = match t with Some t -> decolon t | None -> "objectName" in - let table, conv = - if table = "backPointer" then "refObj", conv_bp else table, conv_gen - in +let get_table h mc ct cfl el = + let aux_c ts (_, p, _) = A.refine_tables ts (C.tables h p) in + let aux_e ts (p, _) = A.refine_tables ts (C.tables h p) in + let fst = C.tables h mc in + let snd = List.fold_left aux_c fst (ct @ (List.concat cfl)) in + let trd = List.fold_left aux_e snd el in + A.default_table trd + +let exec_single h mc ct cfl el table = + let conv p = C.field h p table in let first = conv mc in let mk_con l = List.map (fun (pat, p, v) -> (pat, conv p, v)) l in let cons_true = mk_con ct in @@ -166,13 +130,14 @@ let exec_single h mc ct cfl el t = let other_cols = List.map (fun (p, _) -> conv p) el in let cols = if first = "" then other_cols else first :: other_cols in let low_level = if C.set h C.Galax then gx_query else pg_query in - pg_result false first el (low_level h table cols cons_true cons_false) + let result = low_level h (C.resolve h table) cols cons_true cons_false in + pg_result false first el result let deadline = 100 let exec h refine mc ct cfl el = if refine <> M.RefineExact then not_supported "exec"; - let table = get_table mc ct cfl el in + let table = get_table h mc ct cfl el in let rec exec_aux ct = match ct with | (pat, p, v) :: tail when List.length v > deadline -> let single s = exec_aux ((pat, p, [s]) :: tail) in