sparql stands for sparql protocol and rdf query language...

19
1 Knowledge Representation VII - IKT507 SPARQL stands for SPARQL Protocol And RDF Query Language Jan Pettersen Nytun, UiA This sentence is false!

Upload: doanbao

Post on 24-May-2018

236 views

Category:

Documents


2 download

TRANSCRIPT

1

Knowledge RepresentationVII - IKT507

SPARQL stands for SPARQL

Protocol And RDF Query Language

Jan Pettersen Nytun, UiA

This sentence is false!

S

OP

Jan Pettersen Nytun, UiA, page 2

The Semantic Web Stack

Hierarchy of languages,

where each layer exploits

and uses capabilities of

the layers below.

/ XML Schema

S

OP

[4]: RDF provides a simple way to represent distributed data. The triple is the simplest way to represent a named connection between two things...The standard way to access RDF data uses a query language called SPARQL…

SPARQL query patterns are represented in a variant of Turtle.

Jan Pettersen Nytun, UiA, page 3

5

6

7

S

OPA Simple Query [3]

Find the title of a book from the given data

graph

• Typically it contains a set of triple patterns called a basic graph pattern, where subject, predicate and object may be a variable.

• A basic graph pattern matches a subgraph of the RDF data when RDF terms from that subgraph may be substituted for the variables.

Jan Pettersen Nytun, UiA, page 8

RDF data:<http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> "SPARQL Tutorial" ..

SPARQL query:SELECT ?title WHERE {

<http://example.org/book/book1> <http://purl.org/dc/elements/1.1/title> ?title . }

basic graph patternVariable

Query result:title

"SPARQL Tutorial"

S

OP

Multiple

Matches [3]

The following two subsets of the dataprovided the two matches:

10

11

@prefix : <http://www.semanticweb.org/janpn/ontologies/2014/8/parenthood#> .

...

<http://www.semanticweb.org/janpn/ontologies/2014/8/parenthood> rdf:type owl:Ontology .

:hasSon rdf:type owl:ObjectProperty .

:Female rdf:type owl:Class ;

rdfs:subClassOf :Human .

:Human rdf:type owl:Class .

:Male rdf:type owl:Class ;

rdfs:subClassOf :Human .

:HaraldVofNorway rdf:type owl:NamedIndividual ;

rdfs:label "Harald V" .

Jan Pettersen Nytun, UiA,, page 12

Given Ontology - Example

S

OP Selecting All Triples

Jan Pettersen Nytun, UiA, Ontologies, page 13

S

OP PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

PREFIX owl: <http://www.w3.org/2002/07/owl#>

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?subject ?predicate ?object

WHERE { ?subject ?predicate ?object. }

ORDER BY ?subject

Jan Pettersen Nytun, UiA, Ontologies, page 14

S

OP CONSTRUCT Statement

Jan Pettersen Nytun, UiA, page 15

PREFIX : <http://www.semanticweb.org/janpn/ontologies/2014/8/parenthood#>PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX owl: <http://www.w3.org/2002/07/owl#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>construct { ?son :hasParent ?father}

WHERE { ?father :hasSon ?son. }

S

OP rdfs:subClassOfThe members of one class (the subclass) are also members of the other (the super class).

Tools like reasoners “understands” the semantics of subClassOf. It can also be described with SPARQL:

Jan Pettersen Nytun, UiA, 16

:Female rdf:type owl:Class ;rdfs:subClassOf :Human .

construct { ?resourse rdf:type ?theSuperClass}WHERE { ?theSubClass rdfs:subClassOf ?theSuperClass.

?resourse rdf:type ?theSubClass }

S

OPrdfs:subProperty

OfThe pair related by one property (the sub property) are included in the other (the super property).

It can also be described with SPARQL:

Jan Pettersen Nytun, UiA, 17

:hasSon rdf:type owl:ObjectProperty ; rdfs:subPropertyOf :isParentTo .

S

OPrdfs:subProperty

OfThe pair related by one property (the sub property) are included in the other (the super property).

It can also be described with SPARQL:

Jan Pettersen Nytun, UiA, 18

:hasSon rdf:type owl:ObjectProperty ; rdfs:subPropertyOf :isParentTo .

construct { ? subject ?theSuperProperty ? object }WHERE { ?theSubProperty rdfs:subPropertyOf ?theSuperProperty .

?subject ?theSubProperty ?object }

S

OP References

Jan Pettersen Nytun, UIA, page 19

[1] Book: David Poole and Alan Mackworth, Artificial Intelligence: Foundations of Computational Agents, Cambridge University Press, 2010, http://artint.info/

[2] http://www.w3.org/TR/swbp-n-aryRelations/

[3] SPARQL Query Language for RDF, W3C Recommendation 15 January 2008http://www.w3.org/TR/rdf-sparql-query/

[4] Semantic Web for the Working Ontologist, Second Edition: Effective Modeling in RDFS and OWL, May 20, 2011, by Dean Allemang, James Hendler