sparql tutorial ii & iii

91
SPARQLTUTORIAL SPARQLTUTORIAL BY AMNA BASHARAT 7 th October , 2008 FASTNU , Islamabad

Upload: api-19981384

Post on 18-Nov-2014

216 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SPARQL Tutorial II & III

SPARQL TUTORIALSPARQL TUTORIALBY AMNA BASHARAT

7thOctober , 2008FAST‐NU , Islamabad

Page 2: SPARQL Tutorial II & III

in a nutshellin a nutshellin a nutshellin a nutshell

Adapted from fabien, gandon, inria

Page 3: SPARQL Tutorial II & III

RDF triple model is the first layer of the is the first layer of the semantic web standards

FAST – NU, Islamabad, Fall 2008

Page 4: SPARQL Tutorial II & III

SPARQL on top...an RDF query language an RDF query language and data access protocol

FAST – NU, Islamabad, Fall 2008

Page 5: SPARQL Tutorial II & III

SPARQLstands forSPARQL Protocol and SPARQL Protocol and RDF Query Language

FAST – NU, Islamabad, Fall 2008

Page 6: SPARQL Tutorial II & III

SPARQL in 3 partspart 1: query languagepart 1: query languagepart 2: result format

FAST – NU, Islamabad, Fall 2008

part 3: access protocol

Page 7: SPARQL Tutorial II & III

SPARQL querySELECTSELECT ...FROM ...

FAST – NU, Islamabad, Fall 2008

WHERE { ... }

Page 8: SPARQL Tutorial II & III

SELECT clause

to identify the values to to identify the values to be returned

FAST – NU, Islamabad, Fall 2008

Page 9: SPARQL Tutorial II & III

FROM clause

to identify the data to identify the data sources to query

FAST – NU, Islamabad, Fall 2008

q y

Page 10: SPARQL Tutorial II & III

WHERE clause

the triple/graph pattern the triple/graph pattern to be matched against the 

FAST – NU, Islamabad, Fall 2008

gtriples/graphs of RDF

Page 11: SPARQL Tutorial II & III

WHEREclauseWHEREclausea conjunction of triples: {?x rdf:type ex:Person?x ex:name ?name }}

FAST – NU, Islamabad, Fall 2008

Page 12: SPARQL Tutorial II & III

PREFIX

to declare the schema to declare the schema used in the query 

FAST – NU, Islamabad, Fall 2008

q y

Page 13: SPARQL Tutorial II & III

example : persons and their names

PREFIX ex: <http://inria.fr/schema#>SELECT ?person ?nameWHERE {WHERE {?person rdf:type ex:Person?person ex:name ?name?person ex:name ?name .}

FAST – NU, Islamabad, Fall 2008

Page 14: SPARQL Tutorial II & III

Example or Result

<?xml version="1.0"?> <sparql xmlns="http://www.w3.org/2005/sparql-results#" ><head><variable name="person"/>

<variable name="name"/> </head><results ordered="false" distinct="false"><results ordered="false" distinct="false"><result><binding name="person">

<uri>http://inria.fr/schema#fg</uri>

</binding>

<binding name="name">

<literal>gandon</literal><literal>gandon</literal>

</binding></result>

<result>

FAST – NU, Islamabad, Fall 2008

<result> ...

Page 15: SPARQL Tutorial II & III

FILTER

to add constraints  to the to add constraints  to the graph pattern (e.g., 

FAST – NU, Islamabad, Fall 2008

g p p ( g ,numerical like X>17 ) 

15

Page 16: SPARQL Tutorial II & III

Example: persons at least 18‐year old

PREFIX ex: <http://inria fr/schema#>PREFIX ex: <http://inria.fr/schema#>SELECT ?person ?nameWHERE {?person rdf:type ex:Person?person ex:name ?name .

?person ex:age ?age .

FILTER (?age > 17)FILTER (?age > 17)}

FAST – NU, Islamabad, Fall 2008 16

Page 17: SPARQL Tutorial II & III

FILTER can use many operators  functions (e g  operators, functions (e.g., regular expressions), and 

FAST – NU, Islamabad, Fall 2008

even users' extensions17

Page 18: SPARQL Tutorial II & III

OPTIONAL

to make the matching of a to make the matching of a part of the pattern 

FAST – NU, Islamabad, Fall 2008

p poptional 

18

Page 19: SPARQL Tutorial II & III

Example:: retrieve the age if available

PREFIX e <htt //i i f / h #>PREFIX ex: <http://inria.fr/schema#>SELECT ?person ?name ?ageWHERE {WHERE {?person rdf:type ex:Person?person ex:name ?name .

OPTIONAL { ?person ex:age ?age }} }

FAST – NU, Islamabad, Fall 2008 19

Page 20: SPARQL Tutorial II & III

UNION

to give alternative to give alternative patterns in a query 

FAST – NU, Islamabad, Fall 2008

p q y

20

Page 21: SPARQL Tutorial II & III

Example: explicit or implicit adults 

PREFIX ex: <http://inria.fr/schema#>SELECT ?nameWHERE {WHERE {?person ex:name ?name .

{{ ?person rdf:type ex:Adult }UNION{ ?person ex:age ?age{ ?person ex:age ?age FILTER (?age > 17) }

}}

FAST – NU, Islamabad, Fall 2008 21

}

Page 22: SPARQL Tutorial II & III

Sequence & modify 

ORDER BY to sortORDER BY to sortLIMIT result number

FAST – NU, Islamabad, Fall 2008

OFFSET rank of first result22

Page 23: SPARQL Tutorial II & III

Example: results 21 to 40 ordered by name

PREFIX ex: <http://inria.fr/schema#>SELECT ?person ?nameWHERE {?person rdf:type ex:Person?person ex:name ?name .}

ORDER BY ?nameLIMIT 20OFFSET 20

FAST – NU, Islamabad, Fall 2008 23

Page 24: SPARQL Tutorial II & III

UNBOUND

test a variable is not bound ; test a variable is not bound ; used for negation as failure

FAST – NU, Islamabad, Fall 2008 24

Page 25: SPARQL Tutorial II & III

Example: persons who are not known authors

PREFIX <htt //i i f / h #>PREFIX ex: <http://inria.fr/schema#>SELECT ?nameWHERE {?person ex:name ?name .

OPTIONAL { ?person ex:author ?x } ! b d( )FILTER ( ! bound(?x))

}

FAST – NU, Islamabad, Fall 2008 25

Page 26: SPARQL Tutorial II & III

NEGATION

is tricky and errors can easily be made. 

26

Page 27: SPARQL Tutorial II & III

PREFIX ex: <http://inria.fr/schema#>SELECT ?nameWHERE {WHERE {?person ex:name ?name .

?person ex:knows ?x?person ex:knows ?x FILTER ( ?x != "Java" )}

FAST – NU, Islamabad, Fall 2008? does this find persons who do not know "java" ?

27

Page 28: SPARQL Tutorial II & III

NO!  also persons who know something else !

PREFIX ex: <http://inria.fr/schema#>SELECT ?nameWHERE {?person ex:name ?name .

?person ex:knows ?x FILTER ( ?x != "Java" )}

Amna ex:knows "Java"

Amna ex:knows "C++"

FAST – NU, Islamabad, Fall 2008 28

Amna is a answer...

Page 29: SPARQL Tutorial II & III

YES! persons who are not known to know "java" ... negation of an option...

PREFIX ex: <http://inria.fr/schema#>SELECT ?nameWHERE {?person ex:name ?name .

OPTIONAL { ?person ex:knows ?x

FILTER ( ?x = "Java" ) } !FILTER ( ! bound(?x) )

}

FAST – NU, Islamabad, Fall 2008 29

Page 30: SPARQL Tutorial II & III

ASK

to check just if there is at to check just if there is at least one answer ; result is 

FAST – NU, Islamabad, Fall 2008

;"true" or "false" 

Page 31: SPARQL Tutorial II & III

Example:  is there a person older than 17 ?

PREFIX ex: <http://inria.fr/schema#>ASK

{?person ex:age ?age FILTER (? > 17)FILTER (?age > 17) }

FAST – NU, Islamabad, Fall 2008

Page 32: SPARQL Tutorial II & III

CONSTRUCT

return a specific RDF return a specific RDF graph for each result 

FAST – NU, Islamabad, Fall 2008

g p

Page 33: SPARQL Tutorial II & III

Example:  return instances of adults for persons older than 17

PREFIX ex: <http://inria.fr/schema#>CONSTRUCTCONSTRUCT

{

?person rdf:type ex:Adult

}

WHERE

{?person ex:age ?age FILTER (?age > 17) }

FAST – NU, Islamabad, Fall 2008

}

Page 34: SPARQL Tutorial II & III

SPARQL protocol

sending queries and their sending queries and their results accross the web

FAST – NU, Islamabad, Fall 2008

Page 35: SPARQL Tutorial II & III

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

Page 36: SPARQL Tutorial II & III

Example: with SOAP Binding

<?xml version="1.0" encoding="UTF-8"?>

<soapenv:Envelopexmlns: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>

<query-request xmlns="http://www.w3.org/2005/09/sparql-<query request xmlns http://www.w3.org/2005/09/sparqlprotocol-types/#">

<query>SELECT ?x ?p ?y WHERE {?x ?p ?y}</query>

/</query-request>

</soapenv:Body>

</soapenv:Envelope>

FAST – NU, Islamabad, Fall 2008

/ p p

Page 37: SPARQL Tutorial II & III

SPARQL as a Protocol

A way of communication between parties th t   SPARQL  ithat run SPARQL queries.Defining a way of invoking the service. Bindings of a transport protocol for that goal.

FAST – NU, Islamabad, Fall 2008 37

Page 38: SPARQL Tutorial II & III

SPARQL Protocol (1)

WSDL description file:i i f h lDescription of the protocol.

Not for human understanding.

bi diHTTP binding:Specify how to encode SPARQL queries in URLs ith GET  d POST  th d  with GET and POST methods. 

SOAP binding:S if   h  SOAP   f  Specify the SOAP message format (XML message exchange format for queries)

FAST – NU, Islamabad, Fall 2008 38

Page 39: SPARQL Tutorial II & III

WSDL Description file

WSDL description file: (HTTP binding part)bi di   " Htt " <binding name="queryHttp" interface="tns:SparqlQuery“  >… >

<fault name="MalformedQuery" whttp:zode="400"/> <!‐‐ the GET binding for query operation ‐‐><!‐‐ the GET binding for query operation ‐‐><operation ref="tns:query" whttp:method="GET" whttp:inputSerialization=“ " />whttp:inputSerialization= …  />

</binding> 

FAST – NU, Islamabad, Fall 2008 39

Page 40: SPARQL Tutorial II & III

SPARQL Protocol (2)

Interface SparqlQueryl iOnly one operation: query

For transferring string query

D t  t   i  XML  hData types: via XML schemaBindings: HTTP / SOAP binding for invokable operationsoperations.

A service must support SparqlQuery interfaceinterface

support the bindings as described in the WSDL.

FAST – NU, Islamabad, Fall 2008 40

Page 41: SPARQL Tutorial II & III

SPARQL Protocol Examples

Examples after we cover SPARQL Query L  f  RDFLanguage for RDF.

FAST – NU, Islamabad, Fall 2008 41

Page 42: SPARQL Tutorial II & III

SPARQL Query Language

A standard query language in the form of i   i t th  RDF d t  expressive query against the RDF data 

model…D t    lData access languageGraph patternsPowerful than XML queries in some aspects

FAST – NU, Islamabad, Fall 2008 42

Page 43: SPARQL Tutorial II & III

SPARQL Query Language (1)

SQL:SQL:Internals of DB (tables, fields, data, meaning)Impossible to query databases on the Impossible to query databases on the WILDWILDWEB.

So  what does SPARQL propose?So, what does SPARQL propose?URIs.Querying databases globallyQuerying databases globally.Combining data globally.Value of data grows exponentially with the ways 

FAST – NU, Islamabad, Fall 2008 43

Value of data grows exponentially with the ways you combine it.

Page 44: SPARQL Tutorial II & III

The Wild Wild Web

SQL SPARQLSQL SPARQLXML

FAST – NU, Islamabad, Fall 2008 44

Page 45: SPARQL Tutorial II & III

SPARQL Query Language (2)

Data structure definitions are being  d l d  ld id  i    di t ib t d developed worldwide in a distributed manner.C   t l i  (D bli  C  F f  Common ontologies (Dublin Core, Foaf, DOAP, etc.)A d b   bli h   h   l i  i  A database publishes the ontologies it exports toAn application queries it using those ontologies. 

FAST – NU, Islamabad, Fall 2008 45

Page 46: SPARQL Tutorial II & III

Power of SPARQL Illustrated

Ask fotograf.com if it has a picture which t h     t i t   h   titl  matches some constraints such as title, 

date, size, and some other tag…Th   k  l  f  URL  i   l ti  t  th  Then ask google for URLs in relation to the tag we specified.A d    h   l   f  h    And turn the results of these two uncoordinated data as an RSS feed on your sitesite.All this in just two‐three SPARQL queries.

FAST – NU, Islamabad, Fall 2008 46

Page 47: SPARQL Tutorial II & III

Power of SPARQL (2)

Ask music cds of price less than 10You can run this query against hepsiburada.com, amazon, e‐bay, itti idi       th   ll     th gittigidiyor.com or any other seller on earth 

who has a website and a database.N   ll   d     h   h i  d bNo seller needs to change their databases.Seller needs: Conversion layer between ontologies and database.Client needs: connectivity framework (like 

FAST – NU, Islamabad, Fall 2008

JDBC) for java.47

Page 48: SPARQL Tutorial II & III

Power of SPARQL (2) Imp.

PREFIX dc: htt // l /d / l t / / PREFIX <http://purl.org/dc/elements/1.1/> PREFIX 

ns: <http://example.org/ns#>SELECT ?titl  ? i  SELECT ?title ?price WHERE { 

?x ns:price ?price ?x ns:price ?price .FILTER (?price < 10) . ?x dc:title ?title   ?x dc:title ?title . } 

FAST – NU, Islamabad, Fall 2008 48

Page 49: SPARQL Tutorial II & III

SPARQL Syntax ‐brief‐1

URIsi<URI> in < >

or@PREFIX prefix: <http://....>fi  f  f ll URIprefix:name for full URI

Literals“Literal“ or “Literal”@language 

Blank Node_:name or [ ] for a Blank Node used just once 

FAST – NU, Islamabad, Fall 2008 49

Page 50: SPARQL Tutorial II & III

SPARQL Syntax ‐brief‐2

Triples and .:x :y :z . :t :q :s . 

Common predicate and subject::x :y :z, :t .which is the same as :x :y :z . :x :y :t . 

Common subject:RDF Collections

:x :y ( :z :t :q :s )which is short for many triples (as lists in LISP)

FAST – NU, Islamabad, Fall 2008 50

Page 51: SPARQL Tutorial II & III

A walkthrough example illustrating the power of SPARQL

XML/SQL    SPARQL

FAST – NU, Islamabad, Fall 2008 51

Page 52: SPARQL Tutorial II & III

Walkthrough example (1xml)

<Person><name>Henry Story</name><mbox>[email protected]</mbox><knows>

<Person>i<name>Tim Bray</name> 

<mbox>[email protected]</mbox> 

</Person><Person>

<name>Jonathan Story</name> <mbox>[email protected]</mbox> 

</Person> </knows>

</Person>

FAST – NU, Islamabad, Fall 2008 52

Page 53: SPARQL Tutorial II & III

Walkthrough example (1sparql)

[  a  :Person; :name "Henry Story"; :mbox <mailto:[email protected]>; 

:knows [  a :Person; :name "Tim Bray"; 

b   il b@ ]  :mbox <mailto:[email protected] ]; :knows [ a :Person; 

name "Jonathan Stor "  :name "Jonathan Story"; :mbox <mailto:[email protected]> ]; 

]   

FAST – NU, Islamabad, Fall 2008

] . 

53

Page 54: SPARQL Tutorial II & III

Graph representation

FAST – NU, Islamabad, Fall 2008 54

Page 55: SPARQL Tutorial II & III

Walkthrough example (2)

<AddressBook><Person> 

<name>Jonathan Story</name> <name>Jonathan Story</name> <mbox>[email protected]</mbox><address>

<Country>France</Country></address> 

</Person> <Person> <Person> 

<name>Tim Bray</name> <mbox>[email protected]</mbox>

dd<address><Country>Canada</Country>

</address> 

FAST – NU, Islamabad, Fall 2008 55

</Person></AddressBook> 

Page 56: SPARQL Tutorial II & III

Walkthrough example (2sparql)

[  a :Person; 

:name "Tim Bray"; :name "Tim Bray"; 

:mbox <mailto:[email protected]

:address [  a :Address; :address [  a :Address; 

:country "Canada"@en ]  ]. 

[  a :Person; [ ;

:name "Jonathan Story"; 

:mbox <mailto:[email protected]> :address [ 

a :Address; 

FAST – NU, Islamabad, Fall 2008

:country "France"@en ] 

]. 56

Page 57: SPARQL Tutorial II & III

Graph representation

FAST – NU, Islamabad, Fall 2008 57

Page 58: SPARQL Tutorial II & III

Walkthrough example (2)

These graphs can be merged into the f ll i   h  i ll  if th   b  following graph especially if the mbox relation is stated as being inverse functional 

FAST – NU, Islamabad, Fall 2008 58

Page 59: SPARQL Tutorial II & III

Graph representation(merged)

FAST – NU, Islamabad, Fall 2008 59

Page 60: SPARQL Tutorial II & III

Walkthrough example (2)

"Who does Henry know who lives in Canada, d  h t i  th i   il  dd ?" and what is their e‐mail address?" 

Can only be answered by aggregating data f  b th d t  from both documents. Can not be done using the XML query l   hi h    l   k   h  languages, which can only work on the surface of the document. 

FAST – NU, Islamabad, Fall 2008 60

Page 61: SPARQL Tutorial II & III

Walkthrough example (2sparql)

SELECT ?name ?mail WHERE { 

[a :Person; :name "Henry Story"; :knows [  :name ?name; [ ;

:mbox ?mail; :address [  a :Address;:address [  a :Address;

:country "Canada"@en; ] ] ]

FAST – NU, Islamabad, Fall 2008

] ] ].} 

61

Page 62: SPARQL Tutorial II & III

Walkthrough example (3sparql)

Names and websites of contributors to Pl tRDFPlanetRDF

PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?  ? b it  SELECT ?name ?website FROM <http://planetrdf.com/bloggers.rdf> WHERE { WHERE { 

?person foaf:weblog ?website ;foaf:name ?name . 

?website a foaf:Document } 

FAST – NU, Islamabad, Fall 2008 62

Page 63: SPARQL Tutorial II & III

Protocol Example (1)

PREFIX foaf: <http://xmlns.com/foaf/0.1/>PREFIX dc: <http://purl.org/dc/elements/1.1/>SELECT ?who ?g ?mboxFROM <http://my.example/publishers>FROM NAMED <http://my.example/alice>p // y p /FROM NAMED <http://my.example/bob>WHERE { WHERE { ?g dc:publisher ?who . GRAPH ?  { ?  f f b  ? b  } } 

FAST – NU, Islamabad, Fall 2008

GRAPH ?g { ?x foaf:mbox ?mbox } } 

63

Page 64: SPARQL Tutorial II & III

Protocol Example (1)

HTTP/1.1 200 OKd 8 GDate: Wed, 27 Dec 2005 12:48:25 GMT

Server: Apache/1.3.29 (Unix) PHP/4.3.4 DAV/1.0.3Connection: closeContent‐Type: 

application/sparql‐results+xml; charset=utf‐8l i<?xml version="1.0"?>

<sparql xmlns=“…">… …</sparql>

FAST – NU, Islamabad, Fall 2008 64

Page 65: SPARQL Tutorial II & III

References

http://www.w3.org/2004/Talks/17Dec‐l/i t / ll ht lsparql/intro/all.html

http://jena.sourceforge.net/ARQ/Tutorial/http://blogs.sun.com/roller/page/bblfishhttp://xmlarmyknife.org/api/rdf/sparqlhttp://xml.com/lpt/a/2005/11/16/introducing‐sparql‐querying‐semantic‐web‐tutorial.htmlhttp://www.w3.org/2005/Talks/12May‐

FAST – NU, Islamabad, Fall 2008

p 3 g 5 ySPARQL/all.html

65

Page 66: SPARQL Tutorial II & III

References (2)

http://www‐8 ib /d l k / l/lib /j128.ibm.com/developerworks/xml/library/j‐

sparql/htt // /TR/ df l t l/http://www.w3.org/TR/rdf‐sparql‐protocol/http://www.w3.org/2004/Talks/17Dec‐

l/i /sparql/intro/ex1.rqhttp://www.oreillynet.com/pub/wlg/7823

FAST – NU, Islamabad, Fall 2008 66

Page 67: SPARQL Tutorial II & III

THANK YOU…

For your attendance and patience

67

Page 68: SPARQL Tutorial II & III

ANY QUESTIONS?ANY QUESTIONS?

68

Page 69: SPARQL Tutorial II & III

DUAONTOLOGYDUAONTOLOGY

Page 70: SPARQL Tutorial II & III

Taxonomy

DuaDua

Qurani Duas Masnoon DuasQurani Duas Masnoon Duas

DuasTo Seek K l d DuasToSeekParadise

FAST – NU, Islamabad, Fall 2008

Knowledge DuasToSeekParadise ….

Page 71: SPARQL Tutorial II & III

RDF Model of Duas

containsDua isRelatedTo

DuaSurahProphet

isRelatedTo

isContainedInhasRelatedDua

hasTheme

Theme

FAST – NU, Islamabad, Fall 2008

Page 72: SPARQL Tutorial II & III

SAMPLE SPARQLQUERIESSAMPLE SPARQLQUERIES

Page 73: SPARQL Tutorial II & III

Search Duawith a Particular Theme

PREFIX dua: htt // ti b / t l i /<http://www.semanticweb.org/ontologies/2

008/9/DuaOntology.owl#>

SELECT ?D ?themeWHERE { ?D dua:hasTheme ?theme.}

FAST – NU, Islamabad, Fall 2008

Page 74: SPARQL Tutorial II & III

SAMPLE SPARQL QUERIESSAMPLE SPARQL QUERIES

é éTested with Protégé 3.3.1

Page 75: SPARQL Tutorial II & III

PizzaOntology

Querying for Classes

FAST – NU, Islamabad, Fall 2008

Page 76: SPARQL Tutorial II & III

SELECT ?subject ?objectWHERE { ?subject rdfs:subClassOf ?object }

FAST – NU, Islamabad, Fall 2008

Page 77: SPARQL Tutorial II & III

PREFIX p: <http://www.co‐d / t l i / i / / / 8/ iode.org/ontologies/pizza/2005/10/18/pizza.o

wl#>SELECT ? bj t ? bj tSELECT ?subject ?objectWHERE { ?subject rdfs:subClassOf ?object }

FAST – NU, Islamabad, Fall 2008

Page 78: SPARQL Tutorial II & III

PREFIX p: <http://www.co‐d / t l i / i / / / 8/ iode.org/ontologies/pizza/2005/10/18/pizza.o

wl#>SELECT ? bj t ? bj tSELECT ?subject ?objectWHERE { ?subject rdfs:subClassOf p:Pizza}

FAST – NU, Islamabad, Fall 2008

Page 79: SPARQL Tutorial II & III

PREFIX p: <http://www.co‐d / t l i / i / / / 8/ iode.org/ontologies/pizza/2005/10/18/pizza.o

wl#>SELECT ? bj t ? bj tSELECT ?subject ?objectWHERE { ?subject rdfs:subClassOf Pi T ip:PizzaTopping.

}

FAST – NU, Islamabad, Fall 2008

Page 80: SPARQL Tutorial II & III

PREFIX p: <http://www.co‐ode org/ontologies/pizza/2005/10/18/pizza oode.org/ontologies/pizza/2005/10/18/pizza.owl#>SELECT ?subject ?objectSELECT ?subject ?objectWHERE { ?subject rdfs:subClassOf p:DomainConcept.p p?subject owl:disjointWith ?object.

}

FAST – NU, Islamabad, Fall 2008

Page 81: SPARQL Tutorial II & III

Dua Ontology

Querying on Instance Data

FAST – NU, Islamabad, Fall 2008

Page 82: SPARQL Tutorial II & III

List all Duas with Corresponding themes

PREFIX dua: htt // ti b / t l i /<http://www.semanticweb.org/ontologies/2

008/9/DuaOntology.owl#>

SELECT ?D ?themeWHERE { ?D dua:hasTheme ?theme.}

FAST – NU, Islamabad, Fall 2008

Page 83: SPARQL Tutorial II & III

Example: List of Duas, their Themes which are contained in Surah Taha

PREFIX dua: htt // ti b / t l i /<http://www.semanticweb.org/ontologies/20

08/9/DuaOntology.owl#>

SELECT ?D ?themeWHERE { ?D dua:hasTheme ?theme.?D dua:hasSourceSurah dua:Taha. }

FAST – NU, Islamabad, Fall 2008

Page 84: SPARQL Tutorial II & III

List of All Dua’s which have some Theme and have some source Surah

PREFIX dua: htt // ti b / t l i /<http://www.semanticweb.org/ontologies/20

08/9/DuaOntology.owl#>

SELECT ?D ?theme ?surahWHERE { ?D dua:hasTheme ?theme.

?D dua:hasSourceSurah ?surah.}

FAST – NU, Islamabad, Fall 2008

Page 85: SPARQL Tutorial II & III

PREFIX dua: <http://www.semanticweb.org/ontologies/2008/9/DuaOntology.owl#>

SELECT ?D ?theme ?surah ?no

WHERE { ?D dua:hasTheme ?themeWHERE { ?D dua:hasTheme ?theme.?D dua:hasSourceSurah ?surah .

?surah dua:hasSurahNo ?no?surah dua:hasSurahNo ?no.

}}ORDER BY ?no

FAST – NU, Islamabad, Fall 2008

Page 86: SPARQL Tutorial II & III

PREFIX dua: <http://www.semanticweb.org/ontologies/2008/9/DuaOntology.owl#>

SELECT ?D ?theme ?surah ?no ?ayah

WHERE { ?D dua:hasTheme ?themeWHERE { ?D dua:hasTheme ?theme.?D dua:hasSourceSurah ?surah ;

dua:hasSourceAyah ?ayah.?surah dua:hasSurahNo ?no?surah dua:hasSurahNo ?no.

}}ORDER BY ?no

FAST – NU, Islamabad, Fall 2008

Page 87: SPARQL Tutorial II & III

Notice the change in results with the use of OPTIONALof OPTIONAL

PREFIX dua: <http://www.semanticweb.org/ontologies/2008/9/DuaOntology.owl#>

SELECT ?D ?theme ?surah ?no ?ayah

WHERE{ ?D dua:hasTheme ?theme.?D dua:hasSourceSurah ?surah.

?surah dua:hasSurahNo ?no.

OPTIONAL{     ?D dua:hasSourceAyah ?ayah.

}}ORDER BY ?no

FAST – NU, Islamabad, Fall 2008

Page 88: SPARQL Tutorial II & III

Use of Regular Expression to retrieve duas that contain the word Rabbithat contain the word RabbiPREFIX dua: <http://www.semanticweb.org/ontologies/2008/9/DuaOntology.

lowl#>

SELECT ?D ?surah ?no ?text

WHERE{ ?D dua:hasSourceSurah ?surah?D dua:hasSourceSurah ?surah.?D dua:hasTextAyah ?text.

FILTER regex(?text,  "Rabbi") .

?surah dua:hasSurahNo ?no.

FAST – NU, Islamabad, Fall 2008

}

Page 89: SPARQL Tutorial II & III

Use of Regular Expression to retrieve duas that contain the word Rabbanathat contain the word Rabbana

PREFIX dua: <http://www.semanticweb.org/ontologies/2008/9/DuaOntology.owl#>

SELECT ?D ?surah ?no ?text

WHERE{ WHERE{ ?D dua:hasSourceSurah ?surah.

?D dua:hasTextAyah ?text.FILTER regex(?text   "Rabbana") FILTER regex(?text,   Rabbana ) .

?surah dua:hasSurahNo ?no.

}

FAST – NU, Islamabad, Fall 2008

Page 90: SPARQL Tutorial II & III

AN interesting Query!. …Think about what it does!what it does!

PREFIX dua: <http://www.semanticweb.org/ontologies/2008/9/DuaOntology.owl#>

SELECT ?Dua  ?DuaOther ?surah2

WHERE{ WHERE{ ?Dua dua:hasSourceSurah dua:Taha.?Dua dua:isRelatedTo ?p.?DuaOther dua:isRelatedTo ?p?DuaOther dua:isRelatedTo ?p.?DuaOther dua:hasSourceSurah ?surah2.

}}

FAST – NU, Islamabad, Fall 2008

Page 91: SPARQL Tutorial II & III

Find other Duas related to the same  prophet in a given Surahprophet in a given Surah

� “Find other duas related with the prophet of a given surah ”given surah.

FAST – NU, Islamabad, Fall 2008