Creating RDF Triples from a Relational Database
Thursday, August 5th, 2010In an earlier blog entry I discussed the potential reduction in refactoring effort if our data is represented as RDF triples rather than relational structures. As a way to give myself easy access to RDF data and to work more with semantic web tool features I have created a program to export relational data to RDF.
The program is really a proof-of-concept. It takes a SQL query and converts the resulting rows into assertions of triples. The approach is simple: given a SQL statement and a chosen primary key column (PK) to represent the instance for the exported data, assert triples with the primary key column value as the subject, the column names as the predicates and the non-PK column values as the objects.
Here is a brief sample taken from the documentation accompanying the code.
- Given a table named people with the following columns and rows:
id name age
-- ---- ---
1 Fred 20
2 Martha 25
- And a query of: select id, name, age from people
- And the primary key column set to: id
- Then the asserted triples (shown using Turtle and skipping prefixes) will be:
dsr:PK_1
a owl:Thing , dsr:RdbData ;
rdfs:label "1" ;
dsr:name "Fred" ;
dsr:age "20" .
dsr:PK_2
a owl:Thing , dsr:RdbData ;
rdfs:label "2" ;
dsr:name "Martha" ;
dsr:age "25" .
You can see that the approach represents a quick way to convert the data.