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/
27 type tbl = [ `RefObj| `RefSort| `RefRel| `ObjectName| `Hits| `Count]
31 let sprintf_refObj_format name = [
32 sprintf "CREATE TABLE %s (
33 source varchar(255) binary not null,
34 h_occurrence varchar(255) binary not null,
35 h_position varchar(255) binary not null,
39 let sprintf_refSort_format name = [
40 sprintf "CREATE TABLE %s (
41 source varchar(255) binary not null,
42 h_position varchar(255) binary not null,
43 h_depth integer not null,
44 h_sort varchar(255) binary not null
47 let sprintf_refRel_format name = [
48 sprintf "CREATE TABLE %s (
49 source varchar(255) binary not null,
50 h_position varchar(255) binary not null,
51 h_depth integer not null
54 let sprintf_objectName_format name = [
55 sprintf "CREATE TABLE %s (
56 source varchar(255) binary not null,
57 value varchar(255) binary not null
60 let sprintf_hits_format name = [
61 sprintf "CREATE TABLE %s (
62 source varchar(255) binary not null,
66 let sprintf_count_format name = [
67 sprintf "CREATE TABLE %s (
68 source varchar(255) binary unique not null,
69 conclusion smallint(6) not null,
70 hypothesis smallint(6) not null,
71 statement smallint(6) not null
74 let sprintf_refObj_drop name = [sprintf "DROP TABLE %s;" name]
76 let sprintf_refSort_drop name = [sprintf "DROP TABLE %s;" name]
78 let sprintf_refRel_drop name = [sprintf "DROP TABLE %s;" name]
80 let sprintf_objectName_drop name = [sprintf "DROP TABLE %s;" name]
82 let sprintf_hits_drop name = [sprintf "DROP TABLE %s;" name]
84 let sprintf_count_drop name = [sprintf "DROP TABLE %s;" name]
88 let sprintf_refObj_index name = [
89 sprintf "CREATE INDEX %s_source ON %s (source);" name name ;
90 sprintf "CREATE INDEX %s_target ON %s (h_occurrence);" name name ;
91 sprintf "CREATE INDEX %s_position ON %s (h_position);" name name ]
93 let sprintf_refSort_index name = [
94 sprintf "CREATE INDEX %s_source ON %s (source);" name name]
96 let sprintf_objectName_index name = [
97 sprintf "CREATE INDEX %s_value ON %s (value);" name name]
99 let sprintf_hits_index name = [
100 sprintf "CREATE INDEX %s_source ON %s (source);" name name ;
101 sprintf "CREATE INDEX %s_no ON %s (no);" name name]
103 let sprintf_count_index name = [
104 sprintf "CREATE INDEX %s_source ON %s (source);" name 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_source ON %s (source);" name name
113 let sprintf_refObj_index_drop name = [
114 sprintf "DROP INDEX %s_source ON %s;" name name ;
115 sprintf "DROP INDEX %s_target ON %s;" name name ;
116 sprintf "DROP INDEX %s_position ON %s;" name name ]
118 let sprintf_refSort_index_drop name = [
119 sprintf "DROP INDEX %s_source ON %s;" name name ]
121 let sprintf_objectName_index_drop name = [
122 sprintf "DROP INDEX %s_value ON %s;" name name]
124 let sprintf_hits_index_drop name = [
125 sprintf "DROP INDEX %s_source ON %s;" name name ;
126 sprintf "DROP INDEX %s_no ON %s;" name name]
128 let sprintf_count_index_drop name = [
129 sprintf "DROP INDEX %s_source ON %s;" name name;
130 sprintf "DROP INDEX %s_conclusion ON %s;" name name;
131 sprintf "DROP INDEX %s_hypothesis ON %s;" name name;
132 sprintf "DROP INDEX %s_statement ON %s;" name name]
134 let sprintf_refRel_index_drop name = [
135 sprintf "DROP INDEX %s_source ON %s;" name name]
137 let sprintf_rename_table oldname newname = [
138 sprintf "RENAME TABLE %s TO %s;" oldname newname
144 let get_table_format t named =
146 | `RefObj -> sprintf_refObj_format named
147 | `RefSort -> sprintf_refSort_format named
148 | `RefRel -> sprintf_refRel_format named
149 | `ObjectName -> sprintf_objectName_format named
150 | `Hits -> sprintf_hits_format named
151 | `Count -> sprintf_count_format named
153 let get_index_format t named =
155 | `RefObj -> sprintf_refObj_index named
156 | `RefSort -> sprintf_refSort_index named
157 | `RefRel -> sprintf_refRel_index named
158 | `ObjectName -> sprintf_objectName_index named
159 | `Hits -> sprintf_hits_index named
160 | `Count -> sprintf_count_index named
162 let get_table_drop t named =
164 | `RefObj -> sprintf_refObj_drop named
165 | `RefSort -> sprintf_refSort_drop named
166 | `RefRel -> sprintf_refRel_drop named
167 | `ObjectName -> sprintf_objectName_drop named
168 | `Hits -> sprintf_hits_drop named
169 | `Count -> sprintf_count_drop named
171 let get_index_drop t named =
173 | `RefObj -> sprintf_refObj_index_drop named
174 | `RefSort -> sprintf_refSort_index_drop named
175 | `RefRel -> sprintf_refRel_index_drop named
176 | `ObjectName -> sprintf_objectName_index_drop named
177 | `Hits -> sprintf_hits_index_drop named
178 | `Count -> sprintf_count_index_drop named
180 let create_tables l =
181 List.fold_left (fun s (name,table) -> s @ get_table_format table name) [] l
183 let create_indexes l =
184 List.fold_left (fun s (name,table) -> s @ get_index_format table name) [] l
187 List.fold_left (fun s (name,table) -> s @ get_table_drop table name) [] l
190 List.fold_left (fun s (name,table) -> s @ get_index_drop table name) [] l
192 let rename_tables l =
193 List.fold_left (fun s (o,n) -> s @ sprintf_rename_table o n) [] l
195 let fill_hits refObj hits =
198 SELECT h_occurrence, COUNT(source)
200 GROUP BY h_occurrence;"