-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathfacet.sql
More file actions
1710 lines (1436 loc) · 48.1 KB
/
Copy pathfacet.sql
File metadata and controls
1710 lines (1436 loc) · 48.1 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
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--
-- $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
--
-- Facet web service
create procedure
fct_dbg_msg (in str varchar, in lvl int := 666)
{
declare d_lvl int;
declare d_mode varchar;
d_lvl := connection_get ('fct_dbg_lvl');
d_mode := connection_get ('fct_dbg_mode');
if (lvl < d_lvl) return;
if (d_lvl)
{
if (d_mode = 'stderr')
{
dbg_printf ('%s', str);
return;
}
if (d_mode = 'page')
{
declare d_out_s any;
d_out_s := connection_get ('__fct_dbg_out');
if (d_out_s)
http (str || '\n', d_out_s);
}
}
}
;
create procedure
fct_render_dbg_out ()
{
declare d_lvl int;
declare d_out varchar;
d_lvl := connection_get ('fct_dbg_lvl');
d_out := connection_get ('fct_dbg_out');
if (not d_lvl) return;
if (not d_out) { dbg_printf ('fct_render_dbg_out: no d_out'); return; }
declare d_ses any;
d_ses := connection_get ('__fct_dbg_out');
if (d_ses)
{
http('<div id="dbg_output"><pre>');
http_value (d_ses);
http('</pre></div>');
}
else
dbg_printf ('fct_render_dbg_out: no string session to write to!');
}
;
create procedure
fct_uri_curie (in uri varchar)
{
declare delim integer;
declare uriSearch, nsPrefix varchar;
delim := -1;
if (uri is null)
return uri;
if (iswidestring (uri))
uri := charset_recode (uri, '_WIDE_', 'UTF-8');
uriSearch := uri;
nsPrefix := null;
while (nsPrefix is null and delim <> 0) {
delim := coalesce (strrchr (uriSearch, '/'), 0);
delim := __max (delim, coalesce (strrchr (uriSearch, '#'), 0));
delim := __max (delim, coalesce (strrchr (uriSearch, ':'), 0));
nsPrefix := coalesce (__xml_get_ns_prefix (subseq (uriSearch, 0, delim + 1), 2),
__xml_get_ns_prefix (subseq (uriSearch, 0, delim), 2));
uriSearch := subseq (uriSearch, 0, delim);
-- dbg_obj_print(uriSearch);
}
if (nsPrefix is not null)
{
declare rhs varchar;
rhs := subseq (uri, length (uriSearch) + 1, null);
if (length (rhs) = 0)
{
return null;
}
else
{
return nsPrefix || ':' || rhs;
}
}
return null;
}
;
create procedure
fct_short_uri (in x any)
{
declare loc, pref, sh varchar;
if (not isstring (x))
return x;
pref := iri_split (x, loc);
if (pref is null)
return x;
sh := __xml_get_ns_prefix (pref, 2);
if (sh is not null)
return sh || ':' || loc;
return x;
}
;
create procedure
fct_trunc_uri (in s varchar, in maxlen int := 40)
{
declare _s, ret varchar;
declare _h int;
_s := trim(s);
if (length(_s) <= maxlen) return _s;
_h := floor (maxlen / 2);
ret := sprintf ('%s...%s', "LEFT"(_s, _h), "RIGHT"(_s, _h-1));
return ret;
}
;
create procedure
fct_short_form (in x any, in ltgt int := 0)
{
declare loc, pref, sh0, sh1 varchar;
declare ret nvarchar;
if (iswidestring (x))
x := charset_recode (x, '_WIDE_', 'UTF-8');
if (not isstring (x))
return null;
sh0 := fct_uri_curie(x);
if (x like 'NodeID%')
return 'Blank' || x;
if (sh0 is not null)
sh1 := fct_trunc_uri(sh0);
else
sh1 := (case when ltgt then '<' || fct_trunc_uri (x) || '>' else fct_trunc_uri (x) end);
ret := charset_recode (sh1, 'UTF-8', '_WIDE_');
if (not iswidestring (ret))
{
if (sh0 is not null)
ret := charset_recode (sh0, 'UTF-8', '_WIDE_');
else
{
sh1 := (case when ltgt then '<' || x || '>' else x end);
ret := charset_recode (sh1, 'UTF-8', '_WIDE_');
}
}
return ret;
}
;
create procedure
fct_long_uri (in x any)
{
declare loc, pref, sh varchar;
if (not isstring (x))
return x;
pref := iri_split (x, loc);
if ('' = pref or ':' <> subseq (pref, length (pref) - 1))
return x;
sh := __xml_get_ns_uri (subseq (pref, 0, length (pref) - 1), 2);
if (sh is not null)
x := sh || loc;
return x;
}
;
cl_exec ('registry_set (''fct_label_iri'', ?)',
vector (cast (iri_id_num (__i2id ('http://www.openlinksw.com/schemas/virtrdf#label')) as varchar)));
create procedure
FCT_LABEL (in x any, in g_id iri_id_8, in ctx varchar)
{
declare best_str any;
declare best_l, l int;
declare label_iri iri_id_8;
if (not isiri_id (x))
return null;
if (__proc_exists ('rdf_resolve_labels_s') is not null)
{
declare ret any;
ret := rdf_resolve_labels_s (adler32 ('en'), vector (x));
ret := coalesce (ret[0], '');
return __ro2sq (ret);
}
rdf_check_init ();
label_iri := iri_id_from_num (atoi (registry_get ('fct_label_iri')));
best_str := null;
best_l := 0;
for select o, p
from rdf_quad table option (index primary key)
where s = x and p in (rdf_super_sub_list (ctx, label_iri, 3)) do
{
if (is_rdf_box (o) or isstring (o))
{
if (is_rdf_box (o) and not rdf_box_is_complete (o))
L := 20;
else
l := length (o);
if (l > best_l)
{
best_str := o;
best_l := l;
}
}
}
return __ro2sq(best_str);
}
;
create procedure
FCT_LABEL_DP (in x any, in g_id iri_id_8, in ctx varchar)
{
return FCT_LABEL_DP_L (x, g_id, ctx, null);
}
;
create procedure
FCT_LABEL_DP_L (in x any, in g_id iri_id_8, in ctx varchar, in lng varchar)
{
declare best_str any;
declare best_l, l int;
declare label_iri iri_id_8;
declare q, best_q, str_lang, lng_pref any;
declare lang_vec any;
if (not isiri_id (x))
return vector (null, 1);
rdf_check_init ();
label_iri := iri_id_from_num (atoi (registry_get ('fct_label_iri')));
best_str := null;
best_l := 0;
best_q := 0;
lang_vec := cmp_fill_lang_by_q (lng);
for select o, p
from rdf_quad table option (no cluster, index rdf_quad)
where s = x and p in (rdf_super_sub_list (ctx, label_iri, 3)) do
{
if (is_rdf_box (o))
{
lng_pref := rdf_box_lang (o);
str_lang := (select RL_ID from RDF_LANGUAGE where RL_TWOBYTE = lng_pref);
}
else
str_lang := 'en';
q := get_keyword_ucase (str_lang, lang_vec, 0.001);
if (is_rdf_box (o) or isstring (o))
{
if (q > best_q)
{
best_str := o;
best_q := q;
}
}
if (0)
{
if (is_rdf_box (o) and not rdf_box_is_complete (o))
l := 20;
else
l := length (o);
if (l > best_l)
{
best_str := o;
best_l := l;
}
}
}
if (is_rdf_box (best_str) and not rdf_box_is_complete (best_str))
return vector (0, 0, vector ('LBL_O_VALUE', vector (rdf_box_ro_id (best_str))));
return vector (best_str, 1);
}
;
create procedure
FCT_LABEL_NP (in x any, in g_id iri_id_8, in ctx varchar, in lng varchar := 'en')
{
declare best_str any;
declare best_l, l int;
declare label_iri iri_id_8;
declare q, best_q, str_lang, lang_id any;
declare lang_vec any;
if (is_rdf_box (x))
{
if (not rdf_box_is_complete (x))
__rdf_box_make_complete (x);
best_str := x;
goto endproc;
}
if (not isiri_id (x))
return null;
if (__proc_exists ('rdf_resolve_labels_s') is not null)
{
declare ret any;
ret := rdf_resolve_labels_s (adler32 (lng), vector (x));
ret := coalesce (ret[0], '');
return __ro2sq (ret);
}
rdf_check_init ();
label_iri := iri_id_from_num (atoi (registry_get ('fct_label_iri')));
best_str := '';
best_l := 0;
best_q := 0;
lang_vec := cmp_fill_lang_by_q (lng);
for select o
from rdf_quad table option (index rdf_quad)
where s = x and p in (rdf_super_sub_list (ctx, label_iri, 3)) order by cast (b3s_lbl_order (P) as int) option (same_as) do
{
o := __ro2sq (o);
lang_id := rdf_box_lang (o);
if (lang_id > 257)
str_lang := (select RL_ID from RDF_LANGUAGE where RL_TWOBYTE = lang_id);
else
str_lang := 'en';
q := get_keyword_ucase (str_lang, lang_vec, 0.001);
if (is_rdf_box (o) or isstring (o))
{
if (q > best_q)
{
best_str := o;
best_q := q;
}
}
}
endproc:
if (__tag(best_str) = __tag of varchar)
best_str := charset_recode (best_str, 'UTF-8', '_WIDE_');
return best_str;
}
;
create procedure
FCT_LABEL_S (in x any, in g_id iri_id_8, in ctx varchar, in lng varchar)
{
declare best_str any;
declare best_l, l int;
declare label_iri iri_id_8;
declare q, best_q, str_lang, lng_pref any;
declare lang_vec any;
if (not isiri_id (x))
return null;
if (__proc_exists ('rdf_resolve_labels_s') is not null)
{
declare ret any;
ret := rdf_resolve_labels_s (adler32 (coalesce (lng, '')), vector (x));
ret := coalesce (ret[0], '');
return __ro2sq (ret);
}
rdf_check_init ();
label_iri := iri_id_from_num (atoi (registry_get ('fct_label_iri')));
best_str := null;
best_l := 0;
best_q := 0;
lang_vec := cmp_fill_lang_by_q (lng);
for select o, p
from rdf_quad table option (no cluster, index rdf_quad)
where s = x and p in (rdf_super_sub_list (ctx, label_iri, 3)) do
{
if (is_rdf_box (o))
{
if (not rdf_box_is_complete (o))
__rdf_box_make_complete (o);
lng_pref := rdf_box_lang (o);
if (lng_pref <> 257)
{
str_lang := rdf_cache_id_to_name ('l', lng_pref);
if (0 = str_lang)
str_lang := (select RL_ID from RDF_LANGUAGE where RL_TWOBYTE = lng_pref);
}
else
str_lang := 'en';
}
else
str_lang := 'en';
q := get_keyword_ucase (str_lang, lang_vec, 0.001);
if (is_rdf_box (o) or isstring (o))
{
if (q > best_q)
{
best_str := o;
best_q := q;
}
}
}
if (is_rdf_box (best_str) and not rdf_box_is_complete (best_str))
{
__rdf_box_make_complete (best_str);
}
best_str := charset_recode (best_str, 'UTF-8', '_WIDE_');
return best_str;
}
;
create procedure
LBL_O_VALUE (in id int)
{
set isolation = 'committed';
return vector ((select case (isnull (RO_LONG)) when 0 then blob_to_string (RO_LONG) else RO_VAL end
from DB.DBA.RDF_OBJ table option (no cluster) where RO_ID = id), 1);
}
;
create procedure decl_dpipe_define ()
{
if (sys_stat ('cl_run_local_only'))
return;
dpipe_define ('DB.DBA.FCT_LABEL', 'DB.DBA.RDF_QUAD', 'RDF_QUAD_SP', 'DB.DBA.FCT_LABEL_DP', 0);
dpipe_define ('FCT_LABEL_L', 'DB.DBA.RDF_QUAD', 'RDF_QUAD_SP', 'DB.DBA.FCT_LABEL_DP_L', 0);
dpipe_define ('FCT_LABEL', 'DB.DBA.RDF_QUAD', 'RDF_QUAD_SP', 'DB.DBA.FCT_LABEL_DP', 0); -- was OPGS
dpipe_define ('LBL_O_VALUE', 'DB.DBA.RDF_OBJ', 'RDF_OBJ', 'DB.DBA.LBL_O_VALUE', 0);
}
;
decl_dpipe_define ();
TTLP ('@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix dc: <http://purl.org/dc/elements/1.1/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix virtrdf: <http://www.openlinksw.com/schemas/virtrdf#> .
@prefix fbase: <http://rdf.freebase.com/ns/type.object.> .
@prefix skos: <http://www.w3.org/2008/05/skos#> .
@prefix bibo: <http://purl.org/ontology/bibo/> .
@prefix gr: <http://purl.org/goodrelations/v1#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix og: <http://opengraphprotocol.org/schema/> .
@prefix schema: <http://schema.org/> .
dc:title rdfs:subPropertyOf virtrdf:label .
rdfs:label rdfs:subPropertyOf virtrdf:label .
fbase:name rdfs:subPropertyOf virtrdf:label .
foaf:name rdfs:subPropertyOf virtrdf:label .
<http://s.opencalais.com/1/pred/name> rdfs:subPropertyOf virtrdf:label .
foaf:nick rdfs:subPropertyOf virtrdf:label .
<http://www.w3.org/2004/02/skos/core#prefLabel> rdfs:subPropertyOf virtrdf:label .
skos:prefLabel rdfs:subPropertyOf virtrdf:label .
<http://www.geonames.org/ontology#name> rdfs:subPropertyOf virtrdf:label .
<http://purl.org/dc/terms/title> rdfs:subPropertyOf virtrdf:label .
foaf:accountName rdfs:subPropertyOf virtrdf:label .
bibo:shortTitle rdfs:subPropertyOf virtrdf:label .
<http://s.opencalais.com/1/pred/name> rdfs:subPropertyOf foaf:name .
<http://s.opencalais.com/1/type/er/Company> rdfs:subClassOf gr:BusinessEntity .
gr:BusinessEntity rdfs:subClassOf foaf:Organization .
<http://dbpedia.org/ontology/Company> rdfs:subClassOf gr:BusinessEntity .
<http://www.w3.org/2002/12/cal/ical#summary> rdfs:subPropertyOf rdfs:label .
<http://usefulinc.com/ns/doap#name> rdfs:subPropertyOf rdfs:label .
<http://linkedopencommerce.com/schemas/icecat/v1/hasModelName> rdfs:subPropertyOf virtrdf:label .
<http://aims.fao.org/aos/geopolitical.owl#nameListEN> rdfs:subPropertyOf rdfs:label .
<http://aims.fao.org/aos/geopolitical.owl#hasMinLatitude> rdfs:subPropertyOf geo:lat .
<http://aims.fao.org/aos/geopolitical.owl#hasMinLongitude> rdfs:subPropertyOf geo:long .
og:latitude rdfs:subPropertyOf geo:lat .
og:longitude rdfs:subPropertyOf geo:long .
schema:latitude rdfs:subPropertyOf geo:lat .
schema:longitude rdfs:subPropertyOf geo:long .
<http://uberblic.org/ontology/latitude> rdfs:subPropertyOf geo:lat .
<http://uberblic.org/ontology/longitude> rdfs:subPropertyOf geo:long .
<http://linkedopencommerce.com/schemas/icecat/v1/hasCategory> rdfs:subPropertyOf rdf:type .
<http://poolparty.punkt.at/demozone/ont#title> rdfs:subPropertyOf virtrdf:label .
<http://purl.uniprot.org/core/scientificName> rdfs:subPropertyOf virtrdf:label .
<http://www.openlinksw.com/schemas/googleplus#activity_title> rdfs:subPropertyOf virtrdf:label .
<http://linkedopencommerce.com/schemas/icecat/v1/hasShortSummaryDescription> rdfs:subPropertyOf virtrdf:label .
<http://yago-knowledge.org/resource/hasPreferredName> rdfs:subPropertyOf virtrdf:label .
', 'xx', 'facets');
rdfs_rule_set ('facets', 'facets');
rdfs_rule_set ('facets', 'virtrdf-label');
create procedure
fct_inf_val (in tree any)
{
declare i varchar;
i := cast (xpath_eval ('/query/@inference', tree) as varchar);
if (i is null or '' = i)
return null;
return i;
}
;
create procedure
fct_inf_clause (in tree any)
{
declare i varchar;
i := fct_inf_val (tree);
if (i is not null)
return sprintf (' define input:inference "%s" ', i);
return '';
}
;
create procedure
fct_invfp_val (in tree any)
{
declare i varchar;
if (fct_server_supports_invfp())
{
i := cast (xpath_eval ('/query/@invfp', tree) as varchar);
if (i is null or '' = i)
return null;
return i;
}
return null;
}
;
create procedure
fct_invfp_clause (in tree any)
{
declare i varchar;
i := fct_invfp_val (tree);
if (i is not null)
return sprintf (' define input:ifp "%s" ', i);
return '';
}
;
create procedure
fct_sas_val (in tree any)
{
declare i varchar;
i := cast (xpath_eval ('/query/@same-as', tree) as varchar);
if (i is null or '' = i or (not (fct_server_supports_invfp()) and i <> 'SAME_AS'))
return null;
return i;
}
;
create procedure
fct_sas_clause (in tree any)
{
declare i varchar;
i := fct_sas_val (tree);
if (i is not null)
return sprintf (' define input:same-as "%s" ', i);
return '';
}
;
create procedure
fct_graph_clause (in tree any)
{
declare i varchar;
i := cast (xpath_eval ('/query/@graph', tree) as varchar);
if (i is null or '' = i)
return '';
return sprintf (' define input:default-graph-uri <%s> ', cast (i as varchar));
}
;
create procedure
fct_named_graph_clause (in tree any)
{
declare xt, xp, inx, s any;
inx := 1;
s := string_output ();
while ((xp := xpath_eval (sprintf ('//query/@graph%d', inx), tree)) is not null)
{
inx := inx + 1;
http (sprintf (' define input:default-graph-uri <%s> ', cast (xp as varchar)), s);
}
return string_output_string (s);
}
;
create procedure
fct_post (in tree any, in post any, in lim int, in offs int)
{
if (lim is not null)
http (sprintf (' limit %d ', cast (lim as int)), post);
if (offs is not null)
http (sprintf (' offset %d ', cast (offs as int)), post);
}
;
create procedure
fct_dtp (in x any)
{
if (isiri_id (x) or __box_flags (x) = 1)
return 'uri';
declare dtp any;
dtp := rdf_datatype_of_long (x, UNAME'http://www.openlinksw.com/schemas/facets/dtp/plainstring');
return (id_to_iri (dtp));
}
;
--
-- Handle any DTs which need special serialization in FILTER, etc.
--
create procedure
fct_sparql_ser (in x any)
{
if (__TAG (x) = __TAG (getdate()))
return date_iso8601(__ro2sq (x));
return '';
}
;
create procedure
fct_lang (in x any)
{
if (not is_rdf_box (x))
return NULL;
if (rdf_box_lang (x) = 257)
return null;
return (select rl_id from rdf_language where rl_twobyte = rdf_box_lang (x));
}
;
create procedure
fct_get_mode (in tree any, in xp any)
{
declare view_type varchar;
view_type := cast (xpath_eval (xp, tree, 1) as varchar);
if (0 and sys_stat ('cl_run_local_only') and view_type = 'text-d')
view_type := 'text';
return view_type;
}
;
create procedure
fct_xml_wrap (in tree any, in txt any)
{
declare view_type varchar;
view_type := fct_get_mode (tree, '//view/@type');
declare ntxt any; -- , texp any;
ntxt := string_output ();
declare n_cols int;
n_cols := fct_n_cols(tree);
fct_dbg_msg (sprintf ('fct_xml_wrap: view_type: %s', view_type));
fct_dbg_msg (sprintf (' n_cols : %d', n_cols));
if (n_cols = 2)
{
if (view_type = 'text')
{
http (sprintf ('select xmlelement ("result", xmlattributes (''%s'' as "type"),
xmlagg (xmlelement ("row",
xmlelement ("column",
xmlattributes (''trank'' as "trank"),
"sc"),
xmlelement ("column",
xmlattributes (''erank'' as "erank"),
"rank"),
xmlelement ("column",
xmlattributes (''g'' as "graph"),
__ro2sq ("g")),
xmlelement ("column",
xmlattributes (fct_lang ("c1") as "xml:lang",
fct_dtp ("c1") as "datatype",
fct_short_form(__ro2sq("c1")) as "shortform"),
__ro2sq ("c1")),
xmlelement ("column",
fct_label_np ("c1", 0, ''facets'' )),
xmlelement ("column",
fct_bold_tags("c2")))))
from (sparql define output:valmode "LONG" ', view_type), ntxt);
}
else if (view_type = 'text-d')
{
-- texp := cast (xpath_eval ('string (//query/text)', tree, 1) as varchar);
http ('select xmlelement (\'result\',
xmlattributes (\'text-d\' as "type"),
"res")
from (sparql ', ntxt);
}
else if (view_type = 'entities-list' or view_type = 'list' or view_type = 'propval-list')
{
http (sprintf ('select xmlelement ("result", xmlattributes (''%s'' as "type"),
xmlagg (xmlelement ("row",
xmlelement ("column",
xmlattributes (fct_lang ("c1") as "xml:lang",
fct_dtp ("c1") as "datatype",
fct_short_form(__ro2sq("c1")) as "shortform"),
__ro2sq ("c1")),
xmlelement ("column",
fct_label_np ("c1", 0, ''facets'' )))))
from (sparql define output:valmode "LONG" ', view_type), ntxt);
}
else
{
http (sprintf ('select xmlelement ("result", xmlattributes (''%s'' as "type"),
xmlagg (xmlelement ("row",
xmlelement ("column",
xmlattributes (fct_lang ("c1") as "xml:lang",
fct_dtp ("c1") as "datatype",
fct_short_form(__ro2sq("c1")) as "shortform"),
__ro2sq ("c1")),
xmlelement ("column",
fct_label_np ("c1", 0, ''facets'' )),
xmlelement ("column",
fct_bold_tags("c2")))))
from (sparql define output:valmode "LONG" ', view_type), ntxt);
}
}
if (n_cols = 1)
http (sprintf ('select xmlelement ("result", xmlattributes (''%s'' as "type"),
xmlagg (xmlelement ("row",
xmlelement ("column",
xmlattributes (fct_lang ("c1") as "xml:lang",
fct_dtp ("c1") as "datatype",
fct_short_form(__ro2sq("c1")) as "shortform",
fct_sparql_ser ("c1") as "sparql_ser"),
__ro2sq ("c1")),
xmlelement ("column", fct_label_np ("c1", 0, ''facets'' )))))
from (sparql define output:valmode "LONG" ', view_type), ntxt);
if (n_cols = 3)
http (sprintf ('select xmlelement ("result", xmlattributes (''%s'' as "type"),
xmlagg (xmlelement ("row",
xmlelement ("column",
xmlattributes (fct_lang ("c1") as "xml:lang",
fct_dtp ("c1") as "datatype",
fct_short_form(__ro2sq("c1")) as "shortform"),
__ro2sq ("c1")),
xmlelement ("column",
fct_label_np ("c1", 0, ''facets'' )),
xmlelement ("column", __ro2sq ("c2")),
xmlelement ("column", __ro2sq ("c3"))
)))
from (sparql define output:valmode "LONG" ', view_type), ntxt);
http (txt, ntxt);
http (') xx option (quietcast)', ntxt);
return string_output_string (ntxt);
}
;
create procedure
fct_n_cols (in tree any)
{
declare tp varchar;
tp := cast (xpath_eval ('//view/@type', tree, 1) as varchar);
-- fct_dbg_msg (sprintf ('fct_n_cols: tp: %s', tp));
if ('list' = tp)
return 1;
else if ('geo' = tp or 'geo-list' = tp)
return 3;
return 2;
signal ('FCT00', 'Unknown facet view type');
}
;
create procedure
element_split (in val any)
{
declare srch_split, el varchar;
declare k integer;
declare sall any;
--srch_split := '';
--k := 0;
--sall := split_and_decode(val, 0, '\0\0 ');
--for(k:=0;k<length(sall);k:=k+1)
--{
-- el := sall[k];
-- if (el is not null and length(el) > 0) srch_split := concat (srch_split, ', ', '''',el,'''');
--};
--srch_split := trim(srch_split,',');
--srch_split := trim(srch_split,' ');
--return srch_split;
declare words any;
srch_split := '';
val := trim (val, '"');
FTI_MAKE_SEARCH_STRING_INNER (val,words);
k := 0;
for(k:=0;k<length(words);k:=k+1)
{
el := words[k];
if (el is not null and length(el) > 0)
srch_split := concat (srch_split, ', ', '''',el,'''');
};
srch_split := trim (srch_split,',');
srch_split := trim (srch_split,' ');
return srch_split;
}
;
create procedure
fct_view (in tree any, in this_s int, in txt any, in pre any, in post any, in full_tree any, in plain integer := 0)
{
declare lim, offs int;
declare mode varchar;
offs := xpath_eval ('./@offset', tree, 1);
lim := xpath_eval ('./@limit', tree, 1);
http (sprintf (' %s %s %s %s ', fct_graph_clause (tree), fct_named_graph_clause (tree), fct_inf_clause (tree), fct_invfp_clause (tree), fct_sas_clause (tree)), pre);
mode := fct_get_mode (tree, './@type');
-- geo-based conditionals force geo-list generation unless the old map mode is used
-- dbg_obj_print(full_tree);
declare geo_conds any;
geo_conds := xpath_eval ('//cond/@cond_t = ''near''', full_tree);
if (0 <> geo_conds and mode <> 'geo')
mode := 'geo-list';
fct_dbg_msg (sprintf('fct_view: view mode: %s', mode));
if ('list' = mode or 'propval-list' = mode)
{
declare langs varchar;
langs := connection_get ('langs');
http (sprintf ('select ?s%d as ?c1 ', this_s), pre);
http (sprintf (' group by (?s%d) order by desc (<LONG::IRI_RANK> (?s%d)) desc (bif:langmatches_pct_http (coalesce (lang(?s%d), \'\'), \'%s\'))',
this_s, this_s, this_s, langs), post);
}
if ('list-count' = mode)
{
declare i int;
http (sprintf ('select ?s%d as ?c1 count (*) as ?c2 where { select distinct ', this_s), pre);
for (i := 1; i <= this_s; i := i + 1)
http (sprintf ('?s%d ', i), pre);
if (xpath_eval ('ancestor::query/text', tree)) http ('?g ', pre);
http (sprintf (' } group by ?s%d order by desc 2', this_s), post);
}
if ('entities-list' = mode)
{
http (sprintf ('select ?s%d as ?c1 ', this_s), pre);
http (sprintf (' group by (?s%d) order by desc (<LONG::IRI_RANK> (?s%d)) ', this_s, this_s), post);
}
if ('properties' = mode)
{
if (length (fct_inf_clause (tree)) > 0)
http (sprintf ('select ?s%dp as ?c1 count (distinct (?s%d)) as ?c2 ', this_s, this_s), pre);
else
http (sprintf ('select ?s%dp as ?c1 count (distinct ?s%do) as ?c2 ', this_s, this_s), pre);
http (sprintf (' ?s%d ?s%dp ?s%do .', this_s, this_s, this_s), txt);
http (sprintf (' group by ?s%dp order by desc 2', this_s), post);
}
if ('properties-in' = mode)
{
http (sprintf ('select ?s%dip as ?c1 count (distinct ?s%d) as ?c2 ', this_s, this_s), pre);
http (sprintf (' ?s%do ?s%dip ?s%d .', this_s, this_s, this_s), txt);
http (sprintf (' group by ?s%dip order by desc 2', this_s), post);
}
if ('text-properties' = mode)
{
http (sprintf ('select ?s%dtextp as ?c1 count (*) as ?c2 ', this_s), pre);
http (sprintf (' group by ?s%dtextp order by desc 2', this_s), post);
}
if ('classes' = mode)
{
if (length (fct_inf_clause (tree)) > 0)
http (sprintf ('select ?s%dc as ?c1 count (distinct (?s%d)) as ?c2 ', this_s, this_s), pre);
else
http (sprintf ('select ?s%dc as ?c1 count (distinct ?s%d) as ?c2 ', this_s, this_s), pre);
http (sprintf (' ?s%d a ?s%dc .', this_s, this_s), txt);
http (sprintf (' group by ?s%dc order by desc 2', this_s), post);
}
if ('text' = mode or ('text-d' = mode and plain = 1))
{
declare exp any;
exp := cast (xpath_eval ('string (//text)', tree) as nvarchar);
exp := charset_recode (exp, '_WIDE_', 'UTF-8');
http (sprintf ('select ?s%d as ?c1, (bif:search_excerpt (bif:vector (%s), ?o%d)) as ?c2, ?sc, ?rank, ?g where {{{ select ?s%d, (?sc * 3e-1) as ?sc, ?o%d, (sql:rnk_scale (<LONG::IRI_RANK> (?s%d))) as ?rank, ?g',
this_s,
element_split (exp),
this_s, this_s, this_s, this_s), pre);
http (sprintf (' order by desc (?sc * 3e-1 + sql:rnk_scale (<LONG::IRI_RANK> (?s%d))) ', this_s), post);
fct_post (tree, post, lim, offs);
http ('}}}', post);
return;
}
if ('text-d' = mode)
{
declare exp any;
exp := charset_recode (xpath_eval ('string (//text)', tree), '_WIDE_', 'UTF-8');
-- dbg_obj_print (exp);
-- dbg_obj_print (element_split(exp));
http (sprintf ('select
(<sql:s_sum_page> (<sql:vector_agg> (<bif:vector> (?c1, ?sm, ?g1)), <bif:vector> (%s))) as ?res where { {
select (<SHORT_OR_LONG::>(?s%d)) as ?c1, (<sql:S_SUM> ( <SHORT_OR_LONG::IRI_RANK> (?s%d), <SHORT_OR_LONG::>(?s%dtextp), <SHORT_OR_LONG::>(?o%d), ?sc ) ) as ?sm, <SHORT_OR_LONG::>(?g) as ?g1', element_split (exp), this_s, this_s, this_s, this_s), pre);
http (sprintf ('order by desc (<sql:sum_rank> ((<sql:S_SUM> ( <SHORT_OR_LONG::IRI_RANK> (?s%d), <SHORT_OR_LONG::>(?s%dtextp), <SHORT_OR_LONG::>(?o%d), ?sc ) ) ) )', this_s, this_s, this_s), post);
fct_post (tree, post, lim, offs);
http ('}}', post);
return;
}
if ('graphs' = mode)
{
http ('select ?g as ?c1, count(*) as ?c2 ', pre);
http (' order by desc (2) ' , post);
}
if ('geo' = mode or 'geo-list' = mode)
{
declare loc any;
loc := xpath_eval ('@location-prop', tree);
if (loc = 'any')
loc := '?anyloc';
if (length (loc) > 1)
{
http (sprintf ('define input:inference "facets" select distinct ?s%d as ?c1 (round (xsd:float(?lat%d) * 10000) /10000) as ?c2 (round (xsd:float(?lng%d) * 10000) /10000) as ?c3 ',
this_s, this_s, this_s, this_s), pre);
}
else
http (sprintf ('select distinct ?s%d as ?c1 (round (xsd:float(?lat%d) * 10000) /10000) as ?c2 (round (xsd:float(?lng%d) * 10000) /10000) as ?c3 ',
this_s, this_s, this_s), pre);
if (length (loc) < 2)
http (sprintf (' ?s%d geo:lat ?lat%d ; geo:long ?lng%d .',
this_s, this_s, this_s), txt);
else
http (sprintf (' ?s%d %s ?location . ?location geo:lat ?lat%d ; geo:long ?lng%d .',
this_s, loc, this_s, this_s), txt);
}
fct_post (tree, post, lim, offs);