SlideShare uma empresa Scribd logo
1 de 25
SPARQL Tutorial@TarguMures Semantic Web Meetup June 22, 2011 Adonis Damian
Introduction - SPARQL SPARQL is a query language/engine for RDF graphs.  An RDF graph is a set of triples. A flexible and extensible way to represent information about resources A concept similar to SQL for data bases. A W3C standard query language to fetch data from distributed Semantic Web data models.  Can query a triple store or data on the Web (at a given URL). It provides facilities to: extract information in the form of URIs, blank nodes, plain and typed literals.  extract RDF subgraphs.  construct new RDF graphs based on information in the queried graphs
What is RDF? RDF is a data model of graphs of subject, predicate, object triples. Resources are represented with URIs, which can be abbreviated as prefixed names Objects can be literals: strings, integers, booleans, etc.
Short Ontology Introduction
Reasoning OWL
A SPARQL query comprises, in order: Prefix declarations, for abbreviating URIs Dataset definition, stating what RDF graph(s) are being queried A result clause, identifying what information to return from the query The query pattern, specifying what to query for in the underlying dataset Query modifiers, slicing, ordering, and otherwise rearranging query results # prefix declarations PREFIX foo: http://example.com/resources/ ... # dataset definition FROM ... # result clause SELECT ... # query pattern WHERE { ... } # query modifiers ORDER BY ...
SPARQL Landscape SPARQL 1.0 became a standard in January, 2008, and included: SPARQL 1.0 Query Language SPARQL 1.0 Protocol SPARQL Results XML Format SPARQL 1.1 is in-progress, and includes: Updated 1.1 versions of SPARQL Query and SPARQL Protocol SPARQL 1.1 Update SPARQL 1.1 Uniform HTTP Protocol for Managing RDF Graphs SPARQL 1.1 Service Descriptions SPARQL 1.1 Basic Federated Query
First Query Query DBPedia at http://dbpedia.org/snorql/ Give me all the objects that are a person SELECT ?person WHERE {    ?person rdf:typefoaf:Person. } SPARQL variables start with a ? and can match any node (resource or literal) in the RDF dataset. Triple patterns are just like triples, except that any of the parts of a triple can be replaced with a variable. The SELECT result clause returns a table of variables and values that satisfy the query. Dataset: http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl
Multiple triple patterns Give me all the people that had a Nobel Prize idea SELECT ?person ?idea WHERE {    ?person rdf:typefoaf:Person.    ?person <http://dbpedia.org/ontology/notableIdea> ?idea. } Alternative SELECT * WHERE {    ?person a foaf:Person; 	<http://dbpedia.org/ontology/notableIdea> ?idea. } We can use multiple triple patterns to retrieve multiple properties about a particular resource Shortcut: SELECT * selects all variables mentioned in the query User a instead of rdf:type Use ; to refer to the same subject
Multiple triple patterns: traversing a graph Find me all the artists that were born in Brazil SELECT * WHERE {    ?person a <http://dbpedia.org/ontology/Artist>;          <http://dbpedia.org/ontology/birthPlace> ?birthPlace.    ?birthPlace <http://dbpedia.org/ontology/country>  ?country.    ?country rdfs:label "Brazil"@en. } country Artist Birth Place birthPlace Country label Rdfs:label
Limit the number of results Find me 50 example concepts in the DBPedia dataset. SELECT DISTINCT ?concept WHERE {  	?s a ?concept . } ORDER BY DESC(?concept) LIMIT 50 LIMIT is a solution modifier that limits the number of rows returned from a query. SPARQL has two other solution modifiers: ORDER BY for sorting query solutions on the value of one or more variables OFFSET, used in conjunction with LIMIT and ORDER BY to take a slice of a sorted solution set (e.g. for paging) The DISTINCT modifier eliminates duplicate rows from the query results.
Basic SPARQL filters Find me all landlocked countries with a population greater than 15 million. PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>         PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> SELECT ?country_name ?population WHERE {     ?country a type:LandlockedCountries ; rdfs:label ?country_name ; prop:populationEstimate ?population .     FILTER (?population > 15000000) . } FILTER constraints use boolean conditions to filter out unwanted query results. Shortcut: a semicolon (;) can be used to separate multiple triple patterns that share the same subject. (?country is the shared subject above.) rdfs:label is a common predicate for giving a human-friendly label to a resource. Note all the translated duplicates in the results. How can we deal with that?
Basic SPARQL filters - language Find me all landlocked countries with a population greater than 15 million and show me their English name PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>         PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> SELECT ?country_name ?population WHERE {     ?country a type:LandlockedCountries ; rdfs:label ?country_name ; prop:populationEstimate ?population .     FILTER (?population > 15000000) .     FILTER (lang(?country_name) = "en") . }
Filters using a range Find me all the artists born in Austria in the 19thsencury SELECT * WHERE {    ?person a <http://dbpedia.org/ontology/Artist>;          <http://dbpedia.org/ontology/birthPlace> ?birthPlace.    ?birthPlace <http://dbpedia.org/ontology/country>  ?country.    ?country rdfs:label "Austria"@en.    ?person <http://dbpedia.org/property/dateOfBirth> ?dob    FILTER (?dob > "1/1/1800"^^xsd:date &&           ?dob < "12/31/1899"^^xsd:date) }
SPARQL built-in filter functions Logical: !, &&, || Math: +, -, *, / Comparison: =, !=, >, <, ... SPARQL tests: isURI, isBlank, isLiteral, bound SPARQL accessors: str, lang, datatype Other: sameTerm, langMatches, regex
Finding artists' info - the wrong way Find all Jamendo artists along with their image, home page, and the location they're near. PREFIX mo: <http://purl.org/ontology/mo/> PREFIX foaf:  <http://xmlns.com/foaf/0.1/> SELECT ?name ?img ?hp ?loc WHERE {   ?a amo:MusicArtist ; foaf:name ?name ; foaf:img ?img ; foaf:homepage ?hp ; foaf:based_near ?loc . }  Jamendo has information on about 3,500 artists. Trying the query, though, we only get 2,667 results. What's wrong? Query at: DBTune.org'sJamendo-specific SPARQL endpoint
Finding artists' info - the right way PREFIX mo: <http://purl.org/ontology/mo/> PREFIX foaf:  <http://xmlns.com/foaf/0.1/> SELECT ?name ?img ?hp ?loc WHERE {   ?a amo:MusicArtist ; foaf:name ?name .   OPTIONAL { ?a foaf:img ?img }   OPTIONAL { ?a foaf:homepage ?hp }   OPTIONAL { ?a foaf:based_near ?loc } } OPTIONAL tries to match a graph pattern, but doesn't fail the whole query if the optional match fails. If an OPTIONAL pattern fails to match for a particular solution, any variables in that pattern remain unbound (no value) for that solution.
Querying alternatives Find me everything about Hawaii SELECT ?property ?hasValue ?isValueOf WHERE {   { <http://dbpedia.org/resource/Hawaii> ?property ?hasValue }   UNION   { ?isValueOf ?property <http://dbpedia.org/resource/Hawaii> } } The UNION keyword forms a disjunction of two graph patterns. Solutions to both sides of the UNION are included in the results.
RDF Datasets We said earlier that SPARQL queries are executed against RDF datasets, consisting of RDF graphs. So far, all of our queries have been against a single graph. In SPARQL, this is known as the default graph. RDF datasets are composed of the default graph and zero or more named graphs, identified by a URI. Named graphs can be specified with one or more FROM NAMED clauses, or they can be hardwired into a particular SPARQL endpoint. The SPARQL GRAPH keyword allows portions of a query to match against the named graphs in the RDF dataset. Anything outside a GRAPH clause matches against the default graph.
RDF Datasets
Querying named graphs Find me people who have been involved with at least three ISWC or ESWC conference events. SELECT DISTINCT ?person ?name WHERE {     ?person foaf:name ?name .     GRAPH ?g1 { ?person a foaf:Person }     GRAPH ?g2 { ?person a foaf:Person }     GRAPH ?g3 { ?person a foaf:Person }     FILTER(?g1 != ?g2 && ?g1 != ?g3 && ?g2 != ?g3) . }  N.B. The FILTER assures that we're finding a person who occurs in three distinct graphs. N.B. The Web interface we use for this SPARQL query defines the foaf: prefix, which is why we omit it here. Try it with the data.semanticweb.org SPARQL endpoint.
Transforming between vocabularies Convert FOAF data to VCard data. PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT {    ?X vCard:FN ?name .   ?X vCard:URL ?url .   ?X vCard:TITLE ?title . } FROM <http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf> WHERE {    OPTIONAL { ?X foaf:name ?name . FILTER isLiteral(?name) . }   OPTIONAL { ?X foaf:homepage ?url . FILTER isURI(?url) . }   OPTIONAL { ?X foaf:title ?title . FILTER isLiteral(?title) . } } The result RDF graph is created by taking the results of the equivalent SELECT query and filling in the values of variables that occur in the CONSTRUCT template. Triples are not created in the result graph. Try it with ARQ or OpenLink's Virtuoso. (Expected results.)
ASKing a question Is the Amazon river longer than the Nile River? PREFIX prop: <http://dbpedia.org/property/> ASK {   <http://dbpedia.org/resource/Amazon_River> prop:length ?amazon .   <http://dbpedia.org/resource/Nile> prop:length ?nile .   FILTER(?amazon > ?nile) . } As with SELECT queries, the boolean result is (by default) encoded in an SPARQL Results Format XML document. Shortcut: the WHERE keyword is optional--not only in ASK queries but in all SPARQL queries.
Learning about a resource Tell me whatever you'd like to tell me about the Amazon river. PREFIX prop: <http://dbpedia.org/property/> DESCRIBE ?amazon {   ?amazon rdfs:label "Amazon River"@en. } Because the server is free to interpret DESCRIBE as it sees fit, DESCRIBE queries are not interoperable. Common implementations include concise-bounded descriptions, named graphs, minimum self-contained graphs, etc
What’s new in SPARQL 1.1 Learn about SPARQL 1.1 by David Becket

Mais conteúdo relacionado

Mais procurados

AI, Knowledge Representation and Graph Databases -
 Key Trends in Data Science
AI, Knowledge Representation and Graph Databases -
 Key Trends in Data ScienceAI, Knowledge Representation and Graph Databases -
 Key Trends in Data Science
AI, Knowledge Representation and Graph Databases -
 Key Trends in Data ScienceOptum
 
DBpedia Tutorial - Feb 2015, Dublin
DBpedia Tutorial - Feb 2015, DublinDBpedia Tutorial - Feb 2015, Dublin
DBpedia Tutorial - Feb 2015, Dublinm_ackermann
 
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...Jeff Z. Pan
 
Slides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property GraphsSlides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property GraphsDATAVERSITY
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDFNarni Rajesh
 
Knowledge Graph Introduction
Knowledge Graph IntroductionKnowledge Graph Introduction
Knowledge Graph IntroductionSören Auer
 
Debunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative FactsDebunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative FactsNeo4j
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshellFabien Gandon
 
Orion Context Broker 1.15.0
Orion Context Broker 1.15.0Orion Context Broker 1.15.0
Orion Context Broker 1.15.0Fermin Galan
 
The Semantic Web #9 - Web Ontology Language (OWL)
The Semantic Web #9 - Web Ontology Language (OWL)The Semantic Web #9 - Web Ontology Language (OWL)
The Semantic Web #9 - Web Ontology Language (OWL)Myungjin Lee
 
Data warehouse architecture
Data warehouse architectureData warehouse architecture
Data warehouse architecturepcherukumalla
 
Querying the Wikidata Knowledge Graph
Querying the Wikidata Knowledge GraphQuerying the Wikidata Knowledge Graph
Querying the Wikidata Knowledge GraphIoan Toma
 
Design and manage persistent URIs
Design and manage persistent URIsDesign and manage persistent URIs
Design and manage persistent URIsOpen Data Support
 

Mais procurados (20)

AI, Knowledge Representation and Graph Databases -
 Key Trends in Data Science
AI, Knowledge Representation and Graph Databases -
 Key Trends in Data ScienceAI, Knowledge Representation and Graph Databases -
 Key Trends in Data Science
AI, Knowledge Representation and Graph Databases -
 Key Trends in Data Science
 
SHACL Overview
SHACL OverviewSHACL Overview
SHACL Overview
 
SPARQL Tutorial
SPARQL TutorialSPARQL Tutorial
SPARQL Tutorial
 
DBpedia Tutorial - Feb 2015, Dublin
DBpedia Tutorial - Feb 2015, DublinDBpedia Tutorial - Feb 2015, Dublin
DBpedia Tutorial - Feb 2015, Dublin
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
Linked Data and Knowledge Graphs -- Constructing and Understanding Knowledge ...
 
Slides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property GraphsSlides: Knowledge Graphs vs. Property Graphs
Slides: Knowledge Graphs vs. Property Graphs
 
RDF Data Model
RDF Data ModelRDF Data Model
RDF Data Model
 
Introduction to RDF
Introduction to RDFIntroduction to RDF
Introduction to RDF
 
Knowledge Graph Introduction
Knowledge Graph IntroductionKnowledge Graph Introduction
Knowledge Graph Introduction
 
Debunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative FactsDebunking some “RDF vs. Property Graph” Alternative Facts
Debunking some “RDF vs. Property Graph” Alternative Facts
 
SPARQL in a nutshell
SPARQL in a nutshellSPARQL in a nutshell
SPARQL in a nutshell
 
RDF, linked data and semantic web
RDF, linked data and semantic webRDF, linked data and semantic web
RDF, linked data and semantic web
 
Orion Context Broker 1.15.0
Orion Context Broker 1.15.0Orion Context Broker 1.15.0
Orion Context Broker 1.15.0
 
The Semantic Web #9 - Web Ontology Language (OWL)
The Semantic Web #9 - Web Ontology Language (OWL)The Semantic Web #9 - Web Ontology Language (OWL)
The Semantic Web #9 - Web Ontology Language (OWL)
 
RDF data model
RDF data modelRDF data model
RDF data model
 
Data warehouse architecture
Data warehouse architectureData warehouse architecture
Data warehouse architecture
 
Querying the Wikidata Knowledge Graph
Querying the Wikidata Knowledge GraphQuerying the Wikidata Knowledge Graph
Querying the Wikidata Knowledge Graph
 
Ajax ppt
Ajax pptAjax ppt
Ajax ppt
 
Design and manage persistent URIs
Design and manage persistent URIsDesign and manage persistent URIs
Design and manage persistent URIs
 

Semelhante a Semantic web meetup – sparql tutorial

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
 
Sparql a simple knowledge query
Sparql  a simple knowledge querySparql  a simple knowledge query
Sparql a simple knowledge queryStanley Wang
 
From SQL to SPARQL
From SQL to SPARQLFrom SQL to SPARQL
From SQL to SPARQLGeorge Roth
 
SPARQL Query Forms
SPARQL Query FormsSPARQL Query Forms
SPARQL Query FormsLeigh Dodds
 
Semantic Web(Web 3.0) SPARQL
Semantic Web(Web 3.0) SPARQLSemantic Web(Web 3.0) SPARQL
Semantic Web(Web 3.0) SPARQLDaniel D.J. UM
 
Triplestore and SPARQL
Triplestore and SPARQLTriplestore and SPARQL
Triplestore and SPARQLLino Valdivia
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Storesandyseaborne
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIsJosef Petrák
 
2008 11 13 Hcls Call
2008 11 13 Hcls Call2008 11 13 Hcls Call
2008 11 13 Hcls CallJun Zhao
 
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018Ontotext
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLMyungjin Lee
 
A Little SPARQL in your Analytics
A Little SPARQL in your AnalyticsA Little SPARQL in your Analytics
A Little SPARQL in your AnalyticsDr. Neil Brittliff
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011sesam4able
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011Robert Engels
 
2009 0807 Lod Gmod
2009 0807 Lod Gmod2009 0807 Lod Gmod
2009 0807 Lod GmodJun Zhao
 

Semelhante a Semantic web meetup – sparql tutorial (20)

Querying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQLQuerying the Semantic Web with SPARQL
Querying the Semantic Web with SPARQL
 
Sparql
SparqlSparql
Sparql
 
Sparql a simple knowledge query
Sparql  a simple knowledge querySparql  a simple knowledge query
Sparql a simple knowledge query
 
From SQL to SPARQL
From SQL to SPARQLFrom SQL to SPARQL
From SQL to SPARQL
 
SPARQL Query Forms
SPARQL Query FormsSPARQL Query Forms
SPARQL Query Forms
 
Sparql
SparqlSparql
Sparql
 
Introduction to SPARQL
Introduction to SPARQLIntroduction to SPARQL
Introduction to SPARQL
 
Semantic Web(Web 3.0) SPARQL
Semantic Web(Web 3.0) SPARQLSemantic Web(Web 3.0) SPARQL
Semantic Web(Web 3.0) SPARQL
 
Triplestore and SPARQL
Triplestore and SPARQLTriplestore and SPARQL
Triplestore and SPARQL
 
NoSQL and Triple Stores
NoSQL and Triple StoresNoSQL and Triple Stores
NoSQL and Triple Stores
 
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
2011 4IZ440 Semantic Web – RDF, SPARQL, and software APIs
 
2008 11 13 Hcls Call
2008 11 13 Hcls Call2008 11 13 Hcls Call
2008 11 13 Hcls Call
 
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018
Transforming Your Data with GraphDB: GraphDB Fundamentals, Jan 2018
 
Data in RDF
Data in RDFData in RDF
Data in RDF
 
The Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQLThe Semantic Web #10 - SPARQL
The Semantic Web #10 - SPARQL
 
A Little SPARQL in your Analytics
A Little SPARQL in your AnalyticsA Little SPARQL in your Analytics
A Little SPARQL in your Analytics
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
 
Sesam4 project presentation sparql - april 2011
Sesam4   project presentation sparql - april 2011Sesam4   project presentation sparql - april 2011
Sesam4 project presentation sparql - april 2011
 
2009 0807 Lod Gmod
2009 0807 Lod Gmod2009 0807 Lod Gmod
2009 0807 Lod Gmod
 
RDF validation tutorial
RDF validation tutorialRDF validation tutorial
RDF validation tutorial
 

Último

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 

Último (20)

Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 

Semantic web meetup – sparql tutorial

  • 1. SPARQL Tutorial@TarguMures Semantic Web Meetup June 22, 2011 Adonis Damian
  • 2. Introduction - SPARQL SPARQL is a query language/engine for RDF graphs. An RDF graph is a set of triples. A flexible and extensible way to represent information about resources A concept similar to SQL for data bases. A W3C standard query language to fetch data from distributed Semantic Web data models. Can query a triple store or data on the Web (at a given URL). It provides facilities to: extract information in the form of URIs, blank nodes, plain and typed literals. extract RDF subgraphs. construct new RDF graphs based on information in the queried graphs
  • 3. What is RDF? RDF is a data model of graphs of subject, predicate, object triples. Resources are represented with URIs, which can be abbreviated as prefixed names Objects can be literals: strings, integers, booleans, etc.
  • 6. A SPARQL query comprises, in order: Prefix declarations, for abbreviating URIs Dataset definition, stating what RDF graph(s) are being queried A result clause, identifying what information to return from the query The query pattern, specifying what to query for in the underlying dataset Query modifiers, slicing, ordering, and otherwise rearranging query results # prefix declarations PREFIX foo: http://example.com/resources/ ... # dataset definition FROM ... # result clause SELECT ... # query pattern WHERE { ... } # query modifiers ORDER BY ...
  • 7. SPARQL Landscape SPARQL 1.0 became a standard in January, 2008, and included: SPARQL 1.0 Query Language SPARQL 1.0 Protocol SPARQL Results XML Format SPARQL 1.1 is in-progress, and includes: Updated 1.1 versions of SPARQL Query and SPARQL Protocol SPARQL 1.1 Update SPARQL 1.1 Uniform HTTP Protocol for Managing RDF Graphs SPARQL 1.1 Service Descriptions SPARQL 1.1 Basic Federated Query
  • 8. First Query Query DBPedia at http://dbpedia.org/snorql/ Give me all the objects that are a person SELECT ?person WHERE { ?person rdf:typefoaf:Person. } SPARQL variables start with a ? and can match any node (resource or literal) in the RDF dataset. Triple patterns are just like triples, except that any of the parts of a triple can be replaced with a variable. The SELECT result clause returns a table of variables and values that satisfy the query. Dataset: http://downloads.dbpedia.org/3.6/dbpedia_3.6.owl
  • 9. Multiple triple patterns Give me all the people that had a Nobel Prize idea SELECT ?person ?idea WHERE { ?person rdf:typefoaf:Person. ?person <http://dbpedia.org/ontology/notableIdea> ?idea. } Alternative SELECT * WHERE { ?person a foaf:Person; <http://dbpedia.org/ontology/notableIdea> ?idea. } We can use multiple triple patterns to retrieve multiple properties about a particular resource Shortcut: SELECT * selects all variables mentioned in the query User a instead of rdf:type Use ; to refer to the same subject
  • 10. Multiple triple patterns: traversing a graph Find me all the artists that were born in Brazil SELECT * WHERE { ?person a <http://dbpedia.org/ontology/Artist>; <http://dbpedia.org/ontology/birthPlace> ?birthPlace. ?birthPlace <http://dbpedia.org/ontology/country> ?country. ?country rdfs:label "Brazil"@en. } country Artist Birth Place birthPlace Country label Rdfs:label
  • 11. Limit the number of results Find me 50 example concepts in the DBPedia dataset. SELECT DISTINCT ?concept WHERE { ?s a ?concept . } ORDER BY DESC(?concept) LIMIT 50 LIMIT is a solution modifier that limits the number of rows returned from a query. SPARQL has two other solution modifiers: ORDER BY for sorting query solutions on the value of one or more variables OFFSET, used in conjunction with LIMIT and ORDER BY to take a slice of a sorted solution set (e.g. for paging) The DISTINCT modifier eliminates duplicate rows from the query results.
  • 12. Basic SPARQL filters Find me all landlocked countries with a population greater than 15 million. PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> SELECT ?country_name ?population WHERE { ?country a type:LandlockedCountries ; rdfs:label ?country_name ; prop:populationEstimate ?population . FILTER (?population > 15000000) . } FILTER constraints use boolean conditions to filter out unwanted query results. Shortcut: a semicolon (;) can be used to separate multiple triple patterns that share the same subject. (?country is the shared subject above.) rdfs:label is a common predicate for giving a human-friendly label to a resource. Note all the translated duplicates in the results. How can we deal with that?
  • 13. Basic SPARQL filters - language Find me all landlocked countries with a population greater than 15 million and show me their English name PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX type: <http://dbpedia.org/class/yago/> PREFIX prop: <http://dbpedia.org/property/> SELECT ?country_name ?population WHERE { ?country a type:LandlockedCountries ; rdfs:label ?country_name ; prop:populationEstimate ?population . FILTER (?population > 15000000) . FILTER (lang(?country_name) = "en") . }
  • 14. Filters using a range Find me all the artists born in Austria in the 19thsencury SELECT * WHERE { ?person a <http://dbpedia.org/ontology/Artist>; <http://dbpedia.org/ontology/birthPlace> ?birthPlace. ?birthPlace <http://dbpedia.org/ontology/country> ?country. ?country rdfs:label "Austria"@en. ?person <http://dbpedia.org/property/dateOfBirth> ?dob FILTER (?dob > "1/1/1800"^^xsd:date && ?dob < "12/31/1899"^^xsd:date) }
  • 15. SPARQL built-in filter functions Logical: !, &&, || Math: +, -, *, / Comparison: =, !=, >, <, ... SPARQL tests: isURI, isBlank, isLiteral, bound SPARQL accessors: str, lang, datatype Other: sameTerm, langMatches, regex
  • 16. Finding artists' info - the wrong way Find all Jamendo artists along with their image, home page, and the location they're near. PREFIX mo: <http://purl.org/ontology/mo/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?img ?hp ?loc WHERE { ?a amo:MusicArtist ; foaf:name ?name ; foaf:img ?img ; foaf:homepage ?hp ; foaf:based_near ?loc . } Jamendo has information on about 3,500 artists. Trying the query, though, we only get 2,667 results. What's wrong? Query at: DBTune.org'sJamendo-specific SPARQL endpoint
  • 17. Finding artists' info - the right way PREFIX mo: <http://purl.org/ontology/mo/> PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?name ?img ?hp ?loc WHERE { ?a amo:MusicArtist ; foaf:name ?name . OPTIONAL { ?a foaf:img ?img } OPTIONAL { ?a foaf:homepage ?hp } OPTIONAL { ?a foaf:based_near ?loc } } OPTIONAL tries to match a graph pattern, but doesn't fail the whole query if the optional match fails. If an OPTIONAL pattern fails to match for a particular solution, any variables in that pattern remain unbound (no value) for that solution.
  • 18. Querying alternatives Find me everything about Hawaii SELECT ?property ?hasValue ?isValueOf WHERE { { <http://dbpedia.org/resource/Hawaii> ?property ?hasValue } UNION { ?isValueOf ?property <http://dbpedia.org/resource/Hawaii> } } The UNION keyword forms a disjunction of two graph patterns. Solutions to both sides of the UNION are included in the results.
  • 19. RDF Datasets We said earlier that SPARQL queries are executed against RDF datasets, consisting of RDF graphs. So far, all of our queries have been against a single graph. In SPARQL, this is known as the default graph. RDF datasets are composed of the default graph and zero or more named graphs, identified by a URI. Named graphs can be specified with one or more FROM NAMED clauses, or they can be hardwired into a particular SPARQL endpoint. The SPARQL GRAPH keyword allows portions of a query to match against the named graphs in the RDF dataset. Anything outside a GRAPH clause matches against the default graph.
  • 21. Querying named graphs Find me people who have been involved with at least three ISWC or ESWC conference events. SELECT DISTINCT ?person ?name WHERE { ?person foaf:name ?name . GRAPH ?g1 { ?person a foaf:Person } GRAPH ?g2 { ?person a foaf:Person } GRAPH ?g3 { ?person a foaf:Person } FILTER(?g1 != ?g2 && ?g1 != ?g3 && ?g2 != ?g3) . } N.B. The FILTER assures that we're finding a person who occurs in three distinct graphs. N.B. The Web interface we use for this SPARQL query defines the foaf: prefix, which is why we omit it here. Try it with the data.semanticweb.org SPARQL endpoint.
  • 22. Transforming between vocabularies Convert FOAF data to VCard data. PREFIX vCard: <http://www.w3.org/2001/vcard-rdf/3.0#> PREFIX foaf: <http://xmlns.com/foaf/0.1/> CONSTRUCT { ?X vCard:FN ?name . ?X vCard:URL ?url . ?X vCard:TITLE ?title . } FROM <http://dig.csail.mit.edu/2008/webdav/timbl/foaf.rdf> WHERE { OPTIONAL { ?X foaf:name ?name . FILTER isLiteral(?name) . } OPTIONAL { ?X foaf:homepage ?url . FILTER isURI(?url) . } OPTIONAL { ?X foaf:title ?title . FILTER isLiteral(?title) . } } The result RDF graph is created by taking the results of the equivalent SELECT query and filling in the values of variables that occur in the CONSTRUCT template. Triples are not created in the result graph. Try it with ARQ or OpenLink's Virtuoso. (Expected results.)
  • 23. ASKing a question Is the Amazon river longer than the Nile River? PREFIX prop: <http://dbpedia.org/property/> ASK { <http://dbpedia.org/resource/Amazon_River> prop:length ?amazon . <http://dbpedia.org/resource/Nile> prop:length ?nile . FILTER(?amazon > ?nile) . } As with SELECT queries, the boolean result is (by default) encoded in an SPARQL Results Format XML document. Shortcut: the WHERE keyword is optional--not only in ASK queries but in all SPARQL queries.
  • 24. Learning about a resource Tell me whatever you'd like to tell me about the Amazon river. PREFIX prop: <http://dbpedia.org/property/> DESCRIBE ?amazon { ?amazon rdfs:label "Amazon River"@en. } Because the server is free to interpret DESCRIBE as it sees fit, DESCRIBE queries are not interoperable. Common implementations include concise-bounded descriptions, named graphs, minimum self-contained graphs, etc
  • 25. What’s new in SPARQL 1.1 Learn about SPARQL 1.1 by David Becket