Presentation Transcript
OpenLink Virtuoso – RDF Views: OpenLink Virtuoso – RDF Views Exposing SQL Data as RDF
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
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
Northwind Demo Database: Northwind Demo Database Tables include: Demo.demo.Orders Demo.demo.Customers
Northwind Demo Database:RDF View Definition Extract: Northwind Demo Database: RDF View Definition Extract prefix northwind:
…
create iri class northwind:Customer (in customer_id varchar not null)
…
alter quad storage virtrdf:DefaultQuadStorage
…
from Demo.demo.Customers as customers
from Demo.demo.Orders as orders … {
Demo.demo.Customers Northwind RDF View Definition 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 .
Northwind Demo Database:RDF View Definition Extract: Northwind Demo Database: RDF View Definition Extract prefix northwind:
…
create iri class northwind:Order (in order_id integer not null) .
…
alter quad storage virtrdf:DefaultQuadStorage
…
from Demo.demo.Customers as customers
from Demo.demo.Orders as orders … {
Demo.demo.Orders Northwind RDF View Definition 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 ;
Northwind Demo Database:Customer Table to RDF Entity Mapping: Northwind Demo Database: Customer Table to RDF Entity Mapping Orders Table
Northwind Demo Database:RDF Browser View – Customer : Northwind Demo Database: RDF Browser View – Customer
Northwind Demo Database:RDF Browser View – Order : Northwind Demo Database: RDF Browser View – Order
Example: Product Portfolio – Table View: Example: Product Portfolio – Table View
Example: Product Portfolio – RDF View: Example: Product Portfolio – RDF View
Meta-Schema 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
MSL Building Blocks: MSL Building Blocks Main building blocks:
Quad map patterns
IRI classes
Literal classes
Organizational enhancements
Group map patterns
Quad storage
Naming
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
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
Quad Map Pattern - Example: Quad Map Pattern - Example graph
subject p:product_iri (oplweb2.oplweb.product.product_id)
predicate p:description
object oplweb2.oplweb.product.product_description
Alternative SPARQL-Style Notation
graph
{
p:product_iri (oplweb2.oplweb.product.product_id) p:description oplweb2.oplweb.product.product_description .
}
Named Quad Map Patterns: Named Quad Map Patterns graph
{
p:product_iri (oplweb2.oplweb.product.product_id) p:description oplweb2.oplweb.product.product_description
as virtrdf:product_product_description .
}
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
{
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 .
}
group map pattern name
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
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:
create iri class prd:product_iri “http://www.openlinksw.com/oplweb/product#%s” (
in product_id varchar not null
) .
IRI Classes – Format Strings: IRI Classes – Format Strings sparql
prefix prd:
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
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
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
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
A Simple RDF View Definition: A Simple RDF View Definition prefix p: http://www.openlinksw.com/schemas/oplweb/product#
prefix pc:
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
{
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 ;
...
} .
} .
Additional Meta Schema Language Features: Additional Meta Schema Language Features Table aliases
SQL selection and SQL joins through filters
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
SQL Selection & 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
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
{
. . .
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 .
. . .
} foreign key to IRI conversion primary key to IRI conversion
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
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)