You are here:
/ Dashboard / Main / VOSSQL2RDF

Mapping SQL Data to RDF

Introduction

Virtuoso uses a SPARQL-based Meta Schema Language to provide RDBMS-to-RDF mapping functionality (aka RDF Views of pre-existing SQL data). The language is an extension of the SPARQL query language meshed with Virtuoso's SPASQL (SPARQL-inside-SQL) functionality. The language enables you to map relational database schema tables, columns, rows and foreign key relationships declaratively to Classes, Attributes, Relationships and Instances (Objects/Entities/Individuals) defined by RDF Schemas or OWL Ontologies. The mapping process is simply a case of using a special built-in Virtuoso function for generating IRIs / URIs in "Subject" or "Object" position of a SPARQL graph pattern en route to building a set of SQL compiler rules and optimizations for translating SPARQL queries into SQL on the fly.

Mapping Process:

  1. Identify the tables, views and procedure views to be mapped
  2. Decide if you are performing a 1:1 mapping or a more customized mapping to a specific RDF Schema or Ontology
  3. Declare Virtuoso-URI-Generator functions for each Class in the target RDF Schema or Ontology
  4. Use the Virtuoso-URI-Generator functions in SPARQL graph patterns within ALTER QUAD STORAGE part of a SPASQL-based mapping statement
  5. Use Virtuoso's built-in URL-Rewrite Rules APIs (or Conductor UI) to publish the Linked Data URIs resulting from the mapping above.

Mapping Example

The example that follows in an excerpt from an actual mapping of the phpBB3 SQL schema to the classes defined by the SIOC and FOAF ontologies.


-- SPARQL keyword which is the SPARQL cue for the SQL processor

SPARQL

-- PREFIX declarations

prefix sioc:  <http://rdfs.org/sioc/ns#>
prefix sioct: <http://rdfs.org/sioc/types#>
prefix atom:  <http://atomowl.org/ontologies/atomrdf#>
prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
prefix foaf:  <http://xmlns.com/foaf/0.1/>
prefix dc:    <http://purl.org/dc/elements/1.1/>
prefix dct:   <http://purl.org/dc/terms/>
prefix skos:  <http://www.w3.org/2004/02/skos/core#>
prefix geo:   <http://www.w3.org/2003/01/geo/wgs84_pos#>
prefix bm:    <http://www.w3.org/2002/01/bookmark#>
prefix exif:  <http://www.w3.org/2003/12/exif/ns/>
prefix ann:   <http://www.w3.org/2000/10/annotation-ns#>
prefix phpbb: <http://openlinksw.com/phpBB3/>

-- Remove prior mappings 
drop quad map graph iri("http://^{URIQADefaultHost}^/phpBB3_v/") .

-- Declare the special Virtuoso-URI-Generator functions for later using in actual mappings

create iri class phpbb:site_iri      "http://^{URIQADefaultHost}^/phpBB3/%U#this" (in dummy varchar not null) .
create iri class phpbb:user_iri      "http://^{URIQADefaultHost}^/phpBB3/user/%U#this" (in user_name integer not null) .
create iri class phpbb:usergroup_iri "http://^{URIQADefaultHost}^/phpBB3/group/%U#this" (in group_name integer not null) .
create iri class phpbb:forum_iri     "http://^{URIQADefaultHost}^/phpBB3/forum/%d#this" (in forum_id integer not null) .
create iri class phpbb:post_iri      "http://^{URIQADefaultHost}^/phpBB3/post/%d#this" (in post_id integer not null) .

-- Start the actual mapping declaration process
-- Identify Quad Storage Partition within Quad Store

alter quad storage virtrdf:DefaultQuadStorage
  {

-- Declare Named Graph URI / IRI associated with previously declared Quad Storage partition

    create virtrdf:phpBB3 as graph iri ("http://^{URIQADefaultHost}^/phpBB3_v/")
      {

-- Use SPARQL / Turtle Graph patterns to declare:
-- mappings between Table and a RDF Schema or Ontology Class
	# Default phpBB Space
	phpbb:site_iri (PHPBB3.phpBB.phpBB3_site_rdf.WS_DUMMY)
	a sioc:Space ;

--- mappings between Columns in a Table with Attributes of a RDF Schema or Ontology Class
	dc:title WEB_TITLE .

-- The combined data from each mapped column (row) is used to generate an instance (Entity/Individual) of this RDF Schema or Ontology Class 
-- Repeat the process for Each Table being mapped

	# User
	phpbb:user_iri (PHPBB3.phpBB.phpBB3_users_rdf.username)
	a sioc:User ;
	sioc:id user_id ;
	sioc:name username ;
	sioc:email E_MAIL ;
	sioc:email_sha1 E_MAIL_SHA1 ;
	sioc:has_space phpbb:site_iri(WS_DUMMY) .

	# Usergroup
	phpbb:usergroup_iri (PHPBB3.phpBB.phpBB3_usergroups_rdf.group_name)
	a sioc:Usergroup ;
	sioc:id group_id ;
	sioc:name group_name .
        .....

White Papers & Tutorials

Sample Mapping Scripts

Web 2.0 Platforms

Semi-Structured Content Examples

Enterprise Data Access & Integration

Business Intelligence

How Do I... ?

Virtuoso and the Virtuoso Website are Copyright (C) OpenLink Software 2006-
SourceForge.net Logo