An introductory guide for generating RDF triples from relational data in minutes
Karma (http://usc-isi-i2.github.io/karma/) is a data integration tool developed at the Center of Knowledge Graphs of the Information Science Institute at the University of Southern California.
Here at DISIT, we exploit Karma for triplifying relational data.
This document aims to be an introductory guide that helps beginners moving their first steps with the tool.
Here are the steps to have your triples in your pocket in minutes:
- Get one of the ready-to-use DISIT VMs
- Launch the Karma server
- Build your own model:
- Load vocabularies
- Load relational tables
- (Optional) Load R2RML models
- Define mappings
- Export your model
- Launch the command-line tool
Get one of the ready-to-use DISIT VMs
The DISIT Lab makes available through its Drupal portal a set of ready-to-use virtual machines specifically oriented to data integration. Here is how you can get one of them:
- Connect to https://www.disit.org/drupal/?q=node/6690 and scroll down to the section “MACCHINA VIRTUALE, VMSDETL, GIA' PRONTA”
- Get the “Versione del 2017/2018 0.8 con Phoenix” at https://www.disit.org/vmsdetl/VMSDETL-2017-v0-8.rar, or the “Versione del 2017/2018 0.8 con Phoenix per Virtualbox” at https://www.disit.org/vmsdetl/VMSDETL-2017-v0-8-ovf.rar, unless you have a good reason for picking a different one
- Wait for the download to complete, and extract the archive
- Launch the VM player of your choice
- Open the VM
- Run it
Launch the Karma server
Do the following to run the Karma server:
- Open a shell
- Move to ~/programs/Web-Karma-master/karma-web
- Run mvn -Djetty.port=9999 jetty:run
- Wait while the Jetty server comes up
- Connect to localhost:9999 where you will find the Web application for building your model
Build your own model
For that Karma could produce the RDF triples for you, it is required that you instruct it about how relational data should be mapped to semantic data. Documents that describe such a mapping are called R2RML models. Models are built operating a dedicated Karma Web application, and they are exported as ttl files.
Below here are the basic instructions for building a model from scratch or editing an existing one.
Have you connected to http://localhost:9999? Are you displaying something similar to this?
Right, you are ready to load your vocabularies.
Identify classes and properties that you wish to appear in RDF triples that will be the result of the whole process. Identify vocabularies where such classes and properties are defined. Load them.
Below here is how you load a vocabulary:
- Hit Import, at the top left corner of the Web page
- Hit From File
- Select the vocabulary file (it can be an OWL, RDF/XML, or TTL file)
- Leave OWL Ontology selected, and hit Next
- Indicate the correct file encoding if the proposed one is not, and hit Import
You should now see your newly imported vocabulary displayed in the Command History (left column).
Load relational tables
Identify tables in your RDB where source data can be found. Load them in your model.
Below here is how you load a table:
- Hit Import, at the top left corner of the Web page
- Hit Database Table. The Import Database Table dialog should open.
- Fill in the form with authentication data and RDB name, and hit OK
- A table listing should appear below the form
- Put the mouse pointer over the table of your interest
- Buttons Import and Preview should appear at the right of the table name. Hit Import.
- Confirmation message “Table imported in the workspace!” should appear. Hit OK.
- Repeat steps 5 – 8 for each table where source data are found
- Hit Close at the bottom right corner of the Import Database Table dialog to dismiss it
(Optional) Load R2RML models
If you already have built and exported a model in the past, and you now just need to make a modification over it, you can start loading and applying your existing model, instead of rebuilding it from scratch.
Below here is how you apply an existing model:
- Identify the table to which the model has to be applied, and hit the triangle that is displayed next to the table name similar to nex figure
- Select Apply R2RML Model, and then From File
- Select the ttl file that contains your model, and hit Open
- Done. Classes and links should appear in the workspace.
Below here is how you specify that a column of an RDB table maps to a data property of a semantic class, and how to specify that a column contains an identifier that can be used for building the URIs of instances of the semantic class:
- Below RDB table name, identify the blue box that contains the column name written in white
- Hit the white triangle that you can see next to the column name
- Hit Set Semantic Type
- Pick the checkbox at left of property of Class
- Hit the Edit button at right of property of Class
- Select the semantic class from the All Classes list. Use the Class textbox for filtering.
- Select the property from the All Properties list. Use the Property textbox for filtering.
- If the column is a key, pick the Mark as key for the class checkbox
- You can map the column to a typed literal, filling the textbox below the label Literal type
- When you are done, hit Save. Repeat the procedure for each of the columns to be mapped.
Below here is how you specify instead that a foreign key of a table in a relational database corresponds to an object property of a semantic class. Scenario: a relational table stops, that corresponds to a semantic class Stop, has a column agency_id where the unique identifier of the agency that manages the stop can be found. Each value in agency_id corresponds to one and only one value in a column, let’s say id, that can be found in the relational table agencies. Table agencies corresponds to the semantic class Agency. We wish resources of class Stop to be linked each to the appropriate resource of class Agency, through the property gtfs:agency. For such a purpose, we will do the following:
- Load relational table stops to workspace
- Map data properties, linking columns in table stops, to the class Stop, through appropriate properties, as outlined above
- Identify the grey box with rounded angles that has the name of the class Stop written within. It should locate in the workspace. Identify the black triangle that should locate near the right margin of the box. Click it.
- Select Add Outgoing Link. A popup window should open.
- Type gtfs:agency in the box labelled Property, and gtfs:Agency in the box labelled To Class
- Click Save in the bottom right corner of the popup window to dismiss it.
- A new grey box, related to class Agency, will appear in the workspace, linked to the grey box related to class Stop through a link labelled agency for brevity
- Map column agency_id as a data property of class Agency, also specifying that it is a unique identifier, as described in the above paragraph
- Repeat for all foreign keys to be mapped, then go to next step (Export your model).
Learn more about the building of R2RML models at https://github.com/usc-isi-i2/karma-step-by-step/wiki.
Export your model
Once you have defined all needed mappings, you have to export your model to a ttl file, so that you can provide it as a parameter to the command-line Karma tool that performs the triplification.
Here is how you can export your model:
- Identify the RDB table whose model you wish to export
- Hit the black triangle at the right of the table name
- Select Publish, and then Model
- A popup should appear at the top right corner of the window, saying “R2RML Model published”
- Hit Manage Models, in the menu bar at the top of the page
- A listing should appear of all models that you have exported in the current session
- Identify the row corresponding to the last model exported, based on the File Name (the name of the RDB table) and the Publish Time.
- Cut the URL that you can find in the rightmost column of the prospect, and open it in a new tab
- Save As… the page that you have opened at step 8.
- Done. The file that you have saved at step 9 is your ready-to-use R2RML model.
Launch the command-line tool
Once you have exported your R2RML model as a ttl file, you are ready to perform the triplification:
- Open a shell
- Move to /home/ubuntu/programs/Web-Karma-master/karma-offline
- Launch the following as a single line command, customizing parameter values in bold:
-Dexec.args=" --sourcetype DB --modelfilepath /path/to/model.ttl
--outputfile /path/to/output_triples_file.n3 --dbtype MySQL
–hostname mysql_srv_hostname_or_ip_address --username mysql_user
--password mysql_pwd --portnumber 3306 --dbname mysql_dbname
--tablename mysql_table_name -Dexec.classpathScope=compile
Report mistakes and provide suggestions about this guide
See the help desk page on the left side menu