-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcomplete.sql
More file actions
302 lines (264 loc) · 6.78 KB
/
Copy pathcomplete.sql
File metadata and controls
302 lines (264 loc) · 6.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
--
-- $Id$
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2021 OpenLink Software
--
-- This project 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; only version 2 of the License, dated June 1991.
--
-- This program 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 this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
-- URI completion
create procedure
rpid64_str (in n int)
{
declare s varchar;
s := '\0\0\0\0\0\0\0\0';
s := long_set (s, 0, bit_or (bit_shift (n, -32), 0hex80000000));
s := long_set (s, 1, bit_and (n, 0hexffffffff));
return s;
}
;
create procedure
str_inc (in str varchar, in pref int := 0)
{
-- increment by one for range cmp
declare len int;
len := length (str);
carry:
if (pref = len)
return subseq (str, 0, pref) || '\377\377\377\377\377\377\377\377';
str [len - 1] := str[len - 1] + 1;
if (str[len - 1] = 0)
{
len := len - 1;
goto carry;
}
return str;
}
;
create procedure
cmp_find_iri (in str varchar, in no_name int := 0)
{
/* We look for iris, assuming the full ns is in the name */
declare pref, name, next, local, ext varchar;
declare rp64 varbinary;
declare id, inx int;
declare iris any;
if (no_name)
{
pref := str;
ext := '';
}
else
{
pref := iri_split (str, local, 1);
ext := subseq (local, 8);
}
id := (select rp_id from rdf_prefix where rp_name = pref);
if (id is null)
return null;
name := concat (rpid64_str (id), ext);
if (no_name)
next := rpid64_str (id + 1);
else
next := str_inc (name, 8);
iris := (select vector_agg (ri_name) from (select top 20 ri_name from rdf_iri where ri_name >= name and ri_name < next) ir);
if (length (iris) < 20 and length (iris) > 1) -- XXX: is next code needed at all?
iris := (select vector_agg (ri_name) from (select ri_name from rdf_iri where ri_name >= name and ri_name < next order by iri_rank (ri_id) desc) ir);
for (inx := 0; inx < length (iris); inx := inx + 1)
{
iris[inx] := concat (pref, subseq (iris[inx], 8));
}
return iris;
}
;
create procedure
cmp_find_ns (in str varchar)
{
declare nss any;
nss := (select vector_agg (rp_name)
from (select top 20 rp_name
from rdf_prefix
where rp_name >= str and
rp_name < str_inc (str)) ns);
return nss;
}
;
create procedure
cmp_with_ns (in str varchar)
{
declare pref_str varchar;
declare col int;
col := position (':', str);
if (col = 0)
return null;
pref_str := (select ns_url
from SYS_XML_PERSISTENT_NS_DECL
where ns_prefix = subseq (str, 0, col - 1));
if (pref_str is null)
return null;
str := pref_str || subseq (str, col);
return str;
}
;
create procedure
cmp_uri (in str varchar)
{
declare with_ns varchar;
declare nss, iris, exact_iri any;
-- dbg_printf ('cmp_uri\n');
if (strstr (str, '://') is null)
{
with_ns := cmp_with_ns (str);
if (with_ns is not null)
return cmp_find_iri (with_ns);
-- no protocol and no known prefix
if (strstr (str, ':') is null)
str := 'http://' || str;
}
nss := cmp_find_ns (str);
-- dbg_obj_print ('ns with ', str, ' = ', nss);
exact_iri := cmp_find_iri (str);
vectorbld_init (iris);
foreach (any x in exact_iri) do
{
vectorbld_concat_acc (iris, vector (x));
}
foreach (any x in nss) do
{
vectorbld_concat_acc (iris, cmp_find_iri (x, 1));
}
vectorbld_final (iris);
return iris;
}
;
create procedure
urilbl_ac_ruin_label (in lbl varchar)
{
declare tmp any;
tmp := regexp_replace (lbl, '[''",.]', '', 1, null);
if (not iswidestring (tmp))
tmp := charset_recode (tmp, 'UTF-8', '_WIDE_');
tmp := upper (tmp);
tmp := subseq (tmp, 0, 50);
return charset_recode (tmp, '_WIDE_', 'UTF-8');
}
;
create procedure
urilbl_ac_init_log (in msg varchar)
{
-- dbg_printf(msg);
insert into urilbl_cpl_log (ullog_msg) values (msg);
}
;
create procedure
urilbl_ac_init_state(in info integer := 1)
{
declare sts integer;
declare msg varchar;
sts := cast (registry_get ('urilbl_ac_init_status') as integer);
msg := case sts
when 0 then 'Entity Lookup table has not been generated.'
when 1 then 'Entity Lookup table (re)generation in progress.'
when 2 then 'Entity Lookup table has been successfully generated.'
when 4711 then 'Entity Lookup table generation failed.'
else sprintf('Entity Lookup table in unknown state: %d', sts)
end;
if (info = 1) {
if (sts = 2) return;
http (sprintf ('
<div class="ac_info">
<a href="urilbl_status.vsp"><img class="txt_i" alt="info" src="/fct/images/info.png"/></a>
<span class="ac_info">%V Contact the site administrator.</span>
</div>
', msg));
} else {
http(sprintf (' <p>%V</p', msg));
}
}
;
create procedure
cmp_fill_lang_by_q (in accept varchar)
{
declare itm varchar;
declare arr, vec any;
declare q float;
declare i, l int;
vec := vector ();
arr := split_and_decode (accept, 0, '\0\0,;');
q := 0;
l := length (arr);
for (i := 0; i < l; i := i + 2)
{
declare tmp any;
itm := trim(arr[i]);
q := arr[i+1];
if (q is null)
q := 1.0;
else
{
tmp := split_and_decode (q, 0, '\0\0=');
if (length (tmp) = 2)
q := atof (tmp[1]);
else
q := 1.0;
}
vec := vector_concat (vec, vector (itm, q));
}
if (not position ('en', vec))
vec := vector_concat (vec, vector ('en', 0.002));
return vec;
}
;
-- Originally from rdf_mappers/rdfdesc.sql
-- Determine q of given lang based on value of Accept-Language hdr
create procedure
cmp_get_lang_by_q (in accept varchar, in lang varchar)
{
declare format, itm, q varchar;
declare arr any;
declare i, l int;
arr := split_and_decode (accept, 0, '\0\0,;');
q := 0;
l := length (arr);
format := null;
for (i := 0; i < l; i := i + 2)
{
declare tmp any;
itm := trim(arr[i]);
if (itm = lang)
{
q := arr[i+1];
if (q is null)
q := 1.0;
else
{
tmp := split_and_decode (q, 0, '\0\0=');
if (length (tmp) = 2)
q := atof (tmp[1]);
else
q := 1.0;
}
goto ret;
}
}
ret:
if (q = 0 and lang = 'en')
q := 0.002;
if (q = 0 and not length (lang))
q := 0.001;
return q;
}
;