SlideShare a Scribd company logo
1 of 34
Download to read offline
Dr. Biswanath Dutta
Associate Professor
Documentation Research and Training Centre (DRTC)
Indian Statistical Institute
Bangalore 56059 (INDIA)
dutta2005@gmail.com, bisu@drtc.isibang.ac.in, bisu@isibang.ac.in
Tutorial on
SPARQL: SPARQL Protocol
and RDF Query Language
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021
1
Outline
• Introduction to SPARQL
• SPARQL Query Forms
• SELECT Query form
• Simple query
• Multiple match
• Optional Clause
• Filter Clause (string, arithmatic)
• Matching alternatives
• Algebra
• Query for properties and schema
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
2
Introduction
• SPARQL is a query language for RDF graph traversal
• SPARQL query language specification
• A protocol* for using SPARQL via HTTP
• SPARQL Protocol for RDF Specification
• SPARQL queries and manipulates RDF graph content on the web or in the RDF store
• SPARQL is independent of any particular serialization format (e.g., RDF/XML, N3,
Turtle)
• Inspired by SQL
• SPARQL 1.0: W3C Recommendation (15th January 2008) (https://www.w3.org/TR/rdf-
sparql-query/)
• SPARQL 1.1: W3C Recommendation (21st March 2013)
(https://www.w3.org/TR/sparql11-query/)
*a means of conveying SPARQL queries from query clients to query processors.
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
3
Introduction (contd…2)
• The SPARQL query result is usually displayed in Tabular form.
• SPARQL query results can be exchanged using any of the following formats:
• Extensible Markup Language (XML)
• JavaScript Object Notation (JSON)
• Comma Separated Value (CSV)
• Tab Separated Value (TSV)
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
4
SPARQL Four Query Forms
• These query forms use the solutions from pattern matching to form result sets or RDF graphs.
• SELECT query
• Returns all, or a subset of, the variables bound in a query pattern match.
• Extract raw values, the results are returned in a table format.
• CONSTRUCT query
• Returns an RDF graph constructed by substituting variables in a set of triple templates.
• Extract information and transform the results into valid RDF.
• ASK query
• Returns a boolean indicating whether a query pattern matches or not.
• Provides a simple True/False result for a query.
• DESCRIBE query
• Returns an RDF graph that describes the resources found.
• Extract an RDF graph from the SPARQL endpoint, the content of which is left to the endpoint to decide based on
what the maintainer deems as useful information.
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
5
Query Form: SELECT
PREFIX : <http://www.isibang.ac.in/ns/into#>
SELECT ?x ?y
WHERE { ?x :p ?y }
Prefix mechanism to abbreviate URI
Variables to be returned
Query patterns (list of triple patterns)
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
6
• Syntax: SELECT var1, var2, … varn
• Here, var refers to any string variable, such as, ?x, ?name, ?email,
?title, ?experts
Query Form: SELECT
SELECT ?x ?y
Alternatively:
SELECT ?researcher ?researchInterest
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
7
WHERE
• Graph patterns to match a set of triples
• Syntax: WHERE {
subject predicate object .
subject predicate object .
}
Alternative query:
SELECT ?researcher ?researchInterest
WHERE { ?researcher <http://www.isibang.ac.in/ns/into#hasResearchInterest> ?researchInterest}
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
PREFIX : <http://www.isibang.ac.in/ns/into#hasResearchInterest#>
SELECT ?x ?y
WHERE { ?x : hasResearchInterest ?y }
8
### http://www.isibang.ac.in/ns/into#ADIS
:ADIS rdf:type owl:Class ;
rdfs:subClassOf :CourseSchedule ;
rdfs:comment "This course is equivalent to MLISc
degree"^^xsd:string .
### http://www.isibang.ac.in/ns/into#AcademicProgramme
:AcademicProgramme rdf:type owl:Class .
### http://www.isibang.ac.in/ns/into#AdministrativeStaff
:AdministrativeStaff rdf:type owl:Class ;
rdfs:subClassOf :Employee .
### http://www.isibang.ac.in/ns/into#Agent
:Agent rdf:type owl:Class .
Class inf. of Institutional Ontology (excerpt) (Turtle format)
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
### http://www.isibang.ac.in/ns/into#Article
:Article rdf:type owl:Class ;
rdfs:subClassOf :Publication .
### http://www.isibang.ac.in/ns/into#Assistant
:Assistant rdf:type owl:Class ;
rdfs:subClassOf :Employee .
### http://www.isibang.ac.in/ns/into#AssistantProfessor
:AssistantProfessor rdf:type owl:Class ;
rdfs:subClassOf :Faculty ,
[ rdf:type owl:Restriction ;
owl:onProperty :supervise ;
owl:maxQualifiedCardinality
"4"^^xsd:nonNegativeInteger ;
owl:onClass :ResearchFellow
] . 9
A Simple Query and Result
SELECT ?class ?sub_class
WHERE { ?class rdfs:subClassOf ?sub_class}
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
10
Data in Institutional Ontology
Data in Turtle (1):
### http://www.isibang.ac.in/ns/into#KiranKanta
:BiswanathDutta rdf:type owl:NamedIndividual ,
:SeniorResearchFellow ;
:hasAffiliation :DRTC ,
:ISIBC ;
:hasGender :male ;
:hasQualification :BSc ,
:MLISc ;
:hasResearchInterest :Ontology ,
:SWS ,
:SemanticWebBased-eGovernance ;
foaf:age 26 ;
foaf:email “kiran@drtc.isibang.ac.in"^^xsd:string ;
:firstName “Kiran"^^xsd:string ;
:homepage
"http://drtc.isibang.ac.in/~kiran"^^xsd:anyURI ;
:lastName “Kanta"^^xsd:string ;
:rollNo "RS039"^^xsd:string .
............
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
Data in Turtle (2):
### http://www.isibang.ac.in/ns/into#DebeshDas
:DebeshDas rdf:type owl:NamedIndividual ,
:AssociateProfessor ;
:editorOfEvents :DL2005 ,
:ICSD2007 ;
:hasAffiliation :DRTC ,
:ISIBC ;
:hasGender :male ;
:hasQualification :MLISc ,
:MPhil ;
:hasResearchInterest :AI ,
:DigitalLibrary ,
:NLP ,
:Ontology ;
:supervise :BiswanathDutta ,
:NGuha ,
:SKSunny ;
foaf:age "57"^^xsd:int ;
:firstName "Debesh"^^xsd:string ;
:hasTeachingExperience 10 ;
:homepage "http://drtc.isibang.ac.in/~ard"^^xsd:anyURI ;
:lastName "Das"^^xsd:string ;
:rollNo "ASSP039"^^xsd:string .
............
11
A Simple Query and Result
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
PREFIX : <http://www.isibang.ac.in/ns/into#>
SELECT ?researcher ?topic
WHERE {?researcher :hasResearchInterest ?topic}
12
Multiple Match
• The above query involves two
triple patterns, each triple ends
with a '.'
– the dot (‘.’) after the last
triple can be omitted. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
Graph patterns to match a set of triples
Syntax: WHERE {
subject predicate object .
subject predicate object .
}
E.g.,
PREFIX : <http://www.isibang.ac.in/ns/into#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
SELECT ?firstname ?lastname ?age
WHERE {?p :firstName ?firstname .
?p :lastName ?lastname .
?p foaf:age ?age .}
LIMIT 10
13
Optional Clause
• SPARQL also allows to define OPTIONAL blocks.
• They offer the ability to query for data but not to fail query when that data does
not exist.
• Optional blocks define additional graph patterns that do bind to the graph when
they can be matched, but do not cause solutions to be rejected if they are not
matched.
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
14
Optional Pattern Matching
PREFIX : <http://www.isibang.ac.in/ns/into#>
PREFIX foaf:<http://xmlns.com/foaf/0.1/>
SELECT ?firstname ?lastname ?age
WHERE {?p :firstName ?firstname .
?p :lastName ?lastname .
OPTIONAL {?p foaf:age ?age .} }
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
15
OFFSET causes the solutions generated to start after the
specified number of solutions.
Filter Clause
• SPARQL allows to pose restrictions on the values in query solutions.
• These restrictions are defined in FILTER clauses.
• These clauses are, to some extent, similar to WHERE clause of an SQL query.
• SPARQL filters can be used to restrict:
• String values (using REGEX function),
• Numeric values (using <, >, =, <=, >= and != operators).
• SPARQL also provides test functions:
• BOUND, isURI, isBLANK, isLITERAL
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
16
Filter – String matching
SPARQL provides an operation to test strings, based on regular expressions
This allows to ask SQL "LIKE" style tests, although the syntax of the regular
expression is different from SQL.
Syntax:
FILTER regex(?x, "pattern" [, "flags"])
*Regex invokes the XPath fn:matches function to match text against a
regular expression pattern.The regular expression language is defined
in XQuery 1.0 and XPath 2.0
**The flags argument is optional. The flag "i" means a case-insensitive
pattern match is done.
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
17
SELECT ?name
WHERE { ?person :firstName ?name .
FILTER regex(?name, "^k", "i")
}
Filter – String matching (contd…2)
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
18
SELECT ?name
WHERE { ?person :firstName ?name .
FILTER regex(?name, "ran", "i")
}
Any name starts with
“k”
Any name that contains
“ran”
Filter - Arithmetic Expression
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
19
SELECT ?student ?age
WHERE {?student a :SeniorResearchFellow ;
foaf:age ?age .
FILTER (?age <= 26) }
SELECT ?person ?age
WHERE {?person foaf:age ?age .
FILTER (?age >= 26) }
Optional + Filter
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
20
SELECT ?student ?age
WHERE { ?student a :SeniorResearchFellow .
OPTIONAL { ?student foaf:age ?age .
FILTER (?age != 26)
} }
SELECT ?student ?age
WHERE { ?student a :SeniorResearchFellow .
OPTIONAL { ?student foaf:age ?age .
FILTER (?age >= 26)
}
}
Optional + Filter
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
21
SELECT ?givenName ?birthDay
WHERE {
?x foaf:givenName ?givenName .
OPTIONAL {?x :dateOfBirth ?birthDay}
FILTER ( bound(?birthDay) ) }
SELECT ?givenName ?birthDay
WHERE {
?x foaf:givenName ?givenName .
OPTIONAL {?x :dateOfBirth ?birthDay} }
BOUND rturns true if var is bound to a value. Returns false otherwise.
SELECT ?person ?birthDay
WHERE { ?person :dateOfBirth ?birthDay .
FILTER ( ?birthDay < "2010-11-24T00:00:00"^^xsd:dateTime ) }
Optional + Filter
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
22
SELECT ?givenName ?birthDay
WHERE {
?x foaf:givenName ?givenName .
OPTIONAL {?x :dateOfBirth ?birthDay}
FILTER ( bound(?birthDay) ) }
BOUND rturns true if var is bound to a value. Returns false otherwise.
SELECT ?givenName ?birthDay
WHERE {
?x foaf:givenName ?givenName .
OPTIONAL {?x :dateOfBirth ?birthDay}
FILTER ( !bound(?birthDay) ) }
Matching Alternatives: UNION
• SPARQL supports combining graph patterns so that one of several
alternative graph patterns may match.
• If there is a match of more than one alternatives, all the possible
pattern solutions are found.
• Pattern alternatives are syntactically specified with the UNION
keyword.
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
23
:AKPandey :firstName "Anand"^^xsd:string ;
:lastName "Pandey"^^xsd:string ;
foaf:familyName "Pandey"^^xsd:string ;
foaf:givenName "Anand K."^^xsd:string .
:DebeshDas :firstName "Debesh"^^xsd:string ;
:hasTeachingExperience 10 ;
:lastName "Das"^^xsd:string ;
foaf:familyName "Das"^^xsd:string ;
foaf:givenName "Debesh Satpathy"^^xsd:string.
………….
Data in Institutional Ontology
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
24
SELECT DISTINCT ?firstName ?lastName ?givenName ?familyName
WHERE {
{?x :firstName ?firstName; :lastName ?lastName .}
UNION
{?y foaf:givenName ?givenName; foaf:familyName ?familyName .}
}
Matching Alternatives: UNION (contd…2)
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
25
*Here, modifier DISTINCT to filter out
the duplicate results.
SELECT DISTINCT ?firstName
WHERE {
{?x :firstName ?firstName .}
UNION
{?y foaf:givenName ?firstName .}
} ORDER BY ?firstName
Matching Alternatives: UNION (contd…3)
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
26
• Counting the number of research topics of each researchers.
• The following query displays the individual researchers and the number of
research topics they are working on. Here, the grouping is by “researhchers.”
SELECT ?researcher (COUNT (?topics) AS ?noOfTopics)
WHERE {?researcher :hasResearchInterest ?topics .}
GROUP BY ?researcher ORDER BY DESC(COUNT(?topics)) LIMIT 10
Algebra – Count
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
27
For Ascending order, use “ASC”
• Counting the number of researchers working in an area.
• The following query displays the research areas/ topics and the total number of
researchers working in the area. Here, the grouping is by “researchers.”
SELECT ?topic (COUNT (?researcher) AS ?noOfResearcher)
WHERE {?researcher :hasResearchInterest ?topic .}
GROUP BY ?topic
Algebra – Count (contd…2)
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
28
Query for properties and schema
• The following query tells “what are the sorts of things (i.e., metadata) the dataset knows about
DebeshDas?” This query is very powerful. Because we may not know what properties are used to
describe a resource.
Select DISTINCT ?property
Where {:DebeshDas ?property ?value}
This query returns the properties along with their corresponding values.
SELECT DISTINCT ?property ?value
WHERE {:DebeshDas ?property ?value}
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
29
Query for properties and schema (Contd…2)
• This ability of querying the properties, make it possible to reverse-engineer schema
information from the data itself. For instance, we change the query about properties used
to describe :DebeshDas to find all properties used to describe any :Faculty.
Select DISTINCT ?property
Where {?x a :Faculty .
?x ?property ?object .}
• Note: If we don’t know about the class :Faculty, we can ask about that as well.
Select DISTINCT ?class
Where {?class rdfs:subClassOf :Faculty}
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
30
Query for properties and schema (Contd…3)
• If we do not know anything about the data at all, we can find the classes used in the
data.
Select DISTINCT ?class
Where {?x a ?class}
• Also, alternatively, find all the properties used anywhere in the data.
Select DISTINCT ?property
Where {?x ?property ?y}
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
31
References
1. SPARQL 1.1 Query Language (W3C Recommendation). http://www.w3.org/TR/sparql11-query/
2. Corno, Fulvio (2012). SPARQL and Linked Data. http://www.slideshare.net/
3. Ghaiwi, R. (2013). SPARQL.
4. SPARQL by example. https://www.w3.org/2009/Talks/0615-qbe/
5. DBPedia SPARQL Endpoint. http://dbpedia.org/sparql
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
32
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021
Thank you!!!
Questions?
Contact:
Biswanath Dutta
dutta2005@gmail.com, bisu@drtc.isibang.ac.in, bisu@isibang.ac.in
Organized by
Documentation Research and Training Centre
Indian Statistical Institute (Bangalore)
https://drtc.isibang.ac.in/semtech/
Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8
Jan 2021

More Related Content

What's hot

Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...Edureka!
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)Ameer Sameer
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)Thomas Francart
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization TechniquesNishant Munjal
 
RDF 개념 및 구문 소개
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개Dongbum Kim
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesDatabricks
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Edureka!
 
NoSQL databases - An introduction
NoSQL databases - An introductionNoSQL databases - An introduction
NoSQL databases - An introductionPooyan Mehrparvar
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshellFabien Gandon
 

What's hot (20)

RDF, linked data and semantic web
RDF, linked data and semantic webRDF, linked data and semantic web
RDF, linked data and semantic web
 
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
Pyspark Tutorial | Introduction to Apache Spark with Python | PySpark Trainin...
 
Web ontology language (owl)
Web ontology language (owl)Web ontology language (owl)
Web ontology language (owl)
 
SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)SPARQL introduction and training (130+ slides with exercices)
SPARQL introduction and training (130+ slides with exercices)
 
enhanced er diagram
enhanced er diagramenhanced er diagram
enhanced er diagram
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
SHACL by example
SHACL by exampleSHACL by example
SHACL by example
 
Apache spark
Apache sparkApache spark
Apache spark
 
Database Design and Normalization Techniques
Database Design and Normalization TechniquesDatabase Design and Normalization Techniques
Database Design and Normalization Techniques
 
RDF 개념 및 구문 소개
RDF 개념 및 구문 소개RDF 개념 및 구문 소개
RDF 개념 및 구문 소개
 
SPARQL Tutorial
SPARQL TutorialSPARQL Tutorial
SPARQL Tutorial
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
 
MySQL lecture
MySQL lectureMySQL lecture
MySQL lecture
 
Semantic search
Semantic searchSemantic search
Semantic search
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
Spark SQL Tutorial | Spark Tutorial for Beginners | Apache Spark Training | E...
 
ontop: A tutorial
ontop: A tutorialontop: A tutorial
ontop: A tutorial
 
NoSQL databases - An introduction
NoSQL databases - An introductionNoSQL databases - An introduction
NoSQL databases - An introduction
 
RDF data model
RDF data modelRDF data model
RDF data model
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
 

Similar to Tutorial on SPARQL: SPARQL Protocol and RDF Query Language

WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaKatrien Verbert
 
What;s Coming In SPARQL2?
What;s Coming In SPARQL2?What;s Coming In SPARQL2?
What;s Coming In SPARQL2?LeeFeigenbaum
 
SemFacet paper
SemFacet paperSemFacet paper
SemFacet paperDBOnto
 
Sem facet paper
Sem facet paperSem facet paper
Sem facet paperDBOnto
 
Sparql semantic information retrieval by
Sparql semantic information retrieval bySparql semantic information retrieval by
Sparql semantic information retrieval byIJNSA Journal
 
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONSSPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONSIJNSA Journal
 
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...Allison Jai O'Dell
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLMyungjin Lee
 
Semantic DEX Components
Semantic DEX ComponentsSemantic DEX Components
Semantic DEX ComponentsDavid Price
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLEmanuele Della Valle
 
BioSamples Database Linked Data, SWAT4LS Tutorial
BioSamples Database Linked Data, SWAT4LS TutorialBioSamples Database Linked Data, SWAT4LS Tutorial
BioSamples Database Linked Data, SWAT4LS TutorialRothamsted Research, UK
 
Searching Semantic Web Objects Based on Class Hierarchies
Searching Semantic Web Objects Based on Class HierarchiesSearching Semantic Web Objects Based on Class Hierarchies
Searching Semantic Web Objects Based on Class HierarchiesGong Cheng
 
Case Study in Linked Data and Semantic Web: Human Genome
Case Study in Linked Data and Semantic Web: Human GenomeCase Study in Linked Data and Semantic Web: Human Genome
Case Study in Linked Data and Semantic Web: Human GenomeDavid Portnoy
 
Querying XML: XPath and XQuery
Querying XML: XPath and XQueryQuerying XML: XPath and XQuery
Querying XML: XPath and XQueryKatrien Verbert
 
Sparql a simple knowledge query
Sparql  a simple knowledge querySparql  a simple knowledge query
Sparql a simple knowledge queryStanley Wang
 

Similar to Tutorial on SPARQL: SPARQL Protocol and RDF Query Language (20)

WebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPediaWebTech Tutorial Querying DBPedia
WebTech Tutorial Querying DBPedia
 
What;s Coming In SPARQL2?
What;s Coming In SPARQL2?What;s Coming In SPARQL2?
What;s Coming In SPARQL2?
 
SemFacet paper
SemFacet paperSemFacet paper
SemFacet paper
 
Sem facet paper
Sem facet paperSem facet paper
Sem facet paper
 
Sparql semantic information retrieval by
Sparql semantic information retrieval bySparql semantic information retrieval by
Sparql semantic information retrieval by
 
SPIN in Five Slides
SPIN in Five SlidesSPIN in Five Slides
SPIN in Five Slides
 
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONSSPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
SPARQL: SEMANTIC INFORMATION RETRIEVAL BY EMBEDDING PREPOSITIONS
 
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
Notes from the Library Juice Academy courses on “SPARQL Fundamentals”: Univer...
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
Semantic DEX Components
Semantic DEX ComponentsSemantic DEX Components
Semantic DEX Components
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
BioSamples Database Linked Data, SWAT4LS Tutorial
BioSamples Database Linked Data, SWAT4LS TutorialBioSamples Database Linked Data, SWAT4LS Tutorial
BioSamples Database Linked Data, SWAT4LS Tutorial
 
Searching Semantic Web Objects Based on Class Hierarchies
Searching Semantic Web Objects Based on Class HierarchiesSearching Semantic Web Objects Based on Class Hierarchies
Searching Semantic Web Objects Based on Class Hierarchies
 
Case Study in Linked Data and Semantic Web: Human Genome
Case Study in Linked Data and Semantic Web: Human GenomeCase Study in Linked Data and Semantic Web: Human Genome
Case Study in Linked Data and Semantic Web: Human Genome
 
BioSD Tutorial 2014 Editition
BioSD Tutorial 2014 EdititionBioSD Tutorial 2014 Editition
BioSD Tutorial 2014 Editition
 
Sparql
SparqlSparql
Sparql
 
SPARQL 1.1 Status
SPARQL 1.1 StatusSPARQL 1.1 Status
SPARQL 1.1 Status
 
Querying XML: XPath and XQuery
Querying XML: XPath and XQueryQuerying XML: XPath and XQuery
Querying XML: XPath and XQuery
 
Sparql a simple knowledge query
Sparql  a simple knowledge querySparql  a simple knowledge query
Sparql a simple knowledge query
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 

Recently uploaded

VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiSuhani Kapoor
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz1
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...Pooja Nehwal
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxTanveerAhmed817946
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknowmakika9823
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiSuhani Kapoor
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSAishani27
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 

Recently uploaded (20)

VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service AmravatiVIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
VIP Call Girls in Amravati Aarohi 8250192130 Independent Escort Service Amravati
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
(PARI) Call Girls Wanowrie ( 7001035870 ) HI-Fi Pune Escorts Service
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 
Invezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signalsInvezz.com - Grow your wealth with trading signals
Invezz.com - Grow your wealth with trading signals
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
E-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptxE-Commerce Order PredictionShraddha Kamble.pptx
E-Commerce Order PredictionShraddha Kamble.pptx
 
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...{Pooja:  9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
{Pooja: 9892124323 } Call Girl in Mumbai | Jas Kaur Rate 4500 Free Hotel Del...
 
Digi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptxDigi Khata Problem along complete plan.pptx
Digi Khata Problem along complete plan.pptx
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service BhilaiLow Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
Low Rate Call Girls Bhilai Anika 8250192130 Independent Escort Service Bhilai
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Ukraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICSUkraine War presentation: KNOW THE BASICS
Ukraine War presentation: KNOW THE BASICS
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 

Tutorial on SPARQL: SPARQL Protocol and RDF Query Language

  • 1. Dr. Biswanath Dutta Associate Professor Documentation Research and Training Centre (DRTC) Indian Statistical Institute Bangalore 56059 (INDIA) dutta2005@gmail.com, bisu@drtc.isibang.ac.in, bisu@isibang.ac.in Tutorial on SPARQL: SPARQL Protocol and RDF Query Language Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 1
  • 2. Outline • Introduction to SPARQL • SPARQL Query Forms • SELECT Query form • Simple query • Multiple match • Optional Clause • Filter Clause (string, arithmatic) • Matching alternatives • Algebra • Query for properties and schema Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 2
  • 3. Introduction • SPARQL is a query language for RDF graph traversal • SPARQL query language specification • A protocol* for using SPARQL via HTTP • SPARQL Protocol for RDF Specification • SPARQL queries and manipulates RDF graph content on the web or in the RDF store • SPARQL is independent of any particular serialization format (e.g., RDF/XML, N3, Turtle) • Inspired by SQL • SPARQL 1.0: W3C Recommendation (15th January 2008) (https://www.w3.org/TR/rdf- sparql-query/) • SPARQL 1.1: W3C Recommendation (21st March 2013) (https://www.w3.org/TR/sparql11-query/) *a means of conveying SPARQL queries from query clients to query processors. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 3
  • 4. Introduction (contd…2) • The SPARQL query result is usually displayed in Tabular form. • SPARQL query results can be exchanged using any of the following formats: • Extensible Markup Language (XML) • JavaScript Object Notation (JSON) • Comma Separated Value (CSV) • Tab Separated Value (TSV) Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 4
  • 5. SPARQL Four Query Forms • These query forms use the solutions from pattern matching to form result sets or RDF graphs. • SELECT query • Returns all, or a subset of, the variables bound in a query pattern match. • Extract raw values, the results are returned in a table format. • CONSTRUCT query • Returns an RDF graph constructed by substituting variables in a set of triple templates. • Extract information and transform the results into valid RDF. • ASK query • Returns a boolean indicating whether a query pattern matches or not. • Provides a simple True/False result for a query. • DESCRIBE query • Returns an RDF graph that describes the resources found. • Extract an RDF graph from the SPARQL endpoint, the content of which is left to the endpoint to decide based on what the maintainer deems as useful information. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 5
  • 6. Query Form: SELECT PREFIX : <http://www.isibang.ac.in/ns/into#> SELECT ?x ?y WHERE { ?x :p ?y } Prefix mechanism to abbreviate URI Variables to be returned Query patterns (list of triple patterns) Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 6
  • 7. • Syntax: SELECT var1, var2, … varn • Here, var refers to any string variable, such as, ?x, ?name, ?email, ?title, ?experts Query Form: SELECT SELECT ?x ?y Alternatively: SELECT ?researcher ?researchInterest Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 7
  • 8. WHERE • Graph patterns to match a set of triples • Syntax: WHERE { subject predicate object . subject predicate object . } Alternative query: SELECT ?researcher ?researchInterest WHERE { ?researcher <http://www.isibang.ac.in/ns/into#hasResearchInterest> ?researchInterest} Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 PREFIX : <http://www.isibang.ac.in/ns/into#hasResearchInterest#> SELECT ?x ?y WHERE { ?x : hasResearchInterest ?y } 8
  • 9. ### http://www.isibang.ac.in/ns/into#ADIS :ADIS rdf:type owl:Class ; rdfs:subClassOf :CourseSchedule ; rdfs:comment "This course is equivalent to MLISc degree"^^xsd:string . ### http://www.isibang.ac.in/ns/into#AcademicProgramme :AcademicProgramme rdf:type owl:Class . ### http://www.isibang.ac.in/ns/into#AdministrativeStaff :AdministrativeStaff rdf:type owl:Class ; rdfs:subClassOf :Employee . ### http://www.isibang.ac.in/ns/into#Agent :Agent rdf:type owl:Class . Class inf. of Institutional Ontology (excerpt) (Turtle format) Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 ### http://www.isibang.ac.in/ns/into#Article :Article rdf:type owl:Class ; rdfs:subClassOf :Publication . ### http://www.isibang.ac.in/ns/into#Assistant :Assistant rdf:type owl:Class ; rdfs:subClassOf :Employee . ### http://www.isibang.ac.in/ns/into#AssistantProfessor :AssistantProfessor rdf:type owl:Class ; rdfs:subClassOf :Faculty , [ rdf:type owl:Restriction ; owl:onProperty :supervise ; owl:maxQualifiedCardinality "4"^^xsd:nonNegativeInteger ; owl:onClass :ResearchFellow ] . 9
  • 10. A Simple Query and Result SELECT ?class ?sub_class WHERE { ?class rdfs:subClassOf ?sub_class} Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 10
  • 11. Data in Institutional Ontology Data in Turtle (1): ### http://www.isibang.ac.in/ns/into#KiranKanta :BiswanathDutta rdf:type owl:NamedIndividual , :SeniorResearchFellow ; :hasAffiliation :DRTC , :ISIBC ; :hasGender :male ; :hasQualification :BSc , :MLISc ; :hasResearchInterest :Ontology , :SWS , :SemanticWebBased-eGovernance ; foaf:age 26 ; foaf:email “kiran@drtc.isibang.ac.in"^^xsd:string ; :firstName “Kiran"^^xsd:string ; :homepage "http://drtc.isibang.ac.in/~kiran"^^xsd:anyURI ; :lastName “Kanta"^^xsd:string ; :rollNo "RS039"^^xsd:string . ............ Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 Data in Turtle (2): ### http://www.isibang.ac.in/ns/into#DebeshDas :DebeshDas rdf:type owl:NamedIndividual , :AssociateProfessor ; :editorOfEvents :DL2005 , :ICSD2007 ; :hasAffiliation :DRTC , :ISIBC ; :hasGender :male ; :hasQualification :MLISc , :MPhil ; :hasResearchInterest :AI , :DigitalLibrary , :NLP , :Ontology ; :supervise :BiswanathDutta , :NGuha , :SKSunny ; foaf:age "57"^^xsd:int ; :firstName "Debesh"^^xsd:string ; :hasTeachingExperience 10 ; :homepage "http://drtc.isibang.ac.in/~ard"^^xsd:anyURI ; :lastName "Das"^^xsd:string ; :rollNo "ASSP039"^^xsd:string . ............ 11
  • 12. A Simple Query and Result Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 PREFIX : <http://www.isibang.ac.in/ns/into#> SELECT ?researcher ?topic WHERE {?researcher :hasResearchInterest ?topic} 12
  • 13. Multiple Match • The above query involves two triple patterns, each triple ends with a '.' – the dot (‘.’) after the last triple can be omitted. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 Graph patterns to match a set of triples Syntax: WHERE { subject predicate object . subject predicate object . } E.g., PREFIX : <http://www.isibang.ac.in/ns/into#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> SELECT ?firstname ?lastname ?age WHERE {?p :firstName ?firstname . ?p :lastName ?lastname . ?p foaf:age ?age .} LIMIT 10 13
  • 14. Optional Clause • SPARQL also allows to define OPTIONAL blocks. • They offer the ability to query for data but not to fail query when that data does not exist. • Optional blocks define additional graph patterns that do bind to the graph when they can be matched, but do not cause solutions to be rejected if they are not matched. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 14
  • 15. Optional Pattern Matching PREFIX : <http://www.isibang.ac.in/ns/into#> PREFIX foaf:<http://xmlns.com/foaf/0.1/> SELECT ?firstname ?lastname ?age WHERE {?p :firstName ?firstname . ?p :lastName ?lastname . OPTIONAL {?p foaf:age ?age .} } Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 15 OFFSET causes the solutions generated to start after the specified number of solutions.
  • 16. Filter Clause • SPARQL allows to pose restrictions on the values in query solutions. • These restrictions are defined in FILTER clauses. • These clauses are, to some extent, similar to WHERE clause of an SQL query. • SPARQL filters can be used to restrict: • String values (using REGEX function), • Numeric values (using <, >, =, <=, >= and != operators). • SPARQL also provides test functions: • BOUND, isURI, isBLANK, isLITERAL Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 16
  • 17. Filter – String matching SPARQL provides an operation to test strings, based on regular expressions This allows to ask SQL "LIKE" style tests, although the syntax of the regular expression is different from SQL. Syntax: FILTER regex(?x, "pattern" [, "flags"]) *Regex invokes the XPath fn:matches function to match text against a regular expression pattern.The regular expression language is defined in XQuery 1.0 and XPath 2.0 **The flags argument is optional. The flag "i" means a case-insensitive pattern match is done. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 17
  • 18. SELECT ?name WHERE { ?person :firstName ?name . FILTER regex(?name, "^k", "i") } Filter – String matching (contd…2) Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 18 SELECT ?name WHERE { ?person :firstName ?name . FILTER regex(?name, "ran", "i") } Any name starts with “k” Any name that contains “ran”
  • 19. Filter - Arithmetic Expression Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 19 SELECT ?student ?age WHERE {?student a :SeniorResearchFellow ; foaf:age ?age . FILTER (?age <= 26) } SELECT ?person ?age WHERE {?person foaf:age ?age . FILTER (?age >= 26) }
  • 20. Optional + Filter Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 20 SELECT ?student ?age WHERE { ?student a :SeniorResearchFellow . OPTIONAL { ?student foaf:age ?age . FILTER (?age != 26) } } SELECT ?student ?age WHERE { ?student a :SeniorResearchFellow . OPTIONAL { ?student foaf:age ?age . FILTER (?age >= 26) } }
  • 21. Optional + Filter Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 21 SELECT ?givenName ?birthDay WHERE { ?x foaf:givenName ?givenName . OPTIONAL {?x :dateOfBirth ?birthDay} FILTER ( bound(?birthDay) ) } SELECT ?givenName ?birthDay WHERE { ?x foaf:givenName ?givenName . OPTIONAL {?x :dateOfBirth ?birthDay} } BOUND rturns true if var is bound to a value. Returns false otherwise. SELECT ?person ?birthDay WHERE { ?person :dateOfBirth ?birthDay . FILTER ( ?birthDay < "2010-11-24T00:00:00"^^xsd:dateTime ) }
  • 22. Optional + Filter Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 22 SELECT ?givenName ?birthDay WHERE { ?x foaf:givenName ?givenName . OPTIONAL {?x :dateOfBirth ?birthDay} FILTER ( bound(?birthDay) ) } BOUND rturns true if var is bound to a value. Returns false otherwise. SELECT ?givenName ?birthDay WHERE { ?x foaf:givenName ?givenName . OPTIONAL {?x :dateOfBirth ?birthDay} FILTER ( !bound(?birthDay) ) }
  • 23. Matching Alternatives: UNION • SPARQL supports combining graph patterns so that one of several alternative graph patterns may match. • If there is a match of more than one alternatives, all the possible pattern solutions are found. • Pattern alternatives are syntactically specified with the UNION keyword. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 23
  • 24. :AKPandey :firstName "Anand"^^xsd:string ; :lastName "Pandey"^^xsd:string ; foaf:familyName "Pandey"^^xsd:string ; foaf:givenName "Anand K."^^xsd:string . :DebeshDas :firstName "Debesh"^^xsd:string ; :hasTeachingExperience 10 ; :lastName "Das"^^xsd:string ; foaf:familyName "Das"^^xsd:string ; foaf:givenName "Debesh Satpathy"^^xsd:string. …………. Data in Institutional Ontology Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 24
  • 25. SELECT DISTINCT ?firstName ?lastName ?givenName ?familyName WHERE { {?x :firstName ?firstName; :lastName ?lastName .} UNION {?y foaf:givenName ?givenName; foaf:familyName ?familyName .} } Matching Alternatives: UNION (contd…2) Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 25 *Here, modifier DISTINCT to filter out the duplicate results.
  • 26. SELECT DISTINCT ?firstName WHERE { {?x :firstName ?firstName .} UNION {?y foaf:givenName ?firstName .} } ORDER BY ?firstName Matching Alternatives: UNION (contd…3) Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 26
  • 27. • Counting the number of research topics of each researchers. • The following query displays the individual researchers and the number of research topics they are working on. Here, the grouping is by “researhchers.” SELECT ?researcher (COUNT (?topics) AS ?noOfTopics) WHERE {?researcher :hasResearchInterest ?topics .} GROUP BY ?researcher ORDER BY DESC(COUNT(?topics)) LIMIT 10 Algebra – Count Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 27 For Ascending order, use “ASC”
  • 28. • Counting the number of researchers working in an area. • The following query displays the research areas/ topics and the total number of researchers working in the area. Here, the grouping is by “researchers.” SELECT ?topic (COUNT (?researcher) AS ?noOfResearcher) WHERE {?researcher :hasResearchInterest ?topic .} GROUP BY ?topic Algebra – Count (contd…2) Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 28
  • 29. Query for properties and schema • The following query tells “what are the sorts of things (i.e., metadata) the dataset knows about DebeshDas?” This query is very powerful. Because we may not know what properties are used to describe a resource. Select DISTINCT ?property Where {:DebeshDas ?property ?value} This query returns the properties along with their corresponding values. SELECT DISTINCT ?property ?value WHERE {:DebeshDas ?property ?value} Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 29
  • 30. Query for properties and schema (Contd…2) • This ability of querying the properties, make it possible to reverse-engineer schema information from the data itself. For instance, we change the query about properties used to describe :DebeshDas to find all properties used to describe any :Faculty. Select DISTINCT ?property Where {?x a :Faculty . ?x ?property ?object .} • Note: If we don’t know about the class :Faculty, we can ask about that as well. Select DISTINCT ?class Where {?class rdfs:subClassOf :Faculty} Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 30
  • 31. Query for properties and schema (Contd…3) • If we do not know anything about the data at all, we can find the classes used in the data. Select DISTINCT ?class Where {?x a ?class} • Also, alternatively, find all the properties used anywhere in the data. Select DISTINCT ?property Where {?x ?property ?y} Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 31
  • 32. References 1. SPARQL 1.1 Query Language (W3C Recommendation). http://www.w3.org/TR/sparql11-query/ 2. Corno, Fulvio (2012). SPARQL and Linked Data. http://www.slideshare.net/ 3. Ghaiwi, R. (2013). SPARQL. 4. SPARQL by example. https://www.w3.org/2009/Talks/0615-qbe/ 5. DBPedia SPARQL Endpoint. http://dbpedia.org/sparql Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 32
  • 33. Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021 Thank you!!! Questions? Contact: Biswanath Dutta dutta2005@gmail.com, bisu@drtc.isibang.ac.in, bisu@isibang.ac.in
  • 34. Organized by Documentation Research and Training Centre Indian Statistical Institute (Bangalore) https://drtc.isibang.ac.in/semtech/ Workshop on "Ontology," KSAWU, Vijayapura, Karnataka, 4-8 Jan 2021