This JavaScript library generates a RML mapping based on data sources and corresponding RDF triples. It is available as a Node.js module.
Consider the following table which we want to map to RDF.
id | firstname | lastname |
---|---|---|
0 | john | doe |
1 | james | doe |
2 | Winston | Peterson |
Let's have a look at the first row. The corresponding RDF triples we would want, look like this:
<http://www.example.com/0> a foaf:Person;
foaf:firstName 'john';
foaf:familyName 'Doe'.
Using this library, an RML mapping can be generated by providing both the data source and the example RDF triples. The RML mapping will look something like this.
<#Mapping>
rr:subjectMap [
rr:class foaf:Person
];
rr:predicateObjectMap [
rr:predicate foaf:firstName;
rr:objectMap [
rml:reference 'firstname'
]
];
rr:predicateObjectMap [
rr:predicate foaf:familyName;
rr:objectMap [
rml:reference 'lastname'
]
].
Install the module via npm install example2rml
.
Below you can find an example on how to use the module.
let example2rml = require('example2rml');
let triples = [{
subject: 'http://www.example.com/pieter',
predicate: 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type',
object: 'http://www.example.com#Person'
}, {
subject: 'http://www.example.com/pieter',
predicate: 'http://www.example.com#firstName',
object: '"Pieter"'
}, {
subject: 'http://www.example.com/pieter',
predicate: 'http://www.example.com#lastName',
object: '"Heyvaert"'
}, {
subject: 'http://www.example.com/pieter',
predicate: 'http://www.example.com#age',
object: '"26"'
}];
let dataSources = [{
type: 'csv',
row: [{
column: 'firstname',
value: 'Pieter'
},{
column: 'lastname',
value: 'Heyvaert'
},{
column: 'age',
value: '26'
}]
}];
example2rml(triples, dataSources).then(console.log);
Install the module via npm install -g example2rml
.
You execute an example via example2rml -i ./demo/1/data.csv -t ./demo/1/example2rml.nt
, where -i
is a comma separated list of paths to input data sources and -t
is the path to the example triples.
More information and other options can be found via example2rml -h
.
At the moment CSV and JSON are supported.
The example2rml library is written by Pieter Heyvaert.
This code is copyrighted by Ghent University – imec.