From 58dc98ecc3943c9945dee039fe03e1344cc60e4f Mon Sep 17 00:00:00 2001 From: Stefano Zacchiroli Date: Fri, 13 May 2005 13:01:25 +0000 Subject: [PATCH] added support for hits table --- helm/ocaml/metadata/metadataTypes.ml | 2 + helm/ocaml/metadata/metadataTypes.mli | 1 + helm/ocaml/metadata/sqlStatements.ml | 61 +++++++++++++++++++++------ helm/ocaml/metadata/sqlStatements.mli | 43 ++++++++++++++++--- 4 files changed, 88 insertions(+), 19 deletions(-) diff --git a/helm/ocaml/metadata/metadataTypes.ml b/helm/ocaml/metadata/metadataTypes.ml index 51f79c828..5284d96b5 100644 --- a/helm/ocaml/metadata/metadataTypes.ml +++ b/helm/ocaml/metadata/metadataTypes.ml @@ -69,6 +69,7 @@ let rel_tbl_original = "refRel" let obj_tbl_original = "refObj" let name_tbl_original = "objectName" let count_tbl_original = "count" +let hits_tbl_original = "hits" (** the names currently used *) let sort_tbl_real = ref sort_tbl_original @@ -98,6 +99,7 @@ let library_rel_tbl = rel_tbl_original let library_obj_tbl = obj_tbl_original let library_name_tbl = name_tbl_original let library_count_tbl = count_tbl_original +let library_hits_tbl = hits_tbl_original let are_tables_ownerized () = sort_tbl () <> library_sort_tbl diff --git a/helm/ocaml/metadata/metadataTypes.mli b/helm/ocaml/metadata/metadataTypes.mli index d775fc587..73f9a703e 100644 --- a/helm/ocaml/metadata/metadataTypes.mli +++ b/helm/ocaml/metadata/metadataTypes.mli @@ -73,4 +73,5 @@ val library_rel_tbl: string val library_obj_tbl: string val library_name_tbl: string val library_count_tbl: string +val library_hits_tbl: string diff --git a/helm/ocaml/metadata/sqlStatements.ml b/helm/ocaml/metadata/sqlStatements.ml index e02e9128b..35abac28b 100644 --- a/helm/ocaml/metadata/sqlStatements.ml +++ b/helm/ocaml/metadata/sqlStatements.ml @@ -1,6 +1,30 @@ +(* Copyright (C) 2004-2005, HELM Team. + * + * This file is part of HELM, an Hypertextual, Electronic + * Library of Mathematics, developed at the Computer Science + * Department, University of Bologna, Italy. + * + * HELM is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * HELM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HELM; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + * + * For details, see the HELM World-Wide-Web page, + * http://helm.cs.unibo.it/ + *) open Printf;; -type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Owners| `Count] +type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Hits| `Count] (* TABLES *) @@ -33,10 +57,10 @@ sprintf "CREATE TABLE %s ( value varchar(255) binary not null );" name] -let sprintf_owners_format name = [ +let sprintf_hits_format name = [ sprintf "CREATE TABLE %s ( source varchar(255) binary not null, - owner varchar(255) binary not null + no integer not null );" name] let sprintf_count_format name = [ @@ -55,7 +79,7 @@ let sprintf_refRel_drop name = [sprintf "DROP TABLE %s;" name] let sprintf_objectName_drop name = [sprintf "DROP TABLE %s;" name] -let sprintf_owners_drop name = [sprintf "DROP TABLE %s;" name] +let sprintf_hits_drop name = [sprintf "DROP TABLE %s;" name] let sprintf_count_drop name = [sprintf "DROP TABLE %s;" name] @@ -72,9 +96,9 @@ sprintf "CREATE INDEX %s_source ON %s (source);" name name] let sprintf_objectName_index name = [ sprintf "CREATE INDEX %s_value ON %s (value);" name name] -let sprintf_owners_index name = [ -sprintf "CREATE INDEX %s_owner ON %s (owner);" name name ; -sprintf "CREATE INDEX %s_source ON %s (source);" name name] +let sprintf_hits_index name = [ +sprintf "CREATE INDEX %s_source ON %s (source);" name name ; +sprintf "CREATE INDEX %s_no ON %s (no);" name name] let sprintf_count_index name = [ sprintf "CREATE INDEX %s_source ON %s (source);" name name; @@ -97,9 +121,9 @@ sprintf "DROP INDEX %s_source ON %s;" name name ] let sprintf_objectName_index_drop name = [ sprintf "DROP INDEX %s_value ON %s;" name name] -let sprintf_owners_index_drop name = [ -sprintf "DROP INDEX %s_owner ON %s;" name name ; -sprintf "DROP INDEX %s_source ON %s;" name name] +let sprintf_hits_index_drop name = [ +sprintf "DROP INDEX %s_source ON %s;" name name ; +sprintf "DROP INDEX %s_no ON %s;" name name] let sprintf_count_index_drop name = [ sprintf "DROP INDEX %s_source ON %s;" name name; @@ -123,7 +147,7 @@ let get_table_format t named = | `RefSort -> sprintf_refSort_format named | `RefRel -> sprintf_refRel_format named | `ObjectName -> sprintf_objectName_format named - | `Owners -> sprintf_owners_format named + | `Hits -> sprintf_hits_format named | `Count -> sprintf_count_format named let get_index_format t named = @@ -132,7 +156,7 @@ let get_index_format t named = | `RefSort -> sprintf_refSort_index named | `RefRel -> sprintf_refRel_index named | `ObjectName -> sprintf_objectName_index named - | `Owners -> sprintf_owners_index named + | `Hits -> sprintf_hits_index named | `Count -> sprintf_count_index named let get_table_drop t named = @@ -141,7 +165,7 @@ let get_table_drop t named = | `RefSort -> sprintf_refSort_drop named | `RefRel -> sprintf_refRel_drop named | `ObjectName -> sprintf_objectName_drop named - | `Owners -> sprintf_owners_drop named + | `Hits -> sprintf_hits_drop named | `Count -> sprintf_count_drop named let get_index_drop t named = @@ -150,7 +174,7 @@ let get_index_drop t named = | `RefSort -> sprintf_refSort_index_drop named | `RefRel -> sprintf_refRel_index_drop named | `ObjectName -> sprintf_objectName_index_drop named - | `Owners -> sprintf_owners_index_drop named + | `Hits -> sprintf_hits_index_drop named | `Count -> sprintf_count_index_drop named let create_tables l = @@ -168,3 +192,12 @@ let drop_indexes l = let rename_tables l = List.fold_left (fun s (o,n) -> s @ sprintf_rename_table o n) [] l +let fill_hits refObj hits = + [ sprintf + "INSERT INTO %s + SELECT h_occurrence, COUNT(source) + FROM %s + GROUP BY h_occurrence;" + hits refObj ] + + diff --git a/helm/ocaml/metadata/sqlStatements.mli b/helm/ocaml/metadata/sqlStatements.mli index 18e50e209..9f9af55ef 100644 --- a/helm/ocaml/metadata/sqlStatements.mli +++ b/helm/ocaml/metadata/sqlStatements.mli @@ -1,12 +1,45 @@ +(* Copyright (C) 2004-2005, HELM Team. + * + * This file is part of HELM, an Hypertextual, Electronic + * Library of Mathematics, developed at the Computer Science + * Department, University of Bologna, Italy. + * + * HELM is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * HELM is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with HELM; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + * + * For details, see the HELM World-Wide-Web page, + * http://helm.cs.unibo.it/ + *) -type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Owners| `Count] +(** table shape kinds *) +type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Hits| `Count] + +(** all functions below return either an SQL statement or a list of SQL + * statements. + * For functions taking as argument (string * tbl) list, the meaning is a list + * of pairs ; where the type specify the desired kind of + * table and name the desired name (e.g. create a `RefObj like table name + * refObj_NEW) *) val create_tables: (string * tbl) list -> string list - val create_indexes: (string * tbl) list -> string list - val drop_tables: (string * tbl) list -> string list - val drop_indexes: (string * tbl) list -> string list - val rename_tables: (string * string) list -> string list + +(** @param refObj name of the refObj table + * @param hits name of the hits table *) +val fill_hits: string -> string -> string list + -- 2.39.2