- introduced constraints (vs metadata)
- positions no longer hard coded (so that both short and long names are
supported)
- added "where" parameter so that matching could be perfomed either on
conclusion only or on the whole statement
let add_card_constr tbl (n,from,where) = function
| None -> (n,from,where)
| Some (Eq card) ->
let add_card_constr tbl (n,from,where) = function
| None -> (n,from,where)
| Some (Eq card) ->
+ let cur_tbl = tbln n in
- (sprintf "%s as %s" tbl (tbln n) :: from),
- (sprintf "no=%d" card ::
+ (sprintf "%s as %s" tbl cur_tbl :: from),
+ (sprintf "%s.no=%d" cur_tbl card ::
- else [sprintf "table0.source = %s.source" (tbln n)]) @
+ else [sprintf "table0.source = %s.source" cur_tbl]) @
where))
| Some (Gt card) ->
where))
| Some (Gt card) ->
+ let cur_tbl = tbln n in
- (sprintf "%s as %s" tbl (tbln n) :: from),
- (sprintf "no>%d" card ::
+ (sprintf "%s as %s" tbl cur_tbl :: from),
+ (sprintf "%s.no>%d" cur_tbl card ::
- else [sprintf "table0.source = %s.source" (tbln n)]) @
+ else [sprintf "table0.source = %s.source" cur_tbl]) @
where))
let at_least ~(dbh:Dbi.connection) ?concl_card ?full_card
where))
let at_least ~(dbh:Dbi.connection) ?concl_card ?full_card
let from = String.concat ", " from in
let where = String.concat " and " where in
let query = sprintf "select table0.source from %s where %s" from where in
let from = String.concat ", " from in
let where = String.concat " and " where in
let query = sprintf "select table0.source from %s where %s" from where in
let query = dbh#prepare query in
query#execute [];
List.map (function [`String s] -> s | _ -> assert false) (query#fetchall ())
let query = dbh#prepare query in
query#execute [];
List.map (function [`String s] -> s | _ -> assert false) (query#fetchall ())
(SetSet.singleton (StringSet.singleton root))
and inspect_conclusion n t =
(SetSet.singleton (StringSet.singleton root))
and inspect_conclusion n t =
-if n = 0 then SetSet.empty
-else match t with
+ if n = 0 then SetSet.empty
+ else match t with
Cic.Rel _
| Cic.Meta _
| Cic.Sort _
Cic.Rel _
| Cic.Meta _
| Cic.Sort _
| u::l -> u::(drop_repetitions l) in
drop_repetitions (List.sort Pervasives.compare (List.concat l))
| u::l -> u::(drop_repetitions l) in
drop_repetitions (List.sort Pervasives.compare (List.concat l))
-let must_of_prefix m s =
- let s' = List.map (fun u -> `Obj (u, [`InConclusion])) s in
+let must_of_prefix ?(where = `Conclusion) m s =
+ let positions =
+ match where with
+ | `Conclusion -> [`InConclusion]
+ | `Statement -> [`InConclusion; `InHypothesis; `MainHypothesis None]
+ in
+ let s' = List.map (fun u -> `Obj (u, positions)) s in
`Obj (m, [`MainConclusion None]) :: s'
let escape = Str.global_replace (Str.regexp_string "\'") "\\'"
`Obj (m, [`MainConclusion None]) :: s'
let escape = Str.global_replace (Str.regexp_string "\'") "\\'"
-let get_inconcl (dbh:Dbi.connection) uri =
+let get_constants (dbh:Dbi.connection) ~where uri =
+ let positions =
+ match where with
+ | `Conclusion -> ["\"MainConclusion\""; "\"InConclusion\""]
+ | `Statement ->
+ ["\"MainConclusion\""; "\"InConclusion\""; "\"InHypothesis\"";
+ "\"MainHypothesis\""]
+ in
- dbh#prepare (sprintf "select h_occurrence from refObj where source=\"%s\" and (h_position=\"MainConclusion\" or h_position=\"InConclusion\")"
- uri)
+ dbh#prepare
+ (sprintf "select h_occurrence from refObj where source=\"%s\" and (%s)"
+ uri (String.concat " or " positions))
in
query#execute [];
query#fold_left (* transform the result in a set *)
in
query#execute [];
query#fold_left (* transform the result in a set *)
StringSet.add uri set)
StringSet.empty
StringSet.add uri set)
StringSet.empty
-let test_only ~(dbh:Dbi.connection) only u =
- let inconcl = get_inconcl dbh u in
+let at_most ~(dbh:Dbi.connection) ?(where = `Conclusion) only u =
+ let inconcl = get_constants dbh ~where u in
StringSet.subset inconcl only
(* Special handling of equality. The problem is filtering out theorems just
StringSet.subset inconcl only
(* Special handling of equality. The problem is filtering out theorems just
0,"cic:/Coq/Init/Logic/f_equal2.con";
0,"cic:/Coq/Init/Logic/f_equal3.con"]
0,"cic:/Coq/Init/Logic/f_equal2.con";
0,"cic:/Coq/Init/Logic/f_equal3.con"]
-let compute_exactly ~(dbh:Dbi.connection) main prefixes =
+let compute_exactly ~(dbh:Dbi.connection) where main prefixes =
List.concat
(List.map
(fun (m,s) ->
List.concat
(List.map
(fun (m,s) ->
myspeciallist
else
let res =
myspeciallist
else
let res =
- at_least ~dbh ~concl_card:(Eq (m+1)) (must_of_prefix main s)
+ let must = must_of_prefix ~where main s in
+ match where with
+ | `Conclusion -> at_least ~dbh ~concl_card:(Eq (m+1)) must
+ | `Statement -> at_least ~dbh ~full_card:(Eq (m+1)) must
in
List.map (fun uri -> (m, uri)) res)
prefixes)
(* critical value reached, fallback to "only" constraints *)
in
List.map (fun uri -> (m, uri)) res)
prefixes)
(* critical value reached, fallback to "only" constraints *)
-let compute_with_only ~(dbh:Dbi.connection) main prefixes constants =
+let compute_with_only ~(dbh:Dbi.connection) ?(where = `Conclusion) main
+ prefixes constants
+=
let max_prefix_length =
match prefixes with
| [] -> assert false
let max_prefix_length =
match prefixes with
| [] -> assert false
union
(List.map
(fun (m,s) ->
union
(List.map
(fun (m,s) ->
+ let must = must_of_prefix ~where main s in
- at_least ~dbh ~concl_card:(Gt (m+1)) (must_of_prefix main s)
+ match where with
+ | `Conclusion -> at_least ~dbh ~concl_card:(Gt (m+1)) must
+ | `Statement -> at_least ~dbh ~full_card:(Gt (m+1)) must
in
(* we tag the uri with m+1, for sorting purposes *)
List.map (fun uri -> (m+1, uri)) res))
maximal_prefixes)
in
in
(* we tag the uri with m+1, for sorting purposes *)
List.map (fun uri -> (m+1, uri)) res))
maximal_prefixes)
in
- List.filter (function (_,uri) -> test_only ~dbh constants uri) all in
- let equal_to = compute_exactly ~dbh main prefixes in
+ List.filter (function (_,uri) -> at_most ~dbh ~where constants uri) all in
+ let equal_to = compute_exactly ~dbh where main prefixes in
greater_than @ equal_to
(* real match query implementation *)
greater_than @ equal_to
(* real match query implementation *)
in
compute_with_only ~dbh main all_concl all_constants
| _, _ -> [])
in
compute_with_only ~dbh main all_concl all_constants
| _, _ -> [])
- else if constants_no = 0 then []
else
(* in this case we compute all prefixes, and we do not need
to apply the only constraints *)
else
(* in this case we compute all prefixes, and we do not need
to apply the only constraints *)
- let prefixes = prefixes constants_no t in
+ let prefixes =
+ if constants_no = 0 then
+ Some main, [0, []; List.length types, types]
+ else
+ prefixes constants_no t
+ in
- Some main, all_concl ->
- List.concat
- (List.map
- (fun (m,s) ->
- (let res =
- at_least ~dbh ~concl_card:(Eq (m+1))
- (must_of_prefix main s)
- in
- List.map (fun uri -> (m, uri)) res))
- all_concl)
- | _, _ -> [])
+ Some main, all_concl ->
+ List.concat
+ (List.map
+ (fun (m,s) ->
+ let must = must_of_prefix ~where:`Conclusion main s in
+ let res = at_least ~dbh ~concl_card:(Eq (m+1)) must in
+ List.map (fun uri -> (m, uri)) res)
+ all_concl)
+ | _, _ -> [])
let power_upto upto consts =
let l = StringSet.elements consts in
let power_upto upto consts =
let l = StringSet.elements consts in
(fun res a -> res@(List.map (function (n,l) -> (n+1,a::l)) res))
[(0,[])] l)
(fun res a -> res@(List.map (function (n,l) -> (n+1,a::l)) res))
[(0,[])] l)
-let sigmatch ~(dbh:Dbi.connection) (main, constants) =
+type where = [ `Conclusion | `Statement ]
+
+let sigmatch ~(dbh:Dbi.connection) ?(where = `Conclusion) (main, constants) =
match main with
None -> []
| Some (main, types) ->
match main with
None -> []
| Some (main, types) ->
let all_constants =
List.fold_right StringSet.add types (StringSet.add main constants)
in
let all_constants =
List.fold_right StringSet.add types (StringSet.add main constants)
in
- compute_with_only ~dbh main subsets all_constants
+ compute_with_only ~dbh ~where main subsets all_constants
else
let subsets =
let subsets = power constants in
let types_no = List.length types in
else
let subsets =
let subsets = power constants in
let types_no = List.length types in
- List.map (function (n,l) -> (n+types_no,types@l)) subsets
+ (0,[]) :: List.map (function (n,l) -> (n+types_no,types@l)) subsets
- compute_exactly ~dbh main subsets
+ compute_exactly ~dbh where main subsets
(* match query wrappers *)
let cmatch' = cmatch
(* match query wrappers *)
let cmatch' = cmatch
* relevance information: higher the tag, higher the relevance *)
val cmatch': dbh:Dbi.connection -> Cic.term -> (int * string) list
* relevance information: higher the tag, higher the relevance *)
val cmatch': dbh:Dbi.connection -> Cic.term -> (int * string) list
-val sigmatch: dbh:Dbi.connection -> term_signature -> (int * string) list
+type where = [ `Conclusion | `Statement ] (** signature matching extent *)
+
+ (** @param where defaults to `Conclusion *)
+val sigmatch:
+ dbh:Dbi.connection ->
+ ?where:where -> term_signature ->
+ (int * string) list
(** {2 Constraint engine} *)
(** {2 Constraint engine} *)
MetadataTypes.constr list ->
string list
MetadataTypes.constr list ->
string list
+ (** @param where defaults to `Conclusion *)
+val at_most:
+ dbh:Dbi.connection ->
+ ?where:where -> StringSet.t ->
+ (string -> bool)
+
val signature_of: Cic.term -> term_signature
val constants_of: Cic.term -> StringSet.t
val signature_of: Cic.term -> term_signature
val constants_of: Cic.term -> StringSet.t
-module DB = Dbi_mysql
-
-(* let baseuri = "http://www.cs.unibo.it/helm/schemas/schema-helm#" *)
-let baseuri = ""
-let inconcl_uri = baseuri ^ "InConclusion"
-let mainconcl_uri = baseuri ^ "MainConclusion"
-let mainhyp_uri = baseuri ^ "MainHypothesis"
-let inhyp_uri = baseuri ^ "InHypothesis"
-let inbody_uri = baseuri ^ "InBody"
-
let prepare_insert (dbh: Dbi.connection) =
let insert_owner =
dbh#prepare (sprintf "INSERT INTO %s VALUES (\"?\",\"?\")" owners_tbl)
let prepare_insert (dbh: Dbi.connection) =
let insert_owner =
dbh#prepare (sprintf "INSERT INTO %s VALUES (\"?\",\"?\")" owners_tbl)
let insert_const_no dbh uri =
let inconcl_no =
sprintf "INSERT INTO %s SELECT \"%s\", COUNT(DISTINCT h_occurrence) FROM %s WHERE (h_position=\"%s\" OR h_position=\"%s\") AND source LIKE \"%s%%\""
let insert_const_no dbh uri =
let inconcl_no =
sprintf "INSERT INTO %s SELECT \"%s\", COUNT(DISTINCT h_occurrence) FROM %s WHERE (h_position=\"%s\" OR h_position=\"%s\") AND source LIKE \"%s%%\""
- conclno_tbl uri obj_tbl inconcl_uri mainconcl_uri uri
+ conclno_tbl uri obj_tbl inconcl_pos mainconcl_pos uri
in
let concl_hyp =
sprintf "INSERT INTO %s
SELECT \"%s\",COUNT(DISTINCT h_occurrence)
FROM %s
WHERE NOT (h_position=\"%s\") AND (source = \"%s\")"
in
let concl_hyp =
sprintf "INSERT INTO %s
SELECT \"%s\",COUNT(DISTINCT h_occurrence)
FROM %s
WHERE NOT (h_position=\"%s\") AND (source = \"%s\")"
- conclno_hyp_tbl uri obj_tbl inbody_uri uri
+ conclno_hyp_tbl uri obj_tbl inbody_pos uri
in
(dbh#prepare inconcl_no)#execute [];
(dbh#prepare concl_hyp)#execute []
in
(dbh#prepare inconcl_no)#execute [];
(dbh#prepare concl_hyp)#execute []
let pp_position = function
| `MainConclusion (Some d) -> sprintf "MainConclusion(%d)" d
| `MainConclusion None -> sprintf "MainConclusion"
let pp_position = function
| `MainConclusion (Some d) -> sprintf "MainConclusion(%d)" d
| `MainConclusion None -> sprintf "MainConclusion"
| `InBody -> "InBody"
let pp_position_tag = function
| `InBody -> "InBody"
let pp_position_tag = function
- | `MainConclusion _ -> "MainConclusion"
- | `MainHypothesis _ -> "MainHypothesis"
- | `InConclusion -> "InConclusion"
- | `InHypothesis -> "InHypothesis"
- | `InBody -> "InBody"
+ | `MainConclusion _ -> mainconcl_pos
+ | `MainHypothesis _ -> mainhyp_pos
+ | `InConclusion -> inconcl_pos
+ | `InHypothesis -> inhyp_pos
+ | `InBody -> inbody_pos
let columns_of_position = function
let columns_of_position = function
- | `MainConclusion (Some d) -> `String "MainConclusion", `Int d
- | `MainConclusion None -> `String "MainConclusion", `Null
- | `MainHypothesis (Some d) -> `String "MainHypothesis", `Int d
- | `MainHypothesis None -> `String "MainHypothesis", `Null
- | `InConclusion -> `String "InConclusion", `Null
- | `InHypothesis -> `String "InHypothesis", `Null
- | `InBody -> `String "InBody", `Null
+ | `MainConclusion (Some d) -> `String mainconcl_pos, `Int d
+ | `MainConclusion None -> `String mainconcl_pos, `Null
+ | `MainHypothesis (Some d) -> `String mainhyp_pos, `Int d
+ | `MainHypothesis None -> `String mainhyp_pos, `Null
+ | `InConclusion -> `String inconcl_pos, `Null
+ | `InHypothesis -> `String inhyp_pos, `Null
+ | `InBody -> `String inbody_pos, `Null
(*
let metadata_ns = "http://www.cs.unibo.it/helm/schemas/schema-helm"
(*
let metadata_ns = "http://www.cs.unibo.it/helm/schemas/schema-helm"
* http://helm.cs.unibo.it/
*)
* http://helm.cs.unibo.it/
*)
+let position_prefix = "http://www.cs.unibo.it/helm/schemas/schema-helm#"
+(* let position_prefix = "" *)
+
+let inconcl_pos = position_prefix ^ "InConclusion"
+let mainconcl_pos = position_prefix ^ "MainConclusion"
+let mainhyp_pos = position_prefix ^ "MainHypothesis"
+let inhyp_pos = position_prefix ^ "InHypothesis"
+let inbody_pos = position_prefix ^ "InBody"
+
type main_position =
[ `MainConclusion of int option (* Pi depth *)
| `MainHypothesis of int option (* Pi depth *)
type main_position =
[ `MainConclusion of int option (* Pi depth *)
| `MainHypothesis of int option (* Pi depth *)