SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

20
SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014

Transcript of SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Page 1: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

SPARQL

Dimitar Kazakov,with references to material by Noureddin Sadawi

ARIN, 2014

Page 2: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Ontologies so far: RDFO RDF: a conceptual approach to

representing data as triples: subject – predicate – object. It’s a family of specifications, where…

O Classes and properties vary: rdf vs rdfs

O Various data serialisation formats:- RDF/XML- Turtle- JSON-LD, etc.

Page 3: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

OWLO A family of ontology languages with

clearly defined semanticsO Syntax of: OWL Lite ⊂ OWL DL ⊂ OWL

FullO OWL Lite meant to restrict constructs

for comp. efficiency, but expressiveness (hence complexity) ≈ OWL DL, just more awkward.

O OWL DL: tailored to be a complete and decidable logic, with practical reasoning algs

Page 4: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

OWL2O Introduces 3 subsets of the

language: - EL – polynomial time reasoning

complexity- QL – tailored to work with databases- RL - a rule subset of OWL2

Page 5: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Abstract syntax vs. serialisation

O At the most abstract level one uses the notation of the appropriate class of logic

O This can be saved in a variety of ways, e.g. see Protégé menu:

Page 6: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Ease of reading and expressivity can vary:O OWL2 Functional Syntax:Ontology(<http://example.com/Pop.owl> Declaration( Class( :Pop ) ))

O RDF/XML syntax:<rdf:RDF ...> <owl:Ontology rdf:about=””/> <owl:Class rdf:about=”#Pop"/></rdf:RDF>O RDF/Turtle <http://example.com/Pop.owl> rdf:type owl:Ontology . :Pop rdf:type owl:Class .

Page 7: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

(cont.)O Manchester Syntax:Ontology: <http://example.com/Pop.owl>Class: Pop______________________________________

These details are hidden away when using a GUI tool, such as Protégé, to implement the ontology.

It’s still important to understand the abstract syntax, which appears in the GUI, e.g.

Student Person (a description)⊑Father ≡ Man ⊓ Parent (a definition)_______________________________________

Page 8: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

OWL abstract syntax

e.g. here is a subset:

Page 9: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Protégé 3.x vs 4.xO Use 3.x if application cannot abstract

away from working directly with the RDF triples; or to have built-in support for SPARQL to query the database. Multi-user support, database storage possible. Supports OWL1.0 (DL, OWL Full possible.)

O Use 4.x to work in pure OWL (2.0), with better optimisations of parser and memory use. No SPARQL, no DB support, no multi-u.

Page 10: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Building an ontology with Protégé: a case study

Student Person⊑ Lecturer Person⊑Student Lecturer ≡ ⊓ ⊥(i.e.: disjoint(Student,Lecturer) )CSModule Module⊑ MathsModule Module⊑CSModule ⊓ MathsModule ≡ ⊥

Page 11: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Building an ontology with Protégé: a case study

Object properties:Studies Domain = Student; Range = ModuleTeaches Domain = Lecturer; Range = Module

Data properties:Mapping individuals to values (strings for names and acronyms, integers for student ID.)

Page 12: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.
Page 13: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Publishing the ontologyO Choose the URL where the file will

be placed from the start and enter it in Protégé;

O Put the file at that URL (e.g. home Web dir) when ready.

Page 14: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

SPARQL QueriesO A query language for ontologiesO Protégé 3.x has built-in support (not

in 4.x)O We’ll save our DB in RDF/XML

format…O …then use the Apache Jena-Fuseki

SPARQL servlet to access it.

Page 15: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Apache Jena-FusekiO Serving RDF data over HTTPO Supports SPARQL for querying and

updatingO Get from

http://jena.apache.org/download/- jena-fuseki-1.0.1-distribution.tar.gz- tar –zxf <the above>- cd jena-fuseki-1.0.1- ./fuseki-server -update --mem /ds- open a browser and go to localhost:3030

Page 16: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

Apache Jena-Fuseki- Control panel -> /ds [Select]- File upload (to upload you local DB)- you can then use SPARQL, e.g.

SELECT * WHERE {?x ?y ?z}to see the entire DB.

Page 17: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

SPARQL queries

Page 18: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.
Page 19: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

More examplesO What does this do?

PREFIX uni: <http://www.cs.york.ac.uk/~kazakov/ontologies/2014/3/Student-2.owl#>SELECT ?student WHERE {?student uni:Studies uni:CS101}

Page 20: SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.

More examplesO What does this do?

PREFIX uni: <http://www.cs.york.ac.uk/~kazakov/ontologies/2014/3/Student-2.owl#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>SELECT ?classWHERE {?class rdfs:subClassOf uni:Person}