add text handling to loading and showing triples
This commit is contained in:
parent
6879a9254c
commit
1ff292f9ba
5 changed files with 43 additions and 9 deletions
|
|
@ -6,6 +6,8 @@ begin
|
|||
case tname
|
||||
when 'node' then
|
||||
return get_node(vtext);
|
||||
when 'text' then
|
||||
return get_text(vtext);
|
||||
when 'int' then
|
||||
return to_number(vtext, '99999999');
|
||||
else
|
||||
|
|
@ -35,6 +37,18 @@ end;
|
|||
$$ language plpgsql;
|
||||
|
||||
|
||||
create or replace function get_text(vtext text, out value bigint) as $$
|
||||
begin
|
||||
select texts.id into value from texts
|
||||
where text = vtext;
|
||||
if not found then
|
||||
insert into texts (text) values (vtext)
|
||||
returning texts.id into value;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
|
||||
create or replace function load_triple(
|
||||
stname text, stext text, ptext text,
|
||||
otname text, otext text, event bigint) returns bigint as $$
|
||||
|
|
@ -74,13 +88,15 @@ $$ language plpgsql;
|
|||
create or replace function load_namespace(
|
||||
nsiri text, nspfx text, out nsid int) as $$
|
||||
begin
|
||||
select ns.id into nsid from namespaces ns
|
||||
where iri = nsiri and prefix = nspfx;
|
||||
if not found then
|
||||
nsid := get_nsiri(nsiri);
|
||||
if nsid is null then
|
||||
nsid := get_nsprefix(nspfx);
|
||||
if nsid is null then
|
||||
insert into namespaces as ns (iri, prefix)
|
||||
values (nsiri, nspfx)
|
||||
returning ns.id into nsid;
|
||||
end if;
|
||||
end if;
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
|
|
@ -111,6 +127,16 @@ $$ language plpgsql;
|
|||
|
||||
-- simple SQL functions
|
||||
|
||||
create or replace function get_nsiri(nsiri text) returns int as $$
|
||||
select ns.id from namespaces ns where iri = nsiri;
|
||||
$$ language sql;
|
||||
|
||||
|
||||
create or replace function get_nsprefix(nspfx text) returns int as $$
|
||||
select ns.id from namespaces ns where prefix = nspfx;
|
||||
$$ language sql;
|
||||
|
||||
|
||||
create or replace function get_datatype(name text) returns smallint as $$
|
||||
select dt.id from datatypes dt where dtname = name;
|
||||
$$ language sql;
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ begin
|
|||
case tname
|
||||
when 'node' then
|
||||
return show_node(id);
|
||||
when 'text' then
|
||||
return show_text(id);
|
||||
else
|
||||
return text(show_value.id);
|
||||
end case;
|
||||
|
|
@ -27,3 +29,7 @@ create or replace function show_node(nid bigint) returns text as $$
|
|||
$$ language sql;
|
||||
|
||||
|
||||
create or replace function show_text(tid bigint) returns text as $$
|
||||
select text from texts
|
||||
where texts.id = tid;
|
||||
$$ language sql;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ select new_event() as event
|
|||
|
||||
-- load data
|
||||
|
||||
select load_namespace('http://cyberconcepts.org/cco-blank#', '_');
|
||||
select load_namespace('http://cyberconcepts.org/cco-common#', 'cco');
|
||||
select load_namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#', 'rdf');
|
||||
select load_namespace('http://www.w3.org/2000/01/rdf-schema#', 'rdfs');
|
||||
|
|
@ -26,3 +27,4 @@ select load_datatype('timestamp');
|
|||
select load_triple('node', 'rdf:type', 'rdf:type', 'node', 'rdf:Property', :event);
|
||||
select load_triple('node', 'rdf:Property', 'rdf:type', 'node', 'rdfs:Class', :event);
|
||||
select load_triple('node', 'rdfs:Class', 'rdf:type', 'node', 'rdfs:Class', :event);
|
||||
select load_triple('node', 'rdfs:label', 'rdf:type', 'node', 'rdfs:Property', :event);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
CREATE TABLE namespaces (
|
||||
id serial NOT NULL primary key,
|
||||
iri text NOT NULL unique,
|
||||
prefix text unique
|
||||
prefix text NOT NULL unique
|
||||
);
|
||||
|
||||
CREATE TABLE datatypes (
|
||||
|
|
@ -68,4 +68,4 @@ CREATE INDEX idx_po ON triples USING btree (predicate, otype, ovalue);
|
|||
CREATE INDEX idx_os ON triples USING btree (otype, ovalue, stype, svalue);
|
||||
|
||||
CREATE INDEX fki_language ON texts USING btree (language);
|
||||
CREATE INDEX idx_texts ON texts USING btree (text);
|
||||
CREATE INDEX idx_text ON texts USING btree (text);
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ select triples.id,
|
|||
stype, svalue, show_value(stype, svalue) as stext,
|
||||
predicate, show_value(dt.id, predicate) as ptext,
|
||||
otype, ovalue, show_value(otype, ovalue) as otext,
|
||||
events.tstamp as ts
|
||||
to_char(events.tstamp, 'YYYY-MM-DD HH24:MI:SS') as ts
|
||||
from triples, datatypes dt, events
|
||||
where dtname = 'node'
|
||||
and events.id = creation
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue