-- -- $Id$ -- -- This file is part of the OpenLink Software Virtuoso Open-Source (VOS) -- project. -- -- Copyright (C) 1998-2014 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 -- exec_stmt ('create table RDF_P_SCORE (p_iri iri_id_8 primary key, p_score int)',0); exec_stmt ('create table RDF_LP_SCORE (lp_id int, lp_lang int, lp_score float, primary key (lp_id, lp_lang))',0); create procedure lbl_order (in p any) { declare r int; r := vector ( 'http://www.w3.org/2000/01/rdf-schema#label', 'http://xmlns.com/foaf/0.1/name', 'http://purl.org/dc/elements/1.1/title', 'http://purl.org/dc/terms/title', 'http://xmlns.com/foaf/0.1/nick', 'http://usefulinc.com/ns/doap#name', 'http://rdf.data-vocabulary.org/name', 'http://www.w3.org/2002/12/cal/ical#summary', 'http://aims.fao.org/aos/geopolitical.owl#nameListEN', 'http://s.opencalais.com/1/pred/name', 'http://www.crunchbase.com/source_description', 'http://dbpedia.org/property/name', 'http://www.geonames.org/ontology#name', 'http://purl.org/ontology/bibo/shortTitle', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#value', 'http://xmlns.com/foaf/0.1/accountName', 'http://www.w3.org/2004/02/skos/core#prefLabel', 'http://rdf.freebase.com/ns/type.object.name', 'http://s.opencalais.com/1/pred/name', 'http://www.w3.org/2008/05/skos#prefLabel', 'http://www.w3.org/2002/12/cal/icaltzd#summary', 'http://rdf.data-vocabulary.org/name', 'http://rdf.freebase.com/ns/common.topic.alias', 'http://opengraphprotocol.org/schema/title', 'http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema.rdf#Name', 'http://poolparty.punkt.at/demozone/ont#title', 'http://www.openlinksw.com/schemas/googleplus#activity_title', 'http://www.openlinksw.com/schemas/googleplus#providerTitle' ); r := position (id_to_iri (p), r); if (r <= 0) return 100; return r; } ; -- Same as lbl_order(), except that skos:prefLabel takes precedence -- NLP meta-cartridges use skos:prefLabel to include a label prefix identifying the source cartridge create procedure lbl_order_1 (in p any) { declare r int; r := vector ( 'http://www.w3.org/2004/02/skos/core#prefLabel', 'http://www.w3.org/2000/01/rdf-schema#label', 'http://xmlns.com/foaf/0.1/name', 'http://purl.org/dc/elements/1.1/title', 'http://purl.org/dc/terms/title', 'http://xmlns.com/foaf/0.1/nick', 'http://usefulinc.com/ns/doap#name', 'http://rdf.data-vocabulary.org/name', 'http://www.w3.org/2002/12/cal/ical#summary', 'http://aims.fao.org/aos/geopolitical.owl#nameListEN', 'http://s.opencalais.com/1/pred/name', 'http://www.crunchbase.com/source_description', 'http://dbpedia.org/property/name', 'http://www.geonames.org/ontology#name', 'http://purl.org/ontology/bibo/shortTitle', 'http://www.w3.org/1999/02/22-rdf-syntax-ns#value', 'http://xmlns.com/foaf/0.1/accountName', 'http://rdf.freebase.com/ns/type.object.name', 'http://s.opencalais.com/1/pred/name', 'http://www.w3.org/2008/05/skos#prefLabel', 'http://www.w3.org/2002/12/cal/icaltzd#summary', 'http://rdf.data-vocabulary.org/name', 'http://rdf.freebase.com/ns/common.topic.alias', 'http://opengraphprotocol.org/schema/title', 'http://rdf.alchemyapi.com/rdf/v1/s/aapi-schema.rdf#Name', 'http://poolparty.punkt.at/demozone/ont#title', 'http://www.openlinksw.com/schemas/googleplus#activity_title', 'http://www.openlinksw.com/schemas/googleplus#providerTitle' ); r := position (id_to_iri (p), r); if (r <= 0) return 100; return r; } ; create procedure p_score_init () { declare ps, ord any; ps := rdf_super_sub_list ('virtrdf-label', __i2id ('http://www.openlinksw.com/schemas/virtrdf#label'), 3); delete from rdf_p_score; foreach (any x in ps) do { -- ord := lbl_order (x); ord := lbl_order_1 (x); insert into rdf_p_score (p_iri, p_score) values (x, ord); } commit work; registry_set ('sponge_vec', cast (gt (atoi(sys_stat ('st_dbms_ver')), 6) as varchar)); } ; create procedure rdfdesc_get_lang_acc (in lines any) { declare accept, itm varchar; declare i, l, q int; declare ret, arr any; accept := 'en'; if (lines is not null) { accept := http_request_header_full (lines, 'Accept-Language', 'en'); } arr := split_and_decode (accept, 0, '\0\0,;'); q := 0; l := length (arr); ret := make_array (l, 'any'); for (i := 0; i < l; i := i + 2) { declare tmp any; itm := trim(arr[i]); if (itm like '%-%') itm := subseq (itm, 0, strchr (itm, '-')); 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; } ret[i] := itm; ret[i+1] := q; } return ret; } ; create procedure lp_score_ck (in lines any) { declare accept, ha, arr any; declare i,l any; accept := http_request_header_full (lines, 'Accept-Language', 'en'); ha := adler32 (accept); if (exists (select 1 from rdf_lp_score where lp_id = ha)) { commit work; return ha; } arr := rdfdesc_get_lang_acc (lines); l := length (arr); for (i := 0; i < l; i := i + 2) { declare cd any; cd := DB.DBA.RDF_TWOBYTE_OF_LANGUAGE (arr[i]); if (not exists (select 1 from rdf_lp_score where lp_id = ha and lp_lang = cd)) insert into rdf_lp_score (lp_id, lp_lang, lp_score) values (ha, cd, arr[i+1]); } commit work; return ha; } ; p_score_init () ; create procedure b3s_page_get_type (in val any) { declare delim, delim1, delim2, delim3 integer; declare pref, res varchar; delim1 := coalesce (strrchr (val, '/'), -1); delim2 := coalesce (strrchr (val, '#'), -1); delim3 := coalesce (strrchr (val, ':'), -1); delim := __max (delim1, delim2, delim3); if (delim < 0) return val; pref := subseq (val, 0, delim+1); if (pref = val) return val; if (strstr (val, 'http://dbpedia.org/resource/') = 0 ) return 'dbpedia'; if (strstr (val, 'http://dbpedia.org/property/') = 0 ) return 'p'; if (strstr (val, 'http://dbpedia.openlinksw.com/wikicompany/') = 0 ) return 'wikicompany'; if (strstr (val, 'http://dbpedia.org/class/yago/') = 0 ) return 'yago'; if (strstr (val, 'http://www.w3.org/2003/01/geo/wgs84_pos#') = 0 ) return 'geo'; if (strstr (val, 'http://www.geonames.org/ontology#') = 0 ) return 'geonames'; if (strstr (val, 'http://xmlns.com/foaf/0.1/') = 0 ) return 'foaf'; if (strstr (val, 'http://www.w3.org/2004/02/skos/core#') = 0 ) return 'skos'; if (strstr (val, 'http://www.w3.org/2002/07/owl#') = 0 ) return 'owl'; if (strstr (val, 'http://www.w3.org/2000/01/rdf-schema#') = 0 ) return 'rdfs'; if (strstr (val, 'http://www.w3.org/1999/02/22-rdf-syntax-ns#') = 0 ) return 'rdf'; if (strstr (val, 'http://www.w3.org/2001/XMLSchema#') = 0 ) return 'xsd'; if (strstr (val, 'http://purl.org/dc/elements/1.1/') = 0 ) return 'dc'; if (strstr (val, 'http://purl.org/dc/terms/') = 0 ) return 'dcterms'; if (strstr (val, 'http://dbpedia.org/units/') = 0 ) return 'units'; if (strstr (val, 'http://www.w3.org/1999/xhtml/vocab#') = 0 ) return 'xhv'; if (strstr (val, 'http://rdfs.org/sioc/ns#') = 0 ) return 'sioc'; if (strstr (val, 'http://purl.org/ontology/bibo/') = 0 ) return 'bibo'; if (pref is null) return val; res := __xml_get_ns_prefix (pref, 2); if (res is null) return val; return res; } ; -- -- make a vector of languages and their quality -- create procedure b3s_get_lang_acc (in lines any) { declare accept, itm varchar; declare i, l, q int; declare ret, arr any; accept := 'en'; if (lines is not null) { accept := http_request_header_full (lines, 'Accept-Language', 'en'); } arr := split_and_decode (accept, 0, '\0\0,;'); q := 0; l := length (arr); ret := make_array (l, 'any'); for (i := 0; i < l; i := i + 2) { declare tmp any; itm := trim(arr[i]); if (itm like '%-%') itm := subseq (itm, 0, strchr (itm, '-')); 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; } ret[i] := itm; ret[i+1] := q; } return ret; } ; create procedure b3s_str_lang_check (in lang any, in acc any) { if (lang like '%-%') lang := subseq (lang, 0, strchr (lang, '-')); if (not length (lang)) return 1; else if (position (lang, acc) > 0) return 1; else if (position ('*', acc) > 0) return 1; return 0; } ; create procedure b3s_handle_ses (inout _path any, inout _lines any, inout _params any) { declare sid, refr varchar; sid := get_keyword ('sid', _params); if (sid is null) { refr := http_request_header (http_request_header (), 'Referer', null, null); if (refr is not null) { declare ht, pars any; ht := WS.WS.PARSE_URI (refr); pars := ht[4]; pars := split_and_decode (pars); if (pars is not null) sid := get_keyword ('sid', pars); } } if (sid is not null and (regexp_match ('[0-9]*', sid) = sid)) connection_set ('sid', sid); } ; -- XXX should probably find the most specific if more than one class and inference rule is set create procedure b3s_e_type (in subj varchar) { declare meta, data, ll any; declare i int; ll := 'http://www.w3.org/2002/07/owl#Thing'; if (length (subj)) { exec (sprintf ('sparql select ?tp where { <%S> a ?tp }', subj), null, null, vector (), 100, meta, data); if (length (data)) { for (i := 0; i < length (data); i := i + 1) { if (data[i][0] is not null) return data[i][0]; } } } return ll; } ; create procedure b3s_type (in subj varchar, in _from varchar, out url varchar, out c_iri varchar) { declare meta, data, ll any; declare i int; ll := 'unknown'; url := 'javascript:void()'; c_iri := 'http://www.w3.org/2002/07/owl#Thing'; if (length (subj)) { exec (sprintf ('sparql select ?l ?tp %s where { <%S> a ?tp optional { ?tp rdfs:label ?l } }', _from, subj), null, null, vector (), 100, meta, data); if (length (data)) { for (i := 0; i < length (data); i := i + 1) { if (data[i][0] is not null) ll := data[i][0]; else ll := b3s_uri_local_part (data[i][1]); url := b3s_http_url (data[i][1]); c_iri := data[i][1]; } } } return ll; } ; -- This is where we should have something smart... instead we return the last one... create procedure b3s_choose_e_type (inout type_a any) { if (not length(type_a)) return vector ('http://www.w3.org/2002/07/owl#Thing', 'owl:Thing', 'A Thing'); -- dbg_printf ('type_a length: %d', length(type_a)); return (type_a[length(type_a)-1]); } ; -- -- Detect if viewing an explicit or implicit class -- create procedure b3s_find_class_type (in _s varchar, in _f varchar, inout types_a any) { declare i int; for (i := 0; i < length (types_a); i := i + 1) { if (types_a[i][0] in ('http://www.w3.org/2002/07/owl#Class', 'http://www.w3.org/2000/01/rdf-schema#Class')) return 1; } declare stmt, st, msg varchar; declare meta,data any; data := null; st := '00000'; msg:= ''; stmt := sprintf ('sparql select ?to %s where {?to a <%S>}', _f, _s); exec (stmt, st, msg, vector(), 1, meta, data); if (length (data)) return 1; return 0; } ; create procedure b3s_uri_local_part (in uri varchar) { declare delim integer; declare uriSearch varchar; delim := -1; uriSearch := uri; delim := coalesce (strrchr (uriSearch, '/'), 0); delim := __max (delim, coalesce (strrchr (uriSearch, '#'), 0)); delim := __max (delim, coalesce (strrchr (uriSearch, ':'), 0)); if (delim > 0) uriSearch := subseq (uri, delim + 1); return uriSearch; } ; -- -- vector (vector (, ,