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

LODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopMyungjin Lee
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteChris Baynes
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQLPooja Dixit
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQLOlaf Hartig
 
Web-Scale Graph Analytics with Apache Spark with Tim Hunter
Web-Scale Graph Analytics with Apache Spark with Tim HunterWeb-Scale Graph Analytics with Apache Spark with Tim Hunter
Web-Scale Graph Analytics with Apache Spark with Tim HunterDatabricks
 
파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄SeongHyun Ahn
 
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceDataWorks Summit
 
Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...
Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...
Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...Edureka!
 
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!
 
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
 
Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...
Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...
Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...Simplilearn
 
Pandas UDF: Scalable Analysis with Python and PySpark
Pandas UDF: Scalable Analysis with Python and PySparkPandas UDF: Scalable Analysis with Python and PySpark
Pandas UDF: Scalable Analysis with Python and PySparkLi Jin
 
Getting The Best Performance With PySpark
Getting The Best Performance With PySparkGetting The Best Performance With PySpark
Getting The Best Performance With PySparkSpark Summit
 
Apache Arrow Flight Overview
Apache Arrow Flight OverviewApache Arrow Flight Overview
Apache Arrow Flight OverviewJacques Nadeau
 
Spring introduction
Spring introductionSpring introduction
Spring introductionManav Prasad
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaEdureka!
 
Top 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | EdurekaTop 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | EdurekaEdureka!
 

What's hot (20)

LODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data WorkshopLODAC 2017 Linked Open Data Workshop
LODAC 2017 Linked Open Data Workshop
 
Fast federated SQL with Apache Calcite
Fast federated SQL with Apache CalciteFast federated SQL with Apache Calcite
Fast federated SQL with Apache Calcite
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Querying Linked Data with SPARQL
Querying Linked Data with SPARQLQuerying Linked Data with SPARQL
Querying Linked Data with SPARQL
 
Web-Scale Graph Analytics with Apache Spark with Tim Hunter
Web-Scale Graph Analytics with Apache Spark with Tim HunterWeb-Scale Graph Analytics with Apache Spark with Tim Hunter
Web-Scale Graph Analytics with Apache Spark with Tim Hunter
 
파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄
 
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query PerformanceORC File & Vectorization - Improving Hive Data Storage and Query Performance
ORC File & Vectorization - Improving Hive Data Storage and Query Performance
 
Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...
Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...
Spark Interview Questions and Answers | Apache Spark Interview Questions | Sp...
 
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...
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...
Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...
Spark SQL Tutorial | Spark SQL Using Scala | Apache Spark Tutorial For Beginn...
 
Neo4J 사용
Neo4J 사용Neo4J 사용
Neo4J 사용
 
Pandas UDF: Scalable Analysis with Python and PySpark
Pandas UDF: Scalable Analysis with Python and PySparkPandas UDF: Scalable Analysis with Python and PySpark
Pandas UDF: Scalable Analysis with Python and PySpark
 
Getting The Best Performance With PySpark
Getting The Best Performance With PySparkGetting The Best Performance With PySpark
Getting The Best Performance With PySpark
 
SWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDFSWT Lecture Session 2 - RDF
SWT Lecture Session 2 - RDF
 
Apache Arrow Flight Overview
Apache Arrow Flight OverviewApache Arrow Flight Overview
Apache Arrow Flight Overview
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
SQL Joins With Examples | Edureka
SQL Joins With Examples | EdurekaSQL Joins With Examples | Edureka
SQL Joins With Examples | Edureka
 
Top 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | EdurekaTop 65 SQL Interview Questions and Answers | Edureka
Top 65 SQL Interview Questions and Answers | Edureka
 
SPARQL Cheat Sheet
SPARQL Cheat SheetSPARQL Cheat Sheet
SPARQL Cheat Sheet
 

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
 
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
 
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
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 

Recently uploaded

Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/managementakshesh doshi
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
(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
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998YohFuh
 
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
 
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
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxFurkanTasci3
 
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
 
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
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
{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
 
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
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingNeil Barnes
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptxAnupama Kate
 
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
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfLars Albertsson
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Jack DiGiovanna
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 

Recently uploaded (20)

VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
VIP Call Girls Service Charbagh { Lucknow Call Girls Service 9548273370 } Boo...
 
Spark3's new memory model/management
Spark3's new memory model/managementSpark3's new memory model/management
Spark3's new memory model/management
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
(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
 
RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998RA-11058_IRR-COMPRESS Do 198 series of 1998
RA-11058_IRR-COMPRESS Do 198 series of 1998
 
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
 
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
 
Data Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptxData Science Jobs and Salaries Analysis.pptx
Data Science Jobs and Salaries Analysis.pptx
 
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...
 
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
 
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls Punjabi Bagh 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
{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...
 
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
 
Brighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data StorytellingBrighton SEO | April 2024 | Data Storytelling
Brighton SEO | April 2024 | Data Storytelling
 
100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx100-Concepts-of-AI by Anupama Kate .pptx
100-Concepts-of-AI by Anupama Kate .pptx
 
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
 
Schema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdfSchema on read is obsolete. Welcome metaprogramming..pdf
Schema on read is obsolete. Welcome metaprogramming..pdf
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
Building on a FAIRly Strong Foundation to Connect Academic Research to Transl...
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 

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