]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/metadata/metadataConstraints.ml
removed no_inconcl_aux, no_concl_hyp, no_hyp and added count
[helm.git] / helm / ocaml / metadata / metadataConstraints.ml
index 3e9cd9c5a37942e6df4a9c1ebb9c9105d2da5187..cbeaad49d5112825ce632f122b4c7cdee1417f42 100644 (file)
@@ -76,34 +76,36 @@ let explode_card_constr = function
   | Gt card -> ">", card
   | Lt card -> "<", card
 
-let add_card_constr tbl (n,from,where) = function
-  | None -> (n,from,where)
+let add_card_constr tbl col where = function
+  | None -> where
   | Some constr ->
-      let cur_tbl = tbln n in
       let op, card = explode_card_constr constr in
-      (n+1,
-       (sprintf "%s as %s" tbl cur_tbl :: from),
-       (sprintf "%s.no %s %d" cur_tbl op card ::
-        (if n=0 then []
-        else [sprintf "table0.source = %s.source" cur_tbl]) @
-        where))
+      (* count(_utente).hypothesis = 3 *)
+      (sprintf "%s.%s %s %d" tbl col op card :: where)
 
-let add_diff_constr conclno_tbl hypno_tbl (n,from,where) = function
-  | None -> (n,from,where)
+let add_diff_constr tbl where = function
+  | None -> where
   | Some constr ->
-      let cur_tbl1, cur_tbl2 = tbln n, tbln (n+1) in
       let op, card = explode_card_constr constr in
-      (n+2,
-       (sprintf "%s as %s" conclno_tbl cur_tbl1 ::
-        sprintf "%s as %s" hypno_tbl cur_tbl2 :: from),
-       (sprintf "%s.no - %s.no %s %d" cur_tbl2 cur_tbl1 op card ::
-        (if n=0 then assert false
-        else [sprintf "table0.source = %s.source" cur_tbl1;
-              sprintf "table0.source = %s.source" cur_tbl2]) @
-        where))
+      (sprintf "%s.hypothesis - %s.conclusion %s %d" tbl tbl op card :: where)
+      
+let add_all_constr tbl (n,from,where) concl full diff =
+  match (concl, full, diff) with
+  | None, None, None -> (n,from,where)
+  | _ -> 
+      let where = add_card_constr tbl "conclusion" where concl in
+      let where = add_card_constr tbl "statement" where full in
+      let where = add_diff_constr tbl where diff in
+      (n,tbl :: from, 
+        (if n > 0 then 
+          sprintf "table0.source = %s.source" tbl :: where 
+        else
+          where))
+      
 
 let add_constraint tables (n,from,where) metadata =
-  let obj_tbl,rel_tbl,sort_tbl,conclno_tbl,fullno_tbl,hypno_tbl = tables in
+  let obj_tbl,rel_tbl,sort_tbl,count_tbl = tables 
+  in
   let cur_tbl = tbln n in
   match metadata with
   | `Obj (uri, positions) ->
@@ -138,34 +140,24 @@ let add_constraint tables (n,from,where) metadata =
       in
       ((n+2), from, where)
 
+
 let at_least ~(dbd:Mysql.dbd) ?concl_card ?full_card ?diff ?rating tables
   (metadata: MetadataTypes.constr list)
 =
-  let obj_tbl,rel_tbl,sort_tbl,conclno_tbl,fullno_tbl,hypno_tbl = tables in
+  let obj_tbl,rel_tbl,sort_tbl, count_tbl = tables 
+  in
   if (metadata = []) && concl_card = None && full_card = None then
     failwith "MetadataQuery.at_least: no constraints given";
   let (n,from,where) =
     List.fold_left (add_constraint tables) (0,[],[]) metadata
   in
   let (n,from,where) =
-    add_card_constr conclno_tbl (n,from,where) concl_card
-  in
-  let (n,from,where) =
-    add_card_constr fullno_tbl (n,from,where) full_card
-  in
-  let (n,from,where) =
-    add_diff_constr conclno_tbl hypno_tbl (n,from,where) diff
+    add_all_constr count_tbl (n,from,where) concl_card full_card diff
   in
   let from = String.concat ", " from in
   let where = String.concat " and " where in
   let query =
     match rating with
-(*
-    sprintf
-      ("select table0.source from %s, %s where %s and %s.source = table0.source"
-      ^^ " order by %s.no")
-      from fullno_tbl where fullno_tbl fullno_tbl
- *)
     | None -> sprintf "select table0.source from %s where %s" from where
     | Some `Hits ->
         sprintf
@@ -173,11 +165,12 @@ let at_least ~(dbd:Mysql.dbd) ?concl_card ?full_card ?diff ?rating tables
            ^^ " and hits.source = table0.source order by hits.no desc")
           from where
   in
-(*   prerr_endline query; *)
+  prerr_endline query; 
   let result = Mysql.exec dbd query in
   Mysql.map result
     (fun row -> match row.(0) with Some s -> s | _ -> assert false)
 
+    
 let at_least  
   ~(dbd:Mysql.dbd) ?concl_card ?full_card ?diff ?rating
       (metadata: MetadataTypes.constr list)
@@ -185,18 +178,17 @@ let at_least
   let module MT = MetadataTypes in
   if MT.are_tables_ownerized () then
     (at_least ~dbd ?concl_card ?full_card ?diff ?rating
-      (MT.obj_tbl (),MT.rel_tbl (),MT.sort_tbl (),
-       MT.conclno_tbl (),MT.fullno_tbl (),MT.hypno_tbl ())
+      (MT.obj_tbl (),MT.rel_tbl (),MT.sort_tbl (), MT.count_tbl ())
         metadata)
         @
     (at_least ~dbd ?concl_card ?full_card ?diff ?rating
       (MT.library_obj_tbl,MT.library_rel_tbl,MT.library_sort_tbl,
-       MT.library_conclno_tbl,MT.library_fullno_tbl,MT.library_hypno_tbl) 
+      MT.library_count_tbl) 
         metadata)
   else
     at_least ~dbd ?concl_card ?full_card ?diff ?rating
       (MT.library_obj_tbl,MT.library_rel_tbl,MT.library_sort_tbl,
-       MT.library_conclno_tbl,MT.library_fullno_tbl,MT.library_hypno_tbl) 
+       MT.library_count_tbl) 
         metadata