]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/metadata/metadataDb.ml
version 0.7.1
[helm.git] / helm / ocaml / metadata / metadataDb.ml
index a4e6008a8a0ff22e6ebe526e4845d490657bee5b..51b432a4f5b843545a1e79eb6adf370d54cd956b 100644 (file)
@@ -72,7 +72,33 @@ let execute_insert dbd uri (sort_cols, rel_cols, obj_cols) =
     ignore (Mysql.exec dbd query_obj)
     end
   
+    
+let count_distinct position l =
+  MetadataConstraints.UriManagerSet.cardinal
+  (List.fold_left (fun acc d -> 
+    match position with
+    | `Conclusion -> 
+         (match d with
+         | `Obj (name,`InConclusion) 
+         | `Obj (name,`MainConclusion _ ) -> 
+             MetadataConstraints.UriManagerSet.add name acc
+         | _ -> acc)
+    | `Hypothesis ->
+        (match d with
+        | `Obj (name,`InHypothesis) 
+        | `Obj (name,`MainHypothesis _) -> 
+            MetadataConstraints.UriManagerSet.add name acc
+        | _ -> acc)
+    | `Statement ->
+        (match d with
+        | `Obj (name,`InBody) -> acc
+        | `Obj (name,_) -> MetadataConstraints.UriManagerSet.add name acc
+        | _ -> acc)
+    ) MetadataConstraints.UriManagerSet.empty l)
+(*    
 let insert_const_no dbd uri =
+  let term = CicUtil.term_of_uri uri in 
+  let ty = CicTypeChecker.type_of_aux' 
   let inconcl_no =
     sprintf "INSERT %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_pos mainconcl_pos uri
@@ -86,10 +112,20 @@ let insert_const_no dbd uri =
   in
   ignore (Mysql.exec dbd inconcl_no);
   ignore (Mysql.exec dbd concl_hyp)
-
+*)
+let insert_const_no dbd (uri,metadata) =
+  let no_concl = count_distinct `Conclusion metadata in
+  let no_hyp = count_distinct `Hypothesis metadata in
+  let no_full = count_distinct `Statement metadata in
+  let insert = 
+    sprintf "INSERT INTO %s VALUES (\"%s\", %d, %d, %d)" 
+      (count_tbl ()) (UriManager.string_of_uri uri) no_concl no_hyp no_full
+  in
+  ignore (Mysql.exec dbd insert)
+  
 let insert_name ~dbd ~uri ~name =
   let query =
-    sprintf "INSERT %s VALUES (\"%s\", \"%s\")" (name_tbl ()) uri name
+    sprintf "INSERT %s VALUES (\"%s\", \"%s\")" (name_tbl ()) (UriManager.string_of_uri uri) name
   in
   ignore (Mysql.exec dbd query)
 
@@ -129,22 +165,21 @@ let index_inductive_def ~dbd =
 let index_obj ~dbd ~uri = 
   if not (already_indexed uri) then begin
     let metadata = MetadataExtractor.compute_obj uri in
-    let uri_of (a,b,c) = a in
-    let uris = UriManager.string_of_uri uri :: List.map uri_of metadata in
+    let uri_of (a,b,c) = (a,c) in
     let uri = UriManager.string_of_uri uri in
     let columns = MetadataPp.columns_of_metadata metadata in
     execute_insert dbd uri (columns :> columns);
-    List.iter (insert_const_no dbd) uris;
+    List.iter (insert_const_no dbd) (List.map uri_of metadata);
     List.iter (fun (uri, name, _) -> insert_name ~dbd ~uri ~name) metadata
   end
   
 
 let tables_to_clean =
-  [sort_tbl; rel_tbl; obj_tbl; conclno_tbl; fullno_tbl; name_tbl; hypno_tbl]
+  [sort_tbl; rel_tbl; obj_tbl; name_tbl; count_tbl]
 
 let clean ~(dbd:Mysql.dbd) =
   let owned_uris =  (* list of uris in list-of-columns format *)
-    let query = sprintf "SELECT source FROM %s" (obj_tbl ()) in
+    let query = sprintf "SELECT source FROM %s" (name_tbl ()) in
     let result = Mysql.exec dbd query in
     let uris = Mysql.map result (fun cols ->
       match cols.(0) with