SlideShare una empresa de Scribd logo
1 de 33
Descargar para leer sin conexión
SPARQL
SPARQL	Protocol	And	RDF	Query	Language		
Amrapali	Zaveri,	Ph.D.
What is SPARQL?
SPARQL	(pronounced	sparkle)	stands	for:	SPARQL	Protocol	And	
RDF	Query	Language		
• SPARQL	1.0	W3C-RecommendaFon	since	January	15th	2008	
• SPARQL	1.1	W3C-RecommendaFon	since	March	21st	2013	
• Query	language	to	query	instances	in	RDF	documents	
• Great	pracFcal	importance	(almost	all	applicaFons	need	it)
SPARQL Example
SELECT		
*		
WHERE

{		
?subject					?predicate					?object		.	
}
Similar to SQL !
SPARQL Components
A	SPARQL	query	comprises,	in	order:	
• PREFIX	declaraFons,	for	abbreviaFng	URIs	
• Dataset	defini;on,	staFng	what	RDF	graph(s)	are	being	queried	
• A	result	clause,	idenFfying	what	informaFon	to	return	from	the	
query	
• The	query	pa@ern,	specifying	what	to	query	for	in	the	
underlying	dataset	
• Query	modifiers,	slicing,	ordering,	and	otherwise	rearranging	
query	results
SPARQL Components
#	prefix	declara;ons	
PREFIX	foo:	<h`p://example.com/resources/>	
#	dataset	defini;on	
FROM		
#	result	clause	
SELECT		
#	query	pa@ern	
WHERE	{	
				...	
}	
#	query	modifiers	
ORDER	BY	...
SPARQL Example
SELECT		*	WHERE	{		
?book				rdf:type													<h`p://dbpedia.org/ontology/Book>	.	
}
Try it yourself: dbpedia.org/sparql/
SPARQL Example
PREFIX	dbo:<h@p://dbpedia.org/ontology/>	
SELECT		*	WHERE	{		
?book				a						dbo:Book	.	
?book			dbo:author	?author.	
	}
Try it yourself: dbpedia.org/sparql/
SPARQL Example
PREFIX	dbo:<h@p://dbpedia.org/ontology/>	
SELECT		*	WHERE	{		
?book				a						dbo:Book	.	
?book			dbo:author	?author.	
	}	LIMIT	10
Try it yourself: dbpedia.org/sparql/
SPARQL Example
PREFIX	dbo:<h@p://dbpedia.org/ontology/>	
SELECT		?author	WHERE	{		
?book				a						dbo:Book	.	
?book			dbo:author	?author.	
	}	LIMIT	10
Try it yourself: dbpedia.org/sparql/
Filter in SPARQL
• Keyword	FILTER,	followed	by	filter	expression	in	parentheses		
• Filter	condiFons	output	truth	values	(and	possibly	errors)		
• Many	filter	funcFons	are	not	specified	by	RDF

funcFons		
• partly	taken	from	XQuery/XPath-Standard	for	XML
Filter Functions
Comparison	operators:	<,	=,	>,	<=,	>=,	!=		
• Comparison	of	data	literals	according	to	natural	order		
• Support	for	numerical	data	types,	xsd:dateTime,	xsd:string	
(alphabeFc	ordering),	xsd:Boolean	(1>0)		
• For	other	types	and	other	RDF-elements,	only	=	and	!=	are	
available	
• Comparison	of	literals	of	incompaFble	types	(e.g.	xsd:string	and	
xsd:integer)	is	not	allowed		
ArithmaFc	operators:	+,	-,	*,	/		
• Support	for	numerical	data	types		
• Used	to	combine	values	in	filter	condiFons	Ex.:	FILTER(?weight/
(?size*?size)>=25)
SPARQL Example
PREFIX	dbo:<h`p://dbpedia.org/ontology/>	
SELECT		?author	WHERE	{		
?book				a						dbo:Book	.	
?book			dbo:author	?author.	
?book			dbo:numberOfPages		?pages.	
FILTER	(?pages	>	500)	
	}	LIMIT	10
Try it yourself: dbpedia.org/sparql/
Special Filter Functions
Other	RDF-specific	filter	funcFons:		
sameTERM(A,B) true,	if	A	and	B	are	the	same	RDF-terms.
langMATCHES(A,B) true,	if	the	language	specificaFon	A	fits	the	pa`ern	B
REGEX(A,B)
true,	if	the	character	string	A	contains	the	regular	
expression	B
SPARQL Example
PREFIX	dbo:<h`p://dbpedia.org/ontology/>	
PREFIX	dbp:<h@p://dbpedia.org/property/>	
SELECT		*	WHERE	{		
?book				a																																			dbo:Book	.	
?book			dbo:author																			?author.	
?book			dbo:numberOfPages		?pages.	
?book			dbp:name																						?name.	
FILTER	(?pages	>	500)	
FILTER	(langMATCHES(LANG(?name),"en))	
	}	LIMIT	10
Try it yourself: dbpedia.org/sparql/
Filter Functions: Boolean
operators
Filter	condiFons	can	be	linked	with	boolean	operators:	&&,	||,	!		
• ParFally	also	expressible	through	graph	pa`ern:	
• ConjuncFon	corresponds	to	specificaFons	of	several	filters	
• DisjuncFon	corresponds	to	applicaFon	of	filters	in	alternaFve	
pa`erns
Filter Functions: Boolean
operators
UnFl	now,	only	basic	formaong	seong	for	results:	
• How	can	one	retrieve	defined	parts	of	the	output	set?	
• How	are	the	results	ordered?	
• Can	duplicate	result	rows	be	removed	instantaneously?
Result Sorting
PREFIX	dbo:<h`p://dbpedia.org/ontology/>	
PREFIX	dbp:<h`p://dbpedia.org/property/>	
SELECT		*	WHERE	{		
?book				a																																			dbo:Book	.	
?book			dbo:author																			?author.	
?book			dbo:numberOfPages		?pages.	
?book			dbp:name																						?name.	
FILTER	(?pages	>	500)	
FILTER	(langMATCHES(LANG(?name),"en))	
	}	ORDER	BY	?pages	LIMIT	10
Try it yourself: dbpedia.org/sparql/
Resulting Sorting
• SorFng	same	as	with	filter	comparison	operators		
• SorFng	of	URIs	alphabeFcally	as	sequence	of	characters		
Other	possible	specificaFons:		
•	ORDER	BY	DESC(?price):	descending	
•	ORDER	BY	ASC(?price):	ascending,	default	seong	
•	ORDER	BY	DESC(?price),	?Ftle:	hierarchical	classificaFon	criteria
LIMIT, OFFSET, DISTINCT
RestricFon	of	output	set:	
• LIMIT:	maximal	number	of	results	(table	rows)	
• OFFSET:	posiFon	of	the	first	delivered	result	
• SELECT	DISTINCT:	removal	of	duplicate	table	rows		
LIMIT	and	OFFSET	only	make	sense	with	ORDER	BY!
Hands-on Bio2RDF
• SPARQL endpoint
• http://sparql.openlifedata.org/
• Datasets
• http://download.bio2rdf.org/release/3/
release.html
Hands-on DIY -1
DESCRIBE
<http://bio2rdf.org/drugbank:DB00088>
The DESCRIBE query result clause allows the server to return
whatever RDF it wants that describes the given resource(s).
Hands-on Bio2RDF -2
<http://bio2rdf.org/drugbank:DB00088>
• Retrieve title, affected organism, target and group
of this Drug
TIP: View it as NTriples to construct your query!
Hands-on Bio2RDF - 3
SELECT * WHERE {
?drug a
<http://bio2rdf.org/drugbank_vocabulary:Drug>. }
• filter for drugs starting with A
Hands-on Bio2RDF -3
SELECT * WHERE {
?drug a
<http:bio2rdf.orgdrugbank_vocabulary:Drug>. }
• filter for drugs starting with A
• FILTER regex(?title, "A")
Hands-on Bio2RDF -3
SELECT * WHERE {
?drug a
<http://bio2rdf.org/drugbank_vocabulary:Drug>. }
• filter for drugs starting with A
• FILTER regex(?title, “A")
• sort them alphabetically
Hands-on DIY
• Get 100 drug-metabolizing enzymes
• Get phenotypes and genes associated with
OMIM diseases
• Retrieve unique diseases and publications
associated with the BRCA1 gene
Hands-on DIY
• Get 100 drug-metabolizing enzymes
• Get phenotypes and genes associated with
OMIM diseases
• Retrieve unique diseases and publications
associated with the BRCA1 gene
TIPS:
- View the resource as NTriples to construct your query
- Use prefix.cc to look up prefixes
- Always use LIMIT
- Start by getting results one triple at a time and build up.
Answer 1
PREFIX dv: <http://bio2rdf.org/drugbank_vocabulary:>

PREFIX dct: <http://purl.org/dc/terms/>

SELECT distinct ?enzyme_name ?drug_name 

{

?s a dv:Enzyme-Relation .

?s dv:enzyme/dct:title ?enzyme_name .

?s dv:drug/dct:title ?drug_name .

} 

LIMIT 100
Answer 2
PREFIX om: <http://bio2rdf.org/omim_vocabulary:>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX b: <http://bio2rdf.org/bio2rdf_vocabulary:>
SELECT * {
?s a om:Phenotype .
?s dct:title ?name .
?s om:clinical-synopsis ?cs .
?cs om:feature ?f .
?f om:x-umls/b:identifier ?umls .
?f om:x-hp/dct:identifier ?hp .
?s om:phenotype-map ?pm .
?pm om:gene-symbol ?gene.
} LIMIT 10
Answer 3
PREFIX om: <http://bio2rdf.org/omim_vocabulary:>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX hgnc:<http://bio2rdf.org/hgnc.symbol>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?geneName ?name ?pubmedArticle{
?s a om:Phenotype .
?s dct:title ?name .
?s om:phenotype-map ?pm .
?pm om:gene-symbol ?gene.
?gene dct:title ?geneName.
?s om:article ?pubmed.
?pubmed dct:title ?pubmedArticle.
FILTER regex(?gene, “BRCA1") }
SPARQL Components
#	prefix	declara;ons	
PREFIX	foo:	<h`p://example.com/resources/>	
#	dataset	defini;on	
FROM		
#	result	clause	
SELECT		
#	query	pa@ern	
WHERE	{	
				...	
}	
#	query	modifiers	
ORDER	BY	...
Summary
BASIC Structure
PREFIX
WHERE
GRAPH Pattern
simple graph pattern
{…}
OPTIONAL
UNION
FILTER
LANG
DATATYPE
REGEX
OUTPUT Format
SELECT
CONSTRUCT
ASK
DESCRIBE
MODIFIERS
ORDER BY
LIMIT
OFFSET
DISTINCT
THANK YOU!
QUESTIONS?
@AmrapaliZ
amrapali.j.zaveri@maastrichtuniversity.nl
Contact me if you are interested in doing a project
at the Institute of Data Science, Uni Maastricht!

Más contenido relacionado

Similar a Introduction to Bio SPARQL

Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
Emanuele Della Valle
 
Consuming Linked Data 4/5 Semtech2011
Consuming Linked Data 4/5 Semtech2011Consuming Linked Data 4/5 Semtech2011
Consuming Linked Data 4/5 Semtech2011
Juan Sequeda
 
Health Datapalooza 2013: Open Government Data - Natasha Noy
Health Datapalooza 2013: Open Government Data - Natasha NoyHealth Datapalooza 2013: Open Government Data - Natasha Noy
Health Datapalooza 2013: Open Government Data - Natasha Noy
Health Data Consortium
 
Introduction of semantic technology for SAS programmers
Introduction of semantic technology for SAS programmersIntroduction of semantic technology for SAS programmers
Introduction of semantic technology for SAS programmers
Kevin Lee
 

Similar a Introduction to Bio SPARQL (20)

Querying Linked Data
Querying Linked DataQuerying Linked Data
Querying Linked Data
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
Grails And The Semantic Web
Grails And The Semantic WebGrails And The Semantic Web
Grails And The Semantic Web
 
Consuming Linked Data 4/5 Semtech2011
Consuming Linked Data 4/5 Semtech2011Consuming Linked Data 4/5 Semtech2011
Consuming Linked Data 4/5 Semtech2011
 
Bio2RDF@BH2010
Bio2RDF@BH2010Bio2RDF@BH2010
Bio2RDF@BH2010
 
Getting the best of Linked Data and Property Graphs: rdf2neo and the KnetMine...
Getting the best of Linked Data and Property Graphs: rdf2neo and the KnetMine...Getting the best of Linked Data and Property Graphs: rdf2neo and the KnetMine...
Getting the best of Linked Data and Property Graphs: rdf2neo and the KnetMine...
 
BioSD Tutorial 2014 Editition
BioSD Tutorial 2014 EdititionBioSD Tutorial 2014 Editition
BioSD Tutorial 2014 Editition
 
BioSamples Database Linked Data, SWAT4LS Tutorial
BioSamples Database Linked Data, SWAT4LS TutorialBioSamples Database Linked Data, SWAT4LS Tutorial
BioSamples Database Linked Data, SWAT4LS Tutorial
 
SPARQL-DL - Theory & Practice
SPARQL-DL - Theory & PracticeSPARQL-DL - Theory & Practice
SPARQL-DL - Theory & Practice
 
Semantic Web
Semantic WebSemantic Web
Semantic Web
 
Semantic Web
Semantic WebSemantic Web
Semantic Web
 
Knetminer Backend Training, Nov 2018
Knetminer Backend Training, Nov 2018Knetminer Backend Training, Nov 2018
Knetminer Backend Training, Nov 2018
 
Health Datapalooza 2013: Open Government Data - Natasha Noy
Health Datapalooza 2013: Open Government Data - Natasha NoyHealth Datapalooza 2013: Open Government Data - Natasha Noy
Health Datapalooza 2013: Open Government Data - Natasha Noy
 
Introduction of semantic technology for SAS programmers
Introduction of semantic technology for SAS programmersIntroduction of semantic technology for SAS programmers
Introduction of semantic technology for SAS programmers
 
Overview of SureChEMBL
Overview of SureChEMBLOverview of SureChEMBL
Overview of SureChEMBL
 
Linked APIs for Life Sciences Tutorial at SWAT4LS 3011
Linked APIs for Life Sciences Tutorial at SWAT4LS 3011Linked APIs for Life Sciences Tutorial at SWAT4LS 3011
Linked APIs for Life Sciences Tutorial at SWAT4LS 3011
 
Sparql a simple knowledge query
Sparql  a simple knowledge querySparql  a simple knowledge query
Sparql a simple knowledge query
 
Producing, publishing and consuming linked data - CSHALS 2013
Producing, publishing and consuming linked data - CSHALS 2013Producing, publishing and consuming linked data - CSHALS 2013
Producing, publishing and consuming linked data - CSHALS 2013
 
2009 0807 Lod Gmod
2009 0807 Lod Gmod2009 0807 Lod Gmod
2009 0807 Lod Gmod
 

Más de Amrapali Zaveri, PhD

Más de Amrapali Zaveri, PhD (16)

Data Quality and the FAIR principles
Data Quality and the FAIR principlesData Quality and the FAIR principles
Data Quality and the FAIR principles
 
Workshop on Data Quality Management in Wikidata
Workshop on Data Quality Management in WikidataWorkshop on Data Quality Management in Wikidata
Workshop on Data Quality Management in Wikidata
 
ESOF Panel 2018
ESOF Panel 2018ESOF Panel 2018
ESOF Panel 2018
 
CrowdED: Guideline for optimal Crowdsourcing Experimental Design
CrowdED: Guideline for optimal Crowdsourcing Experimental DesignCrowdED: Guideline for optimal Crowdsourcing Experimental Design
CrowdED: Guideline for optimal Crowdsourcing Experimental Design
 
MetaCrowd: Crowdsourcing Gene Expression Metadata Quality Assessment
MetaCrowd: Crowdsourcing Gene Expression Metadata Quality AssessmentMetaCrowd: Crowdsourcing Gene Expression Metadata Quality Assessment
MetaCrowd: Crowdsourcing Gene Expression Metadata Quality Assessment
 
smartAPI: Towards a more intelligent network of Web APIs
smartAPI: Towards a more intelligent network of Web APIssmartAPI: Towards a more intelligent network of Web APIs
smartAPI: Towards a more intelligent network of Web APIs
 
Crowdsourcing Linked Data Quality Assessment
Crowdsourcing Linked Data Quality AssessmentCrowdsourcing Linked Data Quality Assessment
Crowdsourcing Linked Data Quality Assessment
 
Linked Data Quality Assessment: A Survey
Linked Data Quality Assessment: A SurveyLinked Data Quality Assessment: A Survey
Linked Data Quality Assessment: A Survey
 
Amrapali Zaveri Defense
Amrapali Zaveri DefenseAmrapali Zaveri Defense
Amrapali Zaveri Defense
 
LDQ 2014 DQ Methodology
LDQ 2014 DQ MethodologyLDQ 2014 DQ Methodology
LDQ 2014 DQ Methodology
 
LOD-SEM
LOD-SEMLOD-SEM
LOD-SEM
 
TripleCheckMate
TripleCheckMateTripleCheckMate
TripleCheckMate
 
Towards Biomedical Data Integration for Analyzing the Evolution of Cognition
Towards Biomedical Data Integration for Analyzing the Evolution of CognitionTowards Biomedical Data Integration for Analyzing the Evolution of Cognition
Towards Biomedical Data Integration for Analyzing the Evolution of Cognition
 
User-driven Quality Evaluation of DBpedia
User-driven Quality Evaluation of DBpediaUser-driven Quality Evaluation of DBpedia
User-driven Quality Evaluation of DBpedia
 
Converting GHO to RDF
Converting GHO to RDFConverting GHO to RDF
Converting GHO to RDF
 
ReDD-Observatory
ReDD-ObservatoryReDD-Observatory
ReDD-Observatory
 

Último

Último (20)

How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

Introduction to Bio SPARQL