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) not null,
36 h_occurrence varchar(255) not null,
37 h_position varchar(62) not null,
41 let sprintf_refSort_format name = [
42 sprintf "CREATE TABLE %s (
43 source varchar(255) not null,
44 h_position varchar(62) not null,
45 h_depth integer not null,
46 h_sort varchar(5) not null
49 let sprintf_refRel_format name = [
50 sprintf "CREATE TABLE %s (
51 source varchar(255) not null,
52 h_position varchar(62) not null,
53 h_depth integer not null
56 let sprintf_objectName_format name = [
57 sprintf "CREATE TABLE %s (
58 source varchar(255) not null,
59 value varchar(255) not null
62 let sprintf_hits_format name = [
63 sprintf "CREATE TABLE %s (
64 source varchar(255) not null,
68 let sprintf_count_format name = [
69 sprintf "CREATE TABLE %s (
70 source varchar(255) 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,h_occurrence,h_position);" name name;
92 (*sprintf "CREATE INDEX %s_index ON %s (source(219),h_occurrence(219),h_position);" name name;*)
93 sprintf "CREATE INDEX %s_occurrence ON %s (h_occurrence);" name name ]
95 let sprintf_refSort_index name = [
96 sprintf "CREATE INDEX %s_index ON %s (source,h_sort,h_position,h_depth);" name name]
98 let sprintf_objectName_index name = [
99 sprintf "CREATE INDEX %s_value ON %s (value);" name name]
101 let sprintf_hits_index name = [
102 sprintf "CREATE INDEX %s_source ON %s (source);" name name ;
103 sprintf "CREATE INDEX %s_no ON %s (no);" name name]
105 let sprintf_count_index name = [
106 sprintf "CREATE INDEX %s_conclusion ON %s (conclusion);" name name;
107 sprintf "CREATE INDEX %s_hypothesis ON %s (hypothesis);" name name;
108 sprintf "CREATE INDEX %s_statement ON %s (statement);" name name]
110 let sprintf_refRel_index name = [
111 sprintf "CREATE INDEX %s_index ON %s (source,h_position,h_depth);" name name]
113 let format_drop name sufix =
115 (sprintf "DROP INDEX %s_%s ON %s;" name sufix name)
117 (sprintf "DROP INDEX %s_%s;" name sufix);;
119 let sprintf_refObj_index_drop name = [(format_drop name "index")]
121 let sprintf_refSort_index_drop name = [(format_drop name "index")]
123 let sprintf_objectName_index_drop name = [(format_drop name "value")]
125 let sprintf_hits_index_drop name = [
126 (format_drop name "source");
127 (format_drop name "no")]
129 let sprintf_count_index_drop name = [
130 (format_drop name "source");
131 (format_drop name "conclusion");
132 (format_drop name "hypothesis");
133 (format_drop name "statement")]
135 let sprintf_refRel_index_drop name = [(format_drop name "index")]
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;"
204 let move_content (name1, tbl1) (name2, tbl2) buri =
205 assert (tbl1 = tbl2);
207 "INSERT INTRO %s SELECT * FROM %s WHERE source LIKE \"%s%%\";"
208 name2 name1 (HSql.escape buri)
210 let direct_deps refObj uri =
211 sprintf "SELECT * FROM %s WHERE source = \"%s\";"
212 (HSql.escape refObj) (UriManager.string_of_uri uri)
214 let inverse_deps refObj uri =
215 sprintf "SELECT * FROM %s WHERE h_occurrence = \"%s\";"
216 (HSql.escape refObj) (UriManager.string_of_uri uri)