200 likes | 380 Views
SPARQL. Dimitar Kazakov, with references to material by Noureddin Sadawi ARIN, 2014. Ontologies so far: RDF. RDF: a conceptual approach to representing data as triples: subject – predicate – object. It’s a family of specifications, where… Classes and properties vary: rdf vs rdfs
E N D
SPARQL Dimitar Kazakov, with references to material by NoureddinSadawi ARIN, 2014
Ontologies so far: RDF • RDF: a conceptual approach to representing data as triples: subject – predicate – object. It’s a family of specifications, where… • Classes and properties vary: rdfvsrdfs • Various data serialisationformats: • RDF/XML • Turtle • JSON-LD, etc.
OWL • A family of ontology languages with clearly defined semantics • Syntax of: OWL Lite ⊂ OWL DL ⊂ OWL Full • OWL Lite meant to restrict constructs for comp. efficiency, but expressiveness (hence complexity) ≈ OWL DL, just more awkward. • OWL DL: tailored to be a complete and decidable logic, with practical reasoning algs
OWL2 • 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 • At the most abstract level one uses the notation of the appropriate class of logic • This can be saved in a variety of ways, e.g. see Protégé menu:
Ease of reading and expressivity can vary: • OWL2 Functional Syntax: Ontology(<http://example.com/Pop.owl> Declaration( Class( :Pop ) )) • RDF/XML syntax: <rdf:RDF ...> <owl:Ontologyrdf:about=””/> <owl:Classrdf:about=”#Pop"/> </rdf:RDF> • RDF/Turtle <http://example.com/Pop.owl> rdf:typeowl:Ontology . :Pop rdf:typeowl:Class.
(cont.) • 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) _______________________________________
Protégé 3.x vs 4.x • 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.) • 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 = Module Teaches Domain = Lecturer; Range = Module Data properties: Mapping individuals to values (strings for names and acronyms, integers for student ID.)
Publishing the ontology • Choose the URL where the file will be placed from the start and enter it in Protégé; • Put the file at that URL (e.g. home Web dir) when ready.
SPARQL Queries • A query language for ontologies • Protégé 3.x has built-in support (not in 4.x) • We’ll save our DB in RDF/XML format… • …then use the Apache Jena-Fuseki SPARQL servlet to access it.
Apache Jena-Fuseki • Serving RDF data over HTTP • Supports SPARQL for querying and updating • 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.
More examples • 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 examples • 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 ?class WHERE {?class rdfs:subClassOfuni:Person}