Sparql Tutorial I

  • July 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Sparql Tutorial I as PDF for free.

More details

  • Words: 1,720
  • Pages: 53
SPARQL TUTORIAL BY AMNA BASHARAT

7th October , 2008 FAST‐NU , Islamabad

Self  Reading ƒ Value Partitions  ‐You Must Conver! ƒ Covering Axioms  C i i ƒ Using the Property Matrix Wizard  ƒ Cardinality Restrictions ƒ Datatype Properties ƒ Creating Individuals ƒ Namespaces and Ontology Imports ƒ Enumerated Classes ƒ Annotation Properties p ƒ Open World Reasoning FAST – NU, Islamabad, Fall 2008

QUIZ!

Electronic Quizzes ƒ Generally MCQs or True/False ƒ If it is an open ended question then you are expected to answer it 

on your own. ƒ Go to www.Quizstar.4teachers.org ƒ Login using your username and password L i   i       d  d à You username and password have been created à They can be obtained from me or viewed in the course folder à Your Class is SWT

ƒ Enter your Details ƒ Change your password! ƒ Take the Quiz …when assigned! à Fixed Time

ƒ You can also view answers once the Quiz Expires! ƒ You may as well be given some assignments FAST – NU, Islamabad, Fall 2008

Trial Quiz! ƒ You must take the Trial Quiz today. ƒ The actual Quiz to be released very soon. ƒ Would give you essential practice before the 

upcoming Sessional II à Would require sound logical understanding of 

Ontologies. O l i à May Also require you to do things practically.

FAST – NU, Islamabad, Fall 2008

ABOUT  THE PROJECT

Next Deliverable ƒ Application/ Architecture  ƒ Ontology ƒ Reasoning Support ƒ Due Date : 9 9th October, 2008 ,

FAST – NU, Islamabad, Fall 2008

Guidelines for OWL Model ƒ

An OWL Model (well documented) containing the  ontology developed for the chosen business domain à The ontology is expected to contain between 40 and 50 

classes with a well‐defined taxonomy (i.e.,  class/subclass hierarchy), properties and conditions. 

à Examples of individual instances must be defined as 

well. 

ƒ Refer to the Guidelines Document for 

Coverage of OWL Constructs

FAST – NU, Islamabad, Fall 2008

Documentation of your Ontology ƒ The ontology should be complemented by a 

g documentation containing 

à à à à

design considerations and decisions The developed Taxonomy  comments and assumptions for a better understanding of  g the ontology and decisions  The document should be written in a clear and concise  manner.

ƒ List of Scenarios, Competency Questions  List of Scenarios  Competency Questions 

that your Ontology is capable of answering ƒ Reasoning Mechanisms, Classifications that  g , you have performed ƒ Limitations and Recommended  Modifications/ Enhancement to your  Ontology FAST – NU, Islamabad, Fall 2008

SPARQL TUTORIAL

RDF ƒ RDF is quite committed to Semantic Web. à Data model d l à Serialization by means of XML à Formal semantics F l  i

ƒ Still something is missing! à A standard query language. à A way for the queries and their respective results 

to be transported between applications /  services.

FAST – NU, Islamabad, Fall 2008

…result

SPARQL FAST – NU, Islamabad, Fall 2008

in a nutshell

Adapted from fabien, gandon, inria

RDF triple model 

is the first layer of the  semantic web standards FAST – NU, Islamabad, Fall 2008

SPARQL on top...

an RDF query language  and data access protocol FAST – NU, Islamabad, Fall 2008

SPARQL stands for

SPARQL Protocol and  RDF Query Language FAST – NU, Islamabad, Fall 2008

SPARQL in 3 parts

part 1: query language part 2: result format part 3: access protocol FAST – NU, Islamabad, Fall 2008

SPARQL query SELECT ... FROM ... WHERE { ... } FAST – NU, Islamabad, Fall 2008

SELECT clause

to identify the values to  be returned FAST – NU, Islamabad, Fall 2008

FROM clause

to identify the data  sources to query q y FAST – NU, Islamabad, Fall 2008

WHERE clause

the triple/graph pattern  to be matched against the  g triples/graphs of RDF FAST – NU, Islamabad, Fall 2008

WHERE clause a conjunction of triples:  { ?x rdf:type ex:Person ?x ex:name ?name }

FAST – NU, Islamabad, Fall 2008

PREFIX

to declare the schema  used in the query  q y FAST – NU, Islamabad, Fall 2008

example

: persons and their names

PREFIX ex: SELECT ?person ?name WHERE { ?person rdf:type ex:Person ?person ex:name ?name . }

FAST – NU, Islamabad, Fall 2008

Example or Result <sparql xmlns="http://www.w3.org/2005/sparql-results#" > http://inria.fr/schema#fg gandon

...

FAST – NU, Islamabad, Fall 2008

ASK

to check just if there is at  least one answer ; result is  ; "true" or "false" 

FAST – NU, Islamabad, Fall 2008

Example:  is there a person older than 17 ? PREFIX ex: ASK { ?person ex:age ?age FILTER (? (?age > 17) }

FAST – NU, Islamabad, Fall 2008

CONSTRUCT

return a specific RDF  graph for each result  g p FAST – NU, Islamabad, Fall 2008

return instances of adults for  Example:  persons older than 17 PREFIX ex: CONSTRUCT { ?person rdf:type ex:Adult } WHERE { ?person ex:age ?age FILTER (?age > 17) } FAST – NU, Islamabad, Fall 2008

SPARQL protocol

sending queries and their  results accross the web FAST – NU, Islamabad, Fall 2008

Example:

with HTTP Binding

GET /sparql/?query=<encoded query> HTTP/1.1 Host: www.inria.fr User-agent: my-sparql-client/0.1

FAST – NU, Islamabad, Fall 2008

Example:

with SOAP Binding

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<soapenv:Body> SELECT ?x ?p ?y WHERE {?x ?p ?y} / / p p

FAST – NU, Islamabad, Fall 2008

TAKE‐AWAY summary of SPARQL

SPARQL is... ... a query language ... ... a result format ...     lt f t  ... an access protocol ... p FAST – NU, Islamabad, Fall 2008

for RDF 

... 

SPARQL query language based on the triple model   ?x b d   th  t i l   d l   ? ?p ? ?y ? filters to add constraints optional parts and alternative parts FAST – NU, Islamabad, Fall 2008

SOME MORE EXAMPLES

SPARQL SPARQL = Query Language + Protocol + XML Results Format



Access and query RDF graphs



Product of the RDF Data Access Working Group



Status: W3C Candidate Recommendation

FAST – NU, Islamabad, Fall 2008

SPARQL Query: example PREFIX dc:

SELECT ?title2 WHERE { ?doc

dc:title

"SPARQL at speed" .

?doc

dc:creator

?c .

?docOther dc:creator

?c .

?docOther dc:title

?title2

}



On an abstracts/papers database: p p y g p p “Find other papers by the authors of a given paper.” FAST – NU, Islamabad, Fall 2008

SPARQL Query PREFIX dc: PREFIX foaf: f f PREFIX shop:

SELECT ?title2 WHERE {

?doc dc:title FILTER regex(?title,

?title . "SPARQL") .

?doc

?c .

dc:creator

?c foaf:name ?name . OPTIONAL { ?doc shop:price ?price } }



“Find books with ‘SPARQL’ in the title. Get the authors’ name and the  price (if available).” price (if available).



Multiple vocabularies FAST – NU, Islamabad, Fall 2008

Inference •

An RDF graph may be backed by inference − OWL, RDFS, application, rules OWL  RDFS  application  rules

:x rdf:type :C . :C rdfs:subClassOf :D .

PREFIX

rdf:



SELECT ?type WHERE { ?x rdf:type ?type . } -------| type | ======== | :C

|

| :D

|

-------FAST – NU, Islamabad, Fall 2008

DATA VIRTUALIZATION VIA  SPARQL

SPARQL : Data Virtualization ƒ SPARQL as integrator  à Data remains where it is i h i i à Existing applications untouched à data appears as RDF, remap query to native form d      RDF         i  f

ƒ SPARQL to SQL ‚ Direct mapping of tables i i f bl  Semi‐automatic generation of mapping  SquirrelRDF (also does LDAP)

‚ Modelled: D2RQ  High‐quality mapping, manually developed

FAST – NU, Islamabad, Fall 2008

Federated Query Single Point of Access g SPARQL Que ery

• Inputs: Inp ts – Service Description – Information 

Directory – Request

SPA ARQL Query

FAST – NU, Islamabad, Fall 2008

SP PARQL Query Q

– Unified results

SPA ARQL Query

• Outputs:

Query Broker SPARQL => SPARQL

RDF

Corp LDAP

Doc DB

Access Multiple Sources PREFIX dc: PREFIX ldap:



PREFIX foaf:

SELECT ?name ?name2 { ?doc

dc:title

?title .

FILTER regex(?title, “SPARQL”) . ?doc

dc:creator

?reseacher .

?researcher

ldap:email

?email .

?researcher

ldap:name

?name

}



“Find the name and email addresses of authors of a paper”



Query tech reports first, then go to LDAP for more information.



SQL database; LDAP server FAST – NU, Islamabad, Fall 2008

Access Multiple Sources PREFIX dc: p PREFIX ldap:

p p p p p

PREFIX foaf:

SELECT ?name ?name2 { ?doc

dc:title

?title .

?doc

dc:creator

?reseacher .

?researcher

ldap:email

<mailto:[email protected]> .

}



“Find the reports written by the person with “Fi d th   t   itt  b  th     ith email address  [email protected]



Go to LDAP first  then the reports database Go to LDAP first, then the reports database FAST – NU, Islamabad, Fall 2008

SPARQL : Protocol SPARQL =  Query Language + Protocol + XML Results Format



One request type expressed in WSDL



HTTP and SOAP



Results: fixed XML form for further transformation

FAST – NU, Islamabad, Fall 2008

Links ƒ Jena: Java and .Net Semantic Web Framework à http://jena.sourceforge.net/  à RDF, SPARQL, OWL, Rules à Open source: BSD‐license O    BSD li ‚ Commercial and non‐commercial use

ƒ SPARQL Query à http://jena.sourceforge.net/ARQ

ƒ SPARQL Protocol à http://www.joseki.org

ƒ SquirrelRDF: Access legacy SQL: à http://jena.sourceforge.net/SquirrelRDF FAST – NU, Islamabad, Fall 2008

SPARQL Update INSERT { book:newBook dc:title Q “More about SPARQL” . book:newBook dc:creator [ foaf:mbox foaf:name

<mailto:alex@example> ; “Alex Author”

]

} DELETE { ?book dc:title

?title ;

dc:creator ?c } WHERE { ?book dc:title ?title ; dc:creator ?c FILTER regex(?title, regex(?title “first first edition”) edition ) }

• Future HP proposal to W3C F t  HP  l t  W C FAST – NU, Islamabad, Fall 2008

DUA ONTOLOGY

Taxonomy Dua

Qurani Duas

Duas To Seek  K Knowledge l d

DuasToSeekParadise

FAST – NU, Islamabad, Fall 2008

Masnoon Duas

….

RDF Model of Duas isRelatedTo Prophet Dua

containsDua

hasRelatedDua

isContainedIn

Surah

FAST – NU, Islamabad, Fall 2008

hasTheme

Theme

SAMPLE SPARQL QUERIES

Search Dua with a Particular Theme PREFIX dua:  SELECT ?D ?theme WHERE { ?D dua:hasTheme ?theme.}

FAST – NU, Islamabad, Fall 2008

Related Documents

Sparql Tutorial I
July 2020 1
Sparql
June 2020 0
Sparql-2016
August 2019 45
Tutorial Bf - Apendice I
November 2019 8