SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.
-
Upload
raymond-braggs -
Category
Documents
-
view
216 -
download
0
Transcript of SPARQL Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014.
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.
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
OWL2O Introduces 3 subsets of the
language: - EL – polynomial time reasoning
complexity- QL – tailored to work with databases- RL - a rule subset of OWL2
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:
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 .
(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)_______________________________________
OWL abstract syntax
e.g. here is a subset:
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.
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 ≡ ⊥
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.)
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.
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.
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
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.
SPARQL queries
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}
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}