OpenLink Virtuoso – RDF Views
Download
Report
Transcript OpenLink Virtuoso – RDF Views
OpenLink Virtuoso – RDF Views
Exposing SQL Data as RDF
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
Northwind Demo Database
Tables include:
Demo.demo.Customers
Customer
ID
Company
Name
Contact
Name
Contact
Title
Address
City
Postal
Code
Country
Phone
Fax
varchar(5)
varchar(40)
varchar(30)
varchar(30)
varchar(60)
varchar(15)
varchar(10
)
varchar(15)
varchar(24)
varchar(24)
ALFKI
Alfreds
Futterkiste
Maria
Anders
Sales
Representative
Obere Str.
57
Berlin
12209
Germany
030 0074321
030 0076545
ANATR
Ana Trujillo
Emparedados
y helados
Ana Trujillo
Owner
Avda. de la
Constitucion
2222
Mexico
D.F.
05021
Mexico
(5) 555 4729
(5) 555 3745
ANTON
Antonio
Moreno
Taqueria
Antonio
Moreno
Owner
Avda. de la
Constitucion
2222
Mexico
D.F.
05023
Mexico
(171) 555 7788
(171) 555 6759
Demo.demo.Orders
Order ID
Customer
ID
Employee
ID
Order
Date
Required
Date
Shipped
Date
Ship Via
…
10643
ALFKI
6
1995-09-25
1995-10-23
1995-10-03
1
…
10692
ALFKI
4
1995-11-03
1995-12-01
1995-11-13
2
…
…
…
…
…
…
…
…
© 2007 OpenLink Software, All rights reserved
Northwind Demo Database:
RDF View Definition Extract
Demo.demo.Customers
Customer
ID
Company
Name
Contact
Name
Contact
Title
Address
City
Postal
Code
Northwind RDF View Definition
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 … {
create virtrdf:NorthwindDemo as graph iri (“http://^{URIQADefaultHost}^/Northwind”) {
…
northwind:Customer(customers.CustomerID) a foaf:Organization as virtrdf:Customer-CustomerID ;
northwind:companyName customers.CompanyName as … ;
…
northwind:fax customers.Fax as virtrdf:Customer-fax .
northwind:Customer(orders.CustomerID)
northwind:has_order northwind:Order(orders.OrderID) as virtrdf:Order-has_order .
…
}}
© 2007 OpenLink Software, All rights reserved
Country
Phone
Fax
Northwind Demo Database:
RDF View Definition Extract
Demo.demo.Orders
Order ID
Customer
ID
Employee
ID
Order
Date
Required
Date
Shipped
Date
Shipped
Via
Northwind RDF View Definition
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 … {
create virtrdf:NorthwindDemo as graph iri (“http://^{URIQADefaultHost}^/Northwind”) {
…
northwind:Order (orders.OrderID) a northwind:Order as virtrdf:Order-Order ;
northwind:orderDate orders.OrderDate as virtrdf:Order-order_date ;
northwind:requiredDate orders.RequiredDate as virtrdf:Order-required_date ;
…
northwind:has_customer northwind:Customer (orders.CustomerID) as virtrdf:Order-order_has_customer
northwind:has_employee northwind:Employee (orders.EmployeeID) as virtrdf:Order-order_has_employee ;
…
}}
© 2007 OpenLink Software, All rights reserved
…
Northwind Demo Database:
Customer Table to RDF Entity Mapping
Customer
ID
Company
Name
Contact
Name
Contact
Title
Address
City
Postal
Code
Country
Phone
Fax
ALFKI
Alfreds
Futterkiste
Maria
Anders
Sales
Representative
Obere Str.
57
Berlin
12209
Germany
030 0074321
030 0076545
prefix <http://demo.openlinksw.com/Northwind/>
has_customer
has_order
Customer/ALFKI#this
Order/10643#this
has_order
companyName
Order/10692#this
has_customer
Alfreds
Futterkiste
…
contactName
Maria
Anders
fax
030-0076545
contactTitle
PostalCode
12209
address
030-0074321
city
country
Sales
Representative
Berlin
phone
Germany
Obere Str. 57
© 2007 OpenLink Software, All rights reserved
Orders Table
Order
ID
Customer
ID
…
10643
ALFKI
…
10692
ALFKI
…
Northwind Demo Database:
RDF Browser View – Customer
© 2007 OpenLink Software, All rights reserved
Northwind Demo Database:
RDF Browser View – Order
© 2007 OpenLink Software, All rights reserved
Example: Product Portfolio – Table View
© 2007 OpenLink Software, All rights reserved
Example: Product Portfolio – RDF View
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
MSL Building Blocks
Main building blocks:
Quad map patterns
IRI classes
Literal classes
Organizational enhancements
Group map patterns
Quad storage
Naming
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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 .
}
© 2007 OpenLink Software, All rights reserved
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 .
}
© 2007 OpenLink Software, All rights reserved
Group Map Patterns
Quad map patterns for the same graph can be grouped
together into a group map pattern
create virtrdf:product_portfolio as
group map
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 .
}
© 2007 OpenLink Software, All rights reserved
pattern name
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
© 2007 OpenLink Software, All rights reserved
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
) .
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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 ;
...
} .
} .
© 2007 OpenLink Software, All rights reserved
Additional Meta Schema Language
Features
Table aliases
SQL selection and SQL joins through filters
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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/>
primary key to IRI conversion
{
. . .
pc:product_category_iri(product_category_tbl.product_cat_id)
a pc:ProductCategory
foreign key to IRI conversion
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 .
. . .
}
© 2007 OpenLink Software, All rights reserved
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
© 2007 OpenLink Software, All rights reserved
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)
© 2007 OpenLink Software, All rights reserved