Mapping MySQL database to RDF with Karma

This post describes the workflow for mapping relational database to RDF using Karma tool.

1. Connect to database

image alt text

2. After the connection is established, select and import tables to be mapped from the database.

3. Import an ontology and/or other vocabulary, schemas that are needed for the mapping.

4. For each table set up a Base URI: once we want to publish one RDF resource composed from data from different tables then the base URI must be the same for all tables. image alt text

5. Modify id column in each table in order to use it as unique URIs. Click on triangle next to the column name and select PyTransform. Enter a python expression to change the value in the column:

return "site/"+ getValue("id")

This step is needed to generate unique URIs for objects and because the ids in database are unique only within on table, when working with many tables we must specify the context of id (e.g. add name of the table or column header to the URI).

6. The Workflow:

The rdf data will be save to OpenRDF repository (click the link in the right upper corner to go there). From the list of repositories choose karma_data, then on the left sidebar choose Contexts, and click on the context name you just created.

To export the rdf file one can also from the table panel in Karma interface, it appear there after selecting Publish – RDF.

image alt text

Important thing here is to set the Foreign Key column to the same Semantic Type this column was set in original table and set the same URI. For example: If in first table one sets site_id URI to semantic type E7_Activity1, then in second table which has site_id as FK it should be assigned the same semantic type E7_Activity1 (note also Activity1). In case one wants to set the semantic type of the same Class but distinguish it from other column (another table column) then one has to set it up to E7_Activity2.

image alt text

Link ‘R2RML’ model appears on the table panel, click on it and save it to local directory.

image alt text

Next time import the same table from database, then go to Apply R2RML Model, from File , browse the file - choose saved previously model file and apply it. All previously created mappings should appear on the table.

Comment/Edit this post on GitHub.
export blog text