d2rq/d2rq — pull request #143 by luiseufrasio (2012-04-05 00:17:56+00:00)
Title: R2RML Parser initial implementation

Richard,

I've tested this first version with this simple R2RML mapping and it's working :)
@prefix map: <#> .
@prefix rr: .
@prefix s: .

# Table book
<#BookTriplesMap>
rr:logicalTable [ rr:tableName "book" ];
rr:subjectMap [
rr:template "book/@@book.title|urlify@@";
rr:class s:Book;
];
rr:predicateObjectMap [
rr:predicate s:title;
rr:objectMap [ rr:column "title" ];
];
rr:predicateObjectMap [
rr:predicate s:pub;
rr:objectMap [
rr:parentTriplesMap <#PublTriplesMap>;
rr:joinCondition [
rr:child "publisher";
rr:parent "name";
];
];
].

# Table music
<#MusicTriplesMap>
rr:logicalTable [ rr:tableName "music"];
rr:subjectMap [
rr:template "music/@@music.title|urlify@@";
rr:class s:Music;
];
rr:predicateObjectMap [
rr:predicate s:title;
rr:objectMap [ rr:column "title" ];
];
rr:predicateObjectMap [
rr:predicate s:recorder;
rr:objectMap [ rr:column "rec" ];
].

# Table publ
<#PublTriplesMap>
rr:logicalTable [ rr:tableName "publ" ];
rr:subjectMap [
rr:template "publisher/@@publ.name|urlify@@";
rr:class s:Publ;
];
rr:predicateObjectMap [
rr:predicate s:name;
rr:objectMap [ rr:column "name" ];
];
rr:predicateObjectMap [
rr:predicate s:address;
rr:objectMap [ rr:column "address" ];
].

The DBMS used was MySql and the database script is:
CREATE TABLE Publ (
name VARCHAR(100) NOT NULL,
address VARCHAR(200) NOT NULL,
primary key(name)
);

CREATE TABLE Recorder (
recname VARCHAR(100) NOT NULL,
primary key(recname)
);

CREATE TABLE Book (
title VARCHAR(100) NOT NULL,
price DECIMAL(15,2) NOT NULL,
currency VARCHAR(20) NOT NULL,
isbn VARCHAR(20) NULL,
author VARCHAR(100) NULL,
publisher VARCHAR(100) NULL,
PRIMARY KEY(title),
FOREIGN KEY(publisher)
REFERENCES Publ(name)
);

CREATE TABLE Music (
title VARCHAR(100) NOT NULL,
price DECIMAL(15,2) NOT NULL,
currency VARCHAR(20) NOT NULL,
rec VARCHAR(100) NOT NULL,
PRIMARY KEY(title),
FOREIGN KEY(rec)
REFERENCES Recorder(recname)
);

CREATE TABLE Video (
title VARCHAR(100) NOT NULL,
price DECIMAL(15,2) NOT NULL,
currency VARCHAR(20) NOT NULL,
PRIMARY KEY(title)
);

CREATE TABLE PC_HW (
title VARCHAR(100) NOT NULL,
price DECIMAL(15,2) NOT NULL,
currency VARCHAR(20) NOT NULL,
PRIMARY KEY(title)
);

INSERT INTO Publ
VALUES ('CAMPUS', 'Rua 7 Setembro, 111 an 16- Centro - Rio de Janeiro - RJ');

INSERT INTO Book
VALUES ('VERDADES FUNDAMENTAIS SOBRE A NATUREZA DO LIDER', 59.9, 'REAL', '978-85-352-4150-1', 'Barry Posner', 'CAMPUS');

INSERT INTO Book
VALUES ('Biblia Sagrada Edicao Pastoral', 40.0, 'REAL', '978-85-352-4150-1', 'God', 'CAMPUS');

INSERT INTO Recorder
VALUES ('Universal Music Argentina S.A.');

INSERT INTO Music
VALUES ('TUDO AZUL', 1.5, 'REAL', 'Universal Music Argentina S.A.');

INSERT INTO PC_HW
VALUES ('Kindle', 139, 'DOLAR');

To test it, I start the server.java class as follow:
-u root -pass admin -d com.mysql.jdbc.Driver -j jdbc:mysql://127.0.0.1/amazon mapping.ttl

Please revise the code and let me know what changes and corrections I should do.