Creating RDF Views over SQL Data Sources - Technology Tutorial

Comments

There aren't any comments for this presentation.

Add Comment

Please enter a valid email address.

Optional. Enter a URL for your website.

  Remember Me
  Notify me of follow up comments

Transcript

no image

Slide Text

Slide Notes


OpenLink Virtuoso RDF Views


OpenLink Virtuoso – RDF Views
Exposing SQL Data as RDF

no notes exist for this slide

OpenLink Virtuoso Universal Server


OpenLink Virtuoso Universal Server
Cross-platform server for SQL, XML and RDF data management
Includes
Virtual database engine
Web services deployment platform
Web application server
SPARQL support and an RDF data store tightly integrated with its relational storage engine

no notes exist for this slide

Virtuoso RDF Views


Virtuoso RDF Views
Expose pre-existing relational data as virtual RDF graphs
Available for querying through SPARQL or SPASQL (SPARQL embedded in SQL)
No physical regeneration of relational data

no notes exist for this slide

Northwind Demo Database


Northwind Demo Database
Tables include:

no notes exist for this slide

Northwind Demo Database RDF View Definition Extract


Northwind Demo Database:
RDF View Definition Extract
prefix northwind: <http://www.openlinksw.com/schemas/northwind#>
…
create iri class northwind:Customer
<http://^{URIQADefaultHost}^/Northwind/Customer/%U#this> (in customer_id varchar not null)
…
alter quad storage virtrdf:DefaultQuadStorage
…
from Demo.demo.Customers as customers
from Demo.demo.Orders as orders … {

no notes exist for this slide

Slide 6


Northwind Demo Database:
RDF View Definition Extract
prefix northwind: <http://www.openlinksw.com/schemas/northwind#>
…
create iri class northwind:Order
<http://^{URIQADefaultHost}^/Northwind/Order/%d#this> (in order_id integer not null) .
…
alter quad storage virtrdf:DefaultQuadStorage
…
from Demo.demo.Customers as customers
from Demo.demo.Orders as orders … {

no notes exist for this slide

Northwind Demo Database Customer Table to RDF Entity Mapping


Northwind Demo Database:
Customer Table to RDF Entity Mapping

no notes exist for this slide

Northwind Demo Database RDF Browser View Customer


Northwind Demo Database:
RDF Browser View – Customer

no notes exist for this slide

Northwind Demo Database RDF Browser View Order


Northwind Demo Database:
RDF Browser View – Order

no notes exist for this slide

Example Product Portfolio Table View


Example: Product Portfolio – Table View

no notes exist for this slide

Example Product Portfolio RDF View


Example: Product Portfolio – RDF View

no notes exist for this slide

MetaSchema Language


Meta-Schema Language
RDF Views =
Virtuoso RDF Meta-Schema +
Meta-Schema Language
MSL =
A domain specific, declarative language for mapping a logical SQL data model to a conceptual RDF data model

no notes exist for this slide

MSL Building Blocks


MSL Building Blocks
Main building blocks:
Quad map patterns
IRI classes
Literal classes
Organizational enhancements
Group map patterns
Quad storage
Naming

no notes exist for this slide

Organizational Enhancements


Organizational Enhancements
Make it easier to administer large sets of quad map patterns
Group map patterns – group together map patterns sharing a common graph
Quad storage – groups together group map patterns as a named set
Both allow map patterns to be altered/deleted individually or as a group

no notes exist for this slide

Quad Map Pattern


Quad Map Pattern
Basic unit of meta schema
Defines transformation from one set of relational columns into triples that match one SPARQL graph pattern
Comprises 4 declarations of quad map values – each calculates a triple field value from the SQL data

no notes exist for this slide

Quad Map Pattern Example


Quad Map Pattern - Example
graph <http://www.openlinksw.com/oplweb>
subject p:product_iri (oplweb2.oplweb.product.product_id)
predicate p:description
object oplweb2.oplweb.product.product_description
Alternative SPARQL-Style Notation
graph <http://www.openlinksw.com/oplweb>
{
   p:product_iri (oplweb2.oplweb.product.product_id) p:description oplweb2.oplweb.product.product_description .
}

no notes exist for this slide

Named Quad Map Patterns


Named Quad Map Patterns
graph <http://www.openlinksw.com/oplweb>
{
   p:product_iri (oplweb2.oplweb.product.product_id) p:description oplweb2.oplweb.product.product_description
   as virtrdf:product_product_description .
}

no notes exist for this slide

Group Map Patterns


Group Map Patterns
Quad map patterns for the same graph can be grouped together into a group map pattern
create virtrdf:product_portfolio as
graph <http://www.openlinksw.com/oplweb>
{
   p:product_iri (oplweb2.oplweb.product.product_id)
      a p:Product
      as virtrdf:product_product_id ;
   p:description oplweb2.oplweb.product.product_description
      as virtrdf:product_product_description .
}

no notes exist for this slide

Quad Storage


Quad Storage
Quad storage = a named set of quad patterns
Compartmentalizes the RDF to SQL mapping
Contained quad patterns can be manipulated en-bloc

drop quad storage storage-name
create quad storage storage-name { quad-map declarations }
alter quad storage storage-name { quad-map declarations or
               drop commands }
Map patterns can only be created inside a quad storage definition

no notes exist for this slide

IRI Classes Creating IRIs from Keys


IRI Classes – Creating IRIs from Keys
IRI class – constructs a subject IRI for each primary key column value
Defines how key values (for atomic or compound key) are combined into / decomposed from an IRI string
sparql
prefix prd: <http://www.openlinksw.com/schemas/oplweb/product#>
create iri class prd:product_iri
“http://www.openlinksw.com/oplweb/product#%s”
(
      in product_id varchar not null
   ) .

no notes exist for this slide

IRI Classes Format Strings


IRI Classes – Format Strings
sparql
prefix prd: <http://www.openlinksw.com/schemas/oplweb/product#>
create iri class prd:product_iri
“http://www.openlinksw.com/oplweb/product#%s”
(
      in product_id varchar not null
   ) .
Sprintf-style format string for performing conversion
Other format specifiers supported. E.g. %d
The reverse conversion is inferred automatically

no notes exist for this slide

IRI Classes Complex Conversions


IRI Classes – Complex Conversions
For more complex conversions, functions can be specified that assemble and disassemble an IRI from/into its constituent parts
create iri class prd:product_iri using
   function oplweb2.oplweb.product_uri (in id varchar)
      returns varchar,
   function oplweb2.oplweb.product_uri_inverse (in id_iri varchar)
   returns varchar .

Functions product_uri and product_uri inverse would be defined elsewhere in Virtuoso/PL

no notes exist for this slide

Literal classes Identity classes


Literal classes / Identity classes
Non-key columns normally form the object of a triple
Object component of an RDF triple can be an IRI or an RDF literal
Literal classes create RDF literals from non-key column values
Identity class = special form of literal class
Converts a SQL VARCHAR value into an untyped literal
Converts values of other SQL data types to an appropriate XML Schema typed literal (e.g. xsd:integer or xsd:date)
Need not be defined explicitly
Invoked implicitly when a column name is used directly as the object in a quad map pattern

no notes exist for this slide

Quad Pattern Construction Rules


Quad Pattern Construction Rules
An RDF View is defined by combining the building blocks described so far into a collection of quad patterns
Each quad pattern can consist of:
Subject: an IRI class or constant IRI
Predicate: a constant IRI or an IRI class
Object: an IRI class, literal class, literal IRI or a scalar
Graph: a constant IRI or an IRI class
Filter: an optional SQL search condition used to filter rows

no notes exist for this slide

A Simple RDF View Definition


A Simple RDF View Definition
prefix p: http://www.openlinksw.com/schemas/oplweb/product#
prefix pc: <http://www.openlinksw.com/schemas/oplweb/product_category#>
alter quad storage virtrdf:DefaultQuadStorage
from oplweb2.oplweb.product as product_tbl
from oplweb2.oplweb.product_category as product_category_tbl
{
create virtrdf:product_portfolio as graph <http://www.openlinksw.com/oplweb/>
   {
   p:product_iri(product_tbl.product_id) a p:Product
      as virtrdf:product_product_id ;
   p:details product_tbl.long_description
      as virtrdf:product_long_description ;
   p:product_category pc:product_category_iri(product_tbl.product_cat_id)
      as virtrdf:product_product_cat_id .
   pc:product_category_iri(product_category_tbl.product_cat_id)
      a pc:ProductCategory
      as virtrdf:product_category_product_cat_id ;
   ...
   } .
} .

no notes exist for this slide

Additional Meta Schema Language Features


Additional Meta Schema Language Features
Table aliases
SQL selection and SQL joins through filters

no notes exist for this slide

Table Aliases


Table Aliases
Provide a concise alternative to fully qualified table names in map patterns
Declared with a statement such as:

from oplweb2.oplweb.product as product_tbl
Declared once at the start of the storage declaration
Because quad map patterns usually share a common set of source tables
Shared between all the quad maps defined in the storage declaration

no notes exist for this slide

SQL Selection amp Joins Through Filters


SQL Selection & Joins Through Filters
SQL Projection
Not always desirable to expose all the columns in a table or view
Security reasons etc.
Key column value may have no meaning beyond being a unique identifier which is transformed into an IRI
Obvious – simply :
omit defining quad map patterns for the relevant columns
Omit property definitions for these columns in the RDFS class for the table

no notes exist for this slide

SQL Selection


SQL Selection
A quad map pattern can include a condition
i.e. a boolean SQL expression
Filters out unwanted rows of source data
SQL expression includes placeholders where a table reference should be printed

from oplweb2.oplweb.product as product_tbl
from oplweb2.oplweb.product_category as product_category_tbl
graph <http://www.openlinksw.com/oplweb/>
{
   . . .
   pc:product_category_iri(product_category_tbl.product_cat_id)
    a pc:ProductCategory
    as virtrdf:product_category_product_cat_id ;
   pc:includes_product p:product_iri(product_tbl.product_id)
    where (^{product_tbl.}^.product_cat_id =^{product_category_tbl.}^.product_cat_id)
    as virtrdf:product_category_product_collection .
   . . .
}

no notes exist for this slide

Associating Filters with Table Aliases


Associating Filters with Table Aliases
An alternative to specifying filter conditions directly in quad patterns is to specify them alongside a table alias
from DB.DBA.SYS_USERS as user where (^{user.}^.U_IS_ROLE = 0)
from DB.DBA.SYS_USERS as group where (^{group.}^.U_IS_ROLE = 1)

All map patterns using the alias are subject to the same filter condition
If several aliases have associated conditions, the WHERE clause of the generated SQL contains a combination of all relevant conditions

no notes exist for this slide

SQL Joins


SQL Joins
As well as filtering, a quad map pattern condition can also specify join criteria
Multiple conditions can be associated with a table alias
For complex joins a quad map pattern can reference a SQL view joining multiple tables
from DB.DBA.SYS_USERS as user where (^{user.}^.U_IS_ROLE = 0)
from DB.DBA.SYS_USERS as group where (^{group.}^.U_IS_ROLE = 1)
from DB.DBA.SYS_USERS as account
from user as active_user where (^{active_user.}^.U_ACCOUNT_DISABLED = 0)
from DB.DBA.SYS_ROLE_GRANTS as grant
   where (^{grant.}^.GI_SUPER = ^{account.}^.U_ID)
   where (^{grant.}^.GI_SUB = ^{group.}^.U_ID)
   where (^{grant.}^.GI_SUPER = ^{user.}^.U_ID)

no notes exist for this slide