-- RdfObjects.mysql -- Create a database for storing generic RDF statements.
-- $Id: MigrateRdfObjects1-2.sql,v 1.2 2004/04/30 20:25:04 eric Exp $

-- These instructions assume you want a database called RdfDB.
-- In MySQL, you can create this with:
--   mysqladmin create RdfDB

-- MySQL invocation:
--   mysql -u root RdfDB < makeRdfObjects.mysql

-- This could miss some redundant statements. Detect this with
--   mysql -u root annoteam -e 'select *,count(*) from Statements group by predicate,subject,object,reifiedId' | grep -v 	1\$
-- Note: the tab (before the 1) must be inserted with a ^v in most shells.

-- Create generic triplestore tables:

INSERT INTO __Nodes__ (id, type, hash, str, big, attribOrDT) SELECT RdfIds.id, 'uri', md5(Uris.uri), Uris.uri, NULL, NULL FROM RdfIds INNER JOIN Uris ON RdfIds.uri=Uris.id;
INSERT INTO __Nodes__ (id, type, hash, str, big, attribOrDT) SELECT RdfIds.id, 'literal', md5(concat('P:', Strings.string)), concat('P:', Strings.string), NULL, NULL FROM RdfIds INNER JOIN Strings ON RdfIds.string=Strings.id WHERE Strings.encoding='PLAIN';
INSERT INTO __Nodes__ (id, type, hash, str, big, attribOrDT) SELECT RdfIds.id, 'literal', md5(concat('X:', Strings.string)), concat('X:', Strings.string), NULL, NULL FROM RdfIds INNER JOIN Strings ON RdfIds.string=Strings.id WHERE Strings.encoding='XML';
INSERT INTO __Nodes__ (id, type, hash, str, big, attribOrDT) SELECT RdfIds.id, 'bnode', md5(concat('_', GenIds.id ,':', source.uri)), concat('_', GenIds.id ,':', source.uri), NULL, Attributions.id FROM RdfIds INNER JOIN GenIds ON RdfIds.genId=GenIds.id INNER JOIN Attributions ON GenIds.attribution=Attributions.id INNER JOIN RdfIds AS sourceId ON Attributions.rdfId=sourceId.id INNER JOIN Uris AS source ON sourceId.uri=source.id;

INSERT INTO __Attributions__ (id, type, doc, auth, modified, created) SELECT Attributions.id, 'source', Attributions.rdfId, Attributions.auth, 0, 0 FROM Attributions WHERE type='Source';
-- ... type enum('source','generated','reified') NOT NULL default 'source',

INSERT INTO __AttrLists__ (id, listId, a) SELECT NULL, id, id FROM Attributions WHERE type='Source';

INSERT INTO __Holds__ (id, p, s, o, r, a) SELECT Statements.id, Statements.predicate, Statements.subject, Statements.object, Statements.reifiedId, Statements.attribution FROM Statements;

