SPARQL-DL - Theory & Practice

Post on 11-May-2015

1,148 views 0 download

Tags:

description

Seminário apresentado na disciplina Raciocínio Automático e Representação do Conhecimento Simbólico (RAARCS) do CIn-UFPE em 11/09/2013.

transcript

SPARQL-DLTheory & Practice

Adriel Caféaac3@cin.ufpe.br

Summary

1. OWL Basics

2. SPARQL

3. SPARQL-DL

4. Comparison: SPARQL x SPARQL-DL

5. Reasoner's Support for DL

6. Practice

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

Important

This document was based on W3C specifications

• http://w3.org/2001/sw/wiki/SPARQL-DL

• http://w3.org/TR/sparql11-query

• http://w3.org/TR/sparql11-overview

• http://w3.org/TR/rdf-sparql-query

• http://w3.org/TR/owl-guide

• http://w3.org/TR/owl-features

• http://w3.org/TR/owl-ref

• http://w3.org/TR/owl2-overview

• http://w3.org/TR/owl2-profiles

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

OWL BasicsOntology Web Language

• Is an ontology language for the Semantic Web with formally defined meaning

• Is a W3C standard since 2004

• Written in XML

• Derived from the DAML+OIL

• Developed as a vocabulary extension of RDF

• Provide classes, properties, individuals, data values and are stored as Semantic Web documents

• OWL Tools

• OWL Syntax Converter (http://owl.cs.manchester.ac.uk/converter)

• OWL Validator (http://owl.cs.manchester.ac.uk/validator)

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

OWL 1• Compatible with RDF

• Profiles

• OWL Full (Not DL)

• OWL DL (DL SHOIN(D))

• OWL Lite (DL SHIF(D))

OWL Versions

OWL 2• Compatible with OWL 1 and RDF

• Profiles

• OWL 2 EL (DL EL++)

• OWL 2 QL (DL-Lite)

• OWL 2 RL (DLP)

• OWL 2 DL (DL SROIQ(D))Is used informally to refer to ontologies interpreted using the Direct Semantics http://w3.org/TR/owl2-direct-semantics

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

OWL 2 Structure

http://w3.org/TR/owl2-overview/OWL2-structure2-800.png

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

SPARQLSPARQL Protocol and RDF Query Language

• Is a SQL-Like language for querying RDF data

• Is a protocol

• Is a W3C standard since 2008

• Queries consist of triple patterns, conjunctions, disjunctions, and optional patterns

"SPARQL will make a huge difference“(Berners-Lee, 2006)

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

SPARQL in Semantic Web Stack

http://upload.wikimedia.org/wikipedia/en/3/37/Semantic-web-stack.png

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

SPARQL Query Types

• SELECTReturns all, or a subset of, the variables bound in a query pattern match.

• ASKReturns a boolean indicating whether a query pattern matches or not.

• CONSTRUCTReturns an RDF graph constructed by substituting variables in a set of triple templates.

• DESCRIBEReturns an RDF graph that describes the resources found.

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

PREFIX foaf: <http://xmlns.com/foaf/0.1/>

SELECT DISTINCT ?name

FROM <http://xmlns.com/foaf/spec/index.rdf>

WHERE { ?x foaf:name ?name

}

ORDER BY ?nameLIMIT 5OFFSET 10

Anatomy of a SPARQL Query

Triple patterns to be localizedSubject, Predicate and Object

Prefix label associated with an IRI

Returns all possible bindings of the provided variablesDISTINCT keyword removes all redundant bindings

Data sources that should be consulted

Solution sequences and modifiers

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

RDF Definitions

• RDF TripleContains three components: subject, predicate and object

<http://com.ex/people#adrielcafe> <http://com.ex/contact#name> “Adriel Café"

• RDF GraphIs a set of RDF triples

• Triple PatternIs like an RDF triple, but with the option of a variable in place of RDF terms (i.e., IRIs, literals or blank nodes) in the subject, predicate or object positions

?people <http://com.ex/contact#name> ?name

• Basic Graph Pattern (BGP)Is a conjunction of a finite set of triple patterns

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

SPARQL Subgraph Matching

• The SPARQL query processor will search for sets of triples that match these triple patterns, binding the variables in the query to the corresponding parts of each triple.

• Subgraph matching (a.k.a. simple entailment) considers only the graph structure of RDF for computing query results

• Entailment RegimesRDFS Entailment Regime, D-Entailment Regime, OWL 2 RDF-Based Semantics, OWL 2 Direct Semantics

“The main mechanism for computing query results in SPARQL is subgraph matching: RDF triples in both the queried RDF data and the query pattern are interpreted as nodes and edges of directed graphs, and the resulting query graph is matched to the data graph using variables as wild cards.”

(Glimm; Krötzsch, 2010)

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

SPARQL-DLSPARQL Protocol and RDF Query Language – Description Logics

• Is a distinct subset of SPARQL

• Uses SPARQL syntax

• Is tailored to ontology specific questions

• Is not yet a W3C standard

• Quite expressive language which allows to mix TBox, RBox, and ABox queries

• Fully aligned with the OWL 2 standard

• Settled on top of the OWL API

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

http://www.derivo.de/uploads/pics/SPARQL-DL_01.png

SPARQL-DL Abstract Syntax

• A SPARQL-DL query Q is a finite set of SPARQL-DL query atoms and the query is interpreted as the conjunction of the elements in the set.

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

Query Type of the query An example query

Q1 Standard TBox query SubClassOf(?c, ex:Student)

Q2 Standard ABox query Type(?x, and(ex:Student, ex:Employee)),PropertyValue(?x, ex:name, ?y)

Q3ABox query with non-distinguished variables

PropertyValue(?x, ex:hasPublication, _:y),PropertyValue(:y, ex:publishedAt, _:z),Type(_:z, not(ex:Workshop))

Q4 Mixed ABox/TBox queryType(?x, ex:Student), Type(?x, ?c),SubClassOf(?c, ex:Employee),

Q5 Mixed ABox/RBox query ObjectProperty(?p),PropertyValue(ex:John, ?p, ?v)

(Parsia & Sirin, 2007)

SPARQL-DL Supported Query Patterns

Class(a)

Property(a)

Individual(a)

Type(a, b)

PropertyValue(a, b, c)

EquivalentClass(a, b)

SubClassOf(a, b)

EquivalentProperty(a, b)

SubPropertyOf(a, b)

InverseOf(a, b)

ObjectProperty(a)

DataProperty(a)

Functional(a)

InverseFunctional(a)

Transitive(a)

Symmetric(a)

Reflexive(a)

Irreflexive(a)

SameAs(a, b)

DisjointWith(a, b)

DifferentFrom(a, b)

ComplementOf(a, b)

Annotation(a, b, c)

StrictSubClassOf(a, b)

DirectSubClassOf(a, b)

DirectType(a, b)

StrictSubPropertyOf(a, b)

DirectSubPropertyOf(a, b)

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

SPARQL-DL Syntax

• Query Types: ASK and SELECT

• Supports union-like statements called "OR WHERE“

• Primitives

• Variable: ?[a-zA-Z]+ (for example ?a, ?myVar)

• Full IRI: <http://example.com>

• Prefixed IRI: [the prefix]:[the suffix]

• Literal: "this is a literal" (escape the character " inside a literal with \")

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

SPARQL-DL Query Examples

SELECT ?c WHERE { Class(?c) }

SELECT ?x WHERE { Transitive(?p),PropertyValue(<http://example.com#myClass>, ?p, ?x)

}

PREFIX wine: http://w3.org/TR/2003/PR-owl-guide-20031209/wine#SELECT ?i WHERE {

Type(?i, wine:PinotBlanc)} OR WHERE {

Type(?i, wine:DryRedWine) }

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

Query Comparison: SPARQL x SPARQL-DL

• SPARQLPREFIX wine: http://w3.org/TR/2003/PR-owl-guide-20031209/wine#SELECT ?wine ?region WHERE {

?wine wine:locatedIn ?region }

• SPARQL-DLPREFIX wine: http://w3.org/TR/2003/PR-owl-guide-20031209/wine#SELECT ?wine ?region WHERE {

PropertyValue(?wine, wine:locatedIn, ?region) }

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

Query Comparison: SPARQL x SPARQL-DL

• SPARQLPREFIX wine: http://w3.org/TR/2003/PR-owl-guide-20031209/wine#SELECT ?wine ?flavor WHERE {

?wine wine:locatedIn wine:NewZealandRegion .?wine wine:hasFlavor ?flavor

}

• SPARQL-DLPREFIX wine: http://w3.org/TR/2003/PR-owl-guide-20031209/wine#SELECT ?wine ?flavor WHERE {

PropertyValue(?wine, wine:locatedIn, wine:NewZealandRegion),

PropertyValue(?wine, wine:hasFlavor, ?flavor) }

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

Query Comparison: SPARQL x SPARQL-DL

• SPARQLPREFIX wine: http://w3.org/TR/2003/PR-owl-guide-20031209/wine#SELECT ?wine WHERE {

{ ?wine wine:locatedIn wine:NapaRegion

}UNION{

?wine wine:locatedIn wine:NewZealandRegion }

}

• SPARQL-DLPREFIX wine: http://w3.org/TR/2003/PR-owl-guide-20031209/wine#SELECT ?wine WHERE {

PropertyValue(?wine, wine:locatedIn, wine:NapaRegion) } OR WHERE {

PropertyValue(?wine, wine:locatedIn, wine:NewZealandRegion ) }

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

Reasoner's Support for DL

Pellet RacerPro FaCT++ HermiT

OWL-DL Support Yes Yes Yes Yes

OWL 2 Support Yes Yes Partially Yes

Supported expressivity SROIQ(D) SRIQ(D-) SROIQ(D) SHOIQ+

Reasoning algorithm Tableau Tableau Tableau Hypertableau

Rule Support Yes (SWRL - DL Safe Rules)

Yes (SWRL - not fully supported) & own rule format

No Yes (SWRL - DL Safe Rules)

LicensingFree / open-source

& Non-Free/ closed-source

Non-Free/ closed-source Free / open-source Free / open-source

Adapted from http://en.wikipedia.org/wiki/Semantic_reasoner

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

Practice

• Eclipse IDE (Java Project)http://eclipse.org

• OWL APIhttp://derivo.de/en/resources/owl-api.html

• SPARQL-DL APIhttp://derivo.de/en/resources/sparql-dl-api.html

• HermiT OWL Reasonerhttp://hermit-reasoner.com

• Wine Ontologyhttp://krono.act.uji.es/Links/ontologies/wine.owl

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

PracticeQueries

• PrefixPREFIX wine: <http://krono.act.uji.es/Links/ontologies/wine.owl#>

• Query 1SELECT ?class WHERE {

Class(?class) }

• Query 2SELECT ?subClass WHERE {

SubClassOf(?subClass, wine:Wine) }

• Query 3SELECT ?wine WHERE {

PropertyValue(?wine, wine:locatedIn, wine:GermanyRegion) }

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

PracticeQueries

• Query 4SELECT ?wine ?region WHERE {

PropertyValue(?wine, wine:locatedIn, ?region) }

• Query 5SELECT ?wine ?region WHERE {

Type(?wine, wine:Wine), PropertyValue(?wine, wine:locatedIn, ?region)

}

• Query 6SELECT ?wine ?flavor WHERE {

PropertyValue(?wine, wine:locatedIn, wine:NewZealandRegion),

PropertyValue(?wine, wine:hasFlavor, ?flavor) }

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

PracticeQueries

• Query 7 (DISTINCT Keyword)SELECT DISTINCT ?producer ?wine WHERE {

PropertyValue(?producer, wine:producesWine, ?wine) }

• Query 8 (OR WHERE Statement)SELECT ?wine WHERE {

Type(?wine, wine:PinotBlanc) } OR WHERE {

Type(?wine, wine:DryRedWine) }

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

PracticeOWL API + SPARQL-DL API + HermiT Reasoner

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>

// OntologyIRI ontIRI = IRI.create("http://krono.act.uji.es/Links/ontologies/wine.owl");OWLOntologyManager ontManager = OWLManager.createOWLOntologyManager();OWLOntology ont = ontManager.loadOntologyFromOntologyDocument(ontIRI);

// ReasonersOWLReasoner rStructural = new StructuralReasonerFactory().createReasoner(ont);OWLReasoner rHermit = new Reasoner.ReasonerFactory().createReasoner(ont);

// QueryQueryEngine queryEngine = QueryEngine.create(ontManager, rHermit);Query query = Query.create(query1);

String result = queryEngine.execute(query).toString();

System.out.println(result);

References

• HORROCKS, I.; PEREZ-URBINA, H.; MOTIK, BORIS. Efficient Query Answering for OWL 2. 2009.

• HORROCKS, I.; PATEL-SCHNEIDER, P. F.; MCGUINNESS, D. L.; WELTY, C. A. OWL: a Description Logic Based Ontology Language for the Semantic Web. 2007.

• HORROCKS, I.; KOLLIA, I.; GLIMM, B. SPARQL Query Answering over OWL Ontologies. 2011.

• KREMEN1, P.; SIRIN, E. SPARQL-DL Implementation Experience. 2008.

• PARSIA, B.; SIRIN, E. SPARQL-DL: SPARQL Query for OWL-DL. 2007.

• GLIMM, B.; KRÖTZSCH, M. SPARQL Beyond Subgraph Matching. 2010.

• GRAU, B. C.; HORROCKS, I.; MOTIK, B.; PARSIA, B.; PATEL-SCHNEIDER, P.; SATTLER, U. OWL 2: The Next Step for OWL. 2008.

• DOMINGUE, J.; FENSEL, D.; HENDLER, J. A. Handbook of Semantic Web Technologies. 2011.

• ALLEMANG, D.; HENDLER J. A. Semantic Web for the Working Ontologist. 2011.

• ANTONIOU, G.; VAN HARMELEN, F. Semantic Web Primer. 2008.

• HEBELER, J.; FISHER, M.; BLACE, R.; PEREZ-LOPEZ, A.; DEAN, M. Semantic Web Programming. 2009.

SPARQL-DL: Theory & Practice | Adriel Café <aac3@cin.ufpe.br>