1 (* Copyright (C) 2004-2005, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
29 type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Hits| `Count]
33 let sprintf_refObj_format name = [
34 sprintf "CREATE TABLE %s (
35 source varchar(255) binary not null,
36 h_occurrence varchar(255) binary not null,
37 h_position varchar(62) binary not null,
41 let sprintf_refSort_format name = [
42 sprintf "CREATE TABLE %s (
43 source varchar(255) binary not null,
44 h_position varchar(62) binary not null,
45 h_depth integer not null,
46 h_sort varchar(5) binary not null
49 let sprintf_refRel_format name = [
50 sprintf "CREATE TABLE %s (
51 source varchar(255) binary not null,
52 h_position varchar(62) binary not null,
53 h_depth integer not null
56 let sprintf_objectName_format name = [
57 sprintf "CREATE TABLE %s (
58 source varchar(255) binary not null,
59 value varchar(255) binary not null
62 let sprintf_hits_format name = [
63 sprintf "CREATE TABLE %s (
64 source varchar(255) binary not null,
68 let sprintf_count_format name = [
69 sprintf "CREATE TABLE %s (
70 source varchar(255) binary unique not null,
71 conclusion smallint(6) not null,
72 hypothesis smallint(6) not null,
73 statement smallint(6) not null
76 let sprintf_refObj_drop name = [sprintf "DROP TABLE %s;" name]
78 let sprintf_refSort_drop name = [sprintf "DROP TABLE %s;" name]
80 let sprintf_refRel_drop name = [sprintf "DROP TABLE %s;" name]
82 let sprintf_objectName_drop name = [sprintf "DROP TABLE %s;" name]
84 let sprintf_hits_drop name = [sprintf "DROP TABLE %s;" name]
86 let sprintf_count_drop name = [sprintf "DROP TABLE %s;" name]
90 let sprintf_refObj_index name = [
91 sprintf "CREATE INDEX %s_index ON %s (source(219),h_occurrence(219),h_position);" name name;
92 sprintf "CREATE INDEX %s_occurrence ON %s (h_occurrence);" name name ]
94 let sprintf_refSort_index name = [
95 sprintf "CREATE INDEX %s_index ON %s (source,h_sort,h_position,h_depth);" name name]
97 let sprintf_objectName_index name = [
98 sprintf "CREATE INDEX %s_value ON %s (value);" name name]
100 let sprintf_hits_index name = [
101 sprintf "CREATE INDEX %s_source ON %s (source);" name name ;
102 sprintf "CREATE INDEX %s_no ON %s (no);" name name]
104 let sprintf_count_index name = [
105 sprintf "CREATE INDEX %s_conclusion ON %s (conclusion);" name name;
106 sprintf "CREATE INDEX %s_hypothesis ON %s (hypothesis);" name name;
107 sprintf "CREATE INDEX %s_statement ON %s (statement);" name name]
109 let sprintf_refRel_index name = [
110 sprintf "CREATE INDEX %s_index ON %s (source,h_position,h_depth);" name name]
112 let sprintf_refObj_index_drop name = [
113 sprintf "DROP INDEX %s_index ON %s;" name name ]
115 let sprintf_refSort_index_drop name = [
116 sprintf "DROP INDEX %s_index ON %s;" name name ]
118 let sprintf_objectName_index_drop name = [
119 sprintf "DROP INDEX %s_value ON %s;" name name]
121 let sprintf_hits_index_drop name = [
122 sprintf "DROP INDEX %s_source ON %s;" name name ;
123 sprintf "DROP INDEX %s_no ON %s;" name name]
125 let sprintf_count_index_drop name = [
126 sprintf "DROP INDEX %s_source ON %s;" name name;
127 sprintf "DROP INDEX %s_conclusion ON %s;" name name;
128 sprintf "DROP INDEX %s_hypothesis ON %s;" name name;
129 sprintf "DROP INDEX %s_statement ON %s;" name name]
131 let sprintf_refRel_index_drop name = [
132 sprintf "DROP INDEX %s_index ON %s;" name name]
134 let sprintf_rename_table oldname newname = [
135 sprintf "RENAME TABLE %s TO %s;" oldname newname
141 let get_table_format t named =
143 | `RefObj -> sprintf_refObj_format named
144 | `RefSort -> sprintf_refSort_format named
145 | `RefRel -> sprintf_refRel_format named
146 | `ObjectName -> sprintf_objectName_format named
147 | `Hits -> sprintf_hits_format named
148 | `Count -> sprintf_count_format named
150 let get_index_format t named =
152 | `RefObj -> sprintf_refObj_index named
153 | `RefSort -> sprintf_refSort_index named
154 | `RefRel -> sprintf_refRel_index named
155 | `ObjectName -> sprintf_objectName_index named
156 | `Hits -> sprintf_hits_index named
157 | `Count -> sprintf_count_index named
159 let get_table_drop t named =
161 | `RefObj -> sprintf_refObj_drop named
162 | `RefSort -> sprintf_refSort_drop named
163 | `RefRel -> sprintf_refRel_drop named
164 | `ObjectName -> sprintf_objectName_drop named
165 | `Hits -> sprintf_hits_drop named
166 | `Count -> sprintf_count_drop named
168 let get_index_drop t named =
170 | `RefObj -> sprintf_refObj_index_drop named
171 | `RefSort -> sprintf_refSort_index_drop named
172 | `RefRel -> sprintf_refRel_index_drop named
173 | `ObjectName -> sprintf_objectName_index_drop named
174 | `Hits -> sprintf_hits_index_drop named
175 | `Count -> sprintf_count_index_drop named
177 let create_tables l =
178 List.fold_left (fun s (name,table) -> s @ get_table_format table name) [] l
180 let create_indexes l =
181 List.fold_left (fun s (name,table) -> s @ get_index_format table name) [] l
184 List.fold_left (fun s (name,table) -> s @ get_table_drop table name) [] l
187 List.fold_left (fun s (name,table) -> s @ get_index_drop table name) [] l
189 let rename_tables l =
190 List.fold_left (fun s (o,n) -> s @ sprintf_rename_table o n) [] l
192 let fill_hits refObj hits =
195 SELECT h_occurrence, COUNT(source)
197 GROUP BY h_occurrence;"