• Save
Learning sparql 2012 12
Upcoming SlideShare
Loading in...5
×
 

Learning sparql 2012 12

on

  • 3,291 views

Tutorial on SPARQL 1.1 given at SWAT4LS 2012 in paris to a full room. This material covers enough to get started and includes working with Topbraid Composer.

Tutorial on SPARQL 1.1 given at SWAT4LS 2012 in paris to a full room. This material covers enough to get started and includes working with Topbraid Composer.

Statistics

Views

Total Views
3,291
Views on SlideShare
3,142
Embed Views
149

Actions

Likes
8
Downloads
0
Comments
0

7 Embeds 149

http://lanyrd.com 54
http://www.linkedin.com 51
http://www.scoop.it 36
http://localhost 4
https://twitter.com 2
http://webcache.googleusercontent.com 1
http://www.slashdocs.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

CC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike LicenseCC Attribution-NonCommercial-ShareAlike License

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Learning sparql 2012 12 Learning sparql 2012 12 Presentation Transcript

  • SPARQL UniProt.RDF Jerven Bolleman Developer Swiss-Prot Group Swiss Institute of BioinformaticsTuesday, December 4, 2012
  • A few notes before we begin • SPARQL 1 – Some what useful – Standardized in 2008 • SPARQL 1.1 – Very useful – Currently in recommended standard • Still finding incompatibilities • Or not yet implemented features © 2012 SIBTuesday, December 4, 2012
  • Raise your hand if you have questions © 2012 SIBTuesday, December 4, 2012
  • Tutorial plan • Set up Topbraid Composer – Skipped in talk – On VM • Gather data from uniprot website – Already there. Text • Learn sparql You do not need Topbraid Composer to use UniProt RDF data or do sparql queries. You can use beta.sparql.uniprot.org as well. © 2012 SIBTuesday, December 4, 2012
  • Download and install Topbraid composer • Requirements – Sun/Oracle JVM • Go to – http://www.topquadrant.com/products/ TB_download.html – Register – Select any edition, free is ok for today © 2012 SIBTuesday, December 4, 2012
  • Start Topbraid © 2012 SIBTuesday, December 4, 2012
  • Setting up a workspace for this tutorial • http://www.topquadrant.com/products/TB_download.html © 2012 SIBTuesday, December 4, 2012
  • New project • File > New Project > General © 2012 SIBTuesday, December 4, 2012
  • Gather data from uniprot.org website • In the navigator select the new project you just made. © 2012 SIBTuesday, December 4, 2012
  • Gather data from uniprot.org website Right click on your new project. Select “Import” in the drop down menu • Import RDF or OWL file from the web © 2012 SIBTuesday, December 4, 2012
  • Using the same process download core.owl You can see a html view of this schema ontology at http://www.uniprot.org/core/ © 2012 SIBTuesday, December 4, 2012
  • Gather data from uniprot.org website You can see a html view of this entry at http://www.uniprot.org/taxonomy/40674 © 2012 SIBTuesday, December 4, 2012
  • Gather data from uniprot.org website • Open the mammalia.rdf file by double clicking © 2012 SIBTuesday, December 4, 2012
  • You get a very helpfull dialog. Hit yes © 2012 SIBTuesday, December 4, 2012
  • Its SPARQLy mammal time !! © 2012 SIBTuesday, December 4, 2012
  • Lets look at an single taxon record © 2012 SIBTuesday, December 4, 2012
  • Lets navigate to it in TopBraid • Type the uri as is with the angle brackets © 2012 SIBTuesday, December 4, 2012
  • Investigate the taxon record © 2012 SIBTuesday, December 4, 2012
  • The “Eastern Chipmunk” in turtle © 2012 SIBTuesday, December 4, 2012
  • Turtle is the RDF serialization aligned with SPARQL • Shorthand to avoid typing so much – . ‘dot’ is end statement – ; ‘semi-colon’ repeat subject – , ‘comma’ is repeat subject and predicate • prefix – before ‘:’ is abbreviation of uri © 2012 SIBTuesday, December 4, 2012
  • Why don’t these queries work on the web? • PREFIX – Topbraid composer uses the prefixes defined in the files “overview” tab. – On the web you often have to add these. PREFIX :<http://purl.uniprot.org/core/> SELECT ?x FROM <http://purl.uniprot.org/taxonomy/> WHERE {?x a :Taxon} © 2012 SIBTuesday, December 4, 2012
  • a = rdf:type = <http://www.w3.org/1999/02/22-rdf- syntax-ns#type> © 2012 SIBTuesday, December 4, 2012
  • rdfs:subClassOf taxon:45474 is a more specific classification than taxon:13712 © 2012 SIBTuesday, December 4, 2012
  • rank => “The level, for nomenclatural purposes, of a taxon in a taxonomic hierarchy” © 2012 SIBTuesday, December 4, 2012
  • Why learn SPARQL • Standardized formal query language – implementation independent • SPARQL ➔ SQL (via R2ML) • SPARQL ➔ webservice (via SADI) • SPARQL ➔ LDAP (e.g. SquirrelRDF) • SPARQL ➔ RDF (triplestore e.g. OWLIM-se) • SPARQL ➔ HADOOP/HIVE (e.g. SHARD) – How you query independent of how you store! © 2012 SIBTuesday, December 4, 2012
  • Apparently it helps kill vampires !!! © 2012 SIBTuesday, December 4, 2012
  • Lets learn SPARQL • Queries over RDF data. – Four basic types • SELECT – Returns “tab delimited” results • CONSTRUCT – Makes new triples • DESCRIBE – Returns all triples mentioning a resource • ASK – Return true if anything matches © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern taxon:9606 rdf:type core:Taxon . © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern ?anyTaxon rdf:type core:Taxon . © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern SELECT ?anyTaxon WHERE { ?anyTaxon rdf:type core:Taxon . } © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern taxon:9606 rdf:type core:Taxon . taxon:9606 core:reviewed “true” . © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern ?anyTaxon rdf:type core:Taxon . ?anyTaxon core:reviewed “true” . © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern SELECT ?anyTaxon WHERE { ?anyTaxon rdf:type core:Taxon . ?anyTaxon core:reviewed “true” . } © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern SELECT ?anyTaxon WHERE { ?anyTaxon rdf:type core:Taxon . ?anyTaxin core:reviewed “true” . } © 2012 SIBTuesday, December 4, 2012
  • SPARQL:queries triple pattern SELECT ?anyTaxon WHERE { ?anyTaxon rdf:type core:Taxon . $anyTaxon core:reviewed “true” . } © 2012 SIBTuesday, December 4, 2012
  • Lets learn SPARQL © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • Shorthand a = rdf:type © 2012 SIBTuesday, December 4, 2012
  • AND join (default) © 2012 SIBTuesday, December 4, 2012
  • Now you type © 2012 SIBTuesday, December 4, 2012
  • Remember ‘;’ shortcut © 2012 SIBTuesday, December 4, 2012
  • Two variables one output column © 2012 SIBTuesday, December 4, 2012
  • Optional • When values may be missing – yet interesting when they are there • Use as sub query • bound values from outside stay bound inside – ?x ?y?z . OPTIONAL {?x ?b ?c} • ?x same variable = same thing © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • UNION • Allows you to combine query patterns as an OR operation. • Joins are still from outer to inner. © 2012 SIBTuesday, December 4, 2012
  • UNION © 2012 SIBTuesday, December 4, 2012
  • Negation • When you do not want a certain category of matches. SELECT ?pet WHERE { ?pet a pets:Friendly . } © 2012 SIBTuesday, December 4, 2012
  • Oooops © 2012 SIBTuesday, December 4, 2012
  • Not exists (Negation 1) © 2012 SIBTuesday, December 4, 2012
  • Minus (Negation 2) © 2012 SIBTuesday, December 4, 2012
  • MINUS{} or FILTER (NOT EXISTS{}) • Whats the difference? – MINUS subtracts results – NOT EXITS tests if the sub pattern is possible at all. • Normally the faster option. © 2012 SIBTuesday, December 4, 2012
  • MINUS all data © 2012 SIBTuesday, December 4, 2012
  • FILTER (NOT EXISTS{}) no results © 2012 SIBTuesday, December 4, 2012
  • Negation option 3 SPARQL 1.0 SELECT ?subject ?rank WHERE { ?subject core:rank ?rank . OPTIONAL { ?subject core:rank core:Genus . ?subject core:rank ?genus .} FILTER(! BOUND(?genus)) } © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • FILTERS • You just saw it twice – Once in the !BOUND – Once in the NOT EXISTS • FILTERS a result set by possibly removing values – FILTER do not add a value to the result • Inside the same graph pattern order independent. © 2012 SIBTuesday, December 4, 2012
  • Filter © 2012 SIBTuesday, December 4, 2012
  • Filter on not in © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • IN © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • FILTER on numbers • < – FILTER (1 < 2) • > – FILTER (2 > 1) • = – FILTER (1 =1) • != – FILTER(1 != 2) • © 2012 SIBTuesday, December 4, 2012
  • Filters • ?x = ?y does casting (value conversions) – 1.0^^xsd:float = 1^^xsd:int is true • sameTerm(?x, ?y) does not – sameTerm(1.0^^xsd:float, 1^^xsd:int) © 2012 SIBTuesday, December 4, 2012
  • FILTER on strings • Functions – STRLEN – ENCODE_FOR_URI – SUBSTR – CONCAT – UCASE – langMatches – LCASE – REGEX – STRSTARTS – REPLACE – STRENDS – CONTAINS – IRI – STRBEFORE – STRAFTER © 2012 SIBTuesday, December 4, 2012
  • STRLEN == String Length © 2012 SIBTuesday, December 4, 2012
  • CONTAINS is case sensitive is it in there © 2012 SIBTuesday, December 4, 2012
  • REGEX, just like java regex © 2012 SIBTuesday, December 4, 2012
  • BIND • Builds new Values – Closes the basic graph pattern SELECT ?p WHERE { { ?taxon a :Taxon . } BIND (?taxon AS ?p) } • Always declare before use. © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • BIND can assign any output © 2012 SIBTuesday, December 4, 2012
  • Aggregate functions • on select line • limited in number – count – sum – avg – min – max – groupConcat – sample © 2012 SIBTuesday, December 4, 2012
  • count © 2012 SIBTuesday, December 4, 2012
  • SAMPLE should give a random result back © 2012 SIBTuesday, December 4, 2012
  • Follow the path © 2012 SIBTuesday, December 4, 2012
  • Path queries © 2012 SIBTuesday, December 4, 2012
  • Finding a grand parent using normal joins © 2012 SIBTuesday, December 4, 2012
  • Finding a grandParent using a path query © 2012 SIBTuesday, December 4, 2012
  • | is OR for predicate © 2012 SIBTuesday, December 4, 2012
  • Same result with UNION © 2012 SIBTuesday, December 4, 2012
  • Finding any ancestor © 2012 SIBTuesday, December 4, 2012
  • Can use the variable in a normal join afterwards © 2012 SIBTuesday, December 4, 2012
  • GROUP BY © 2012 SIBTuesday, December 4, 2012
  • GROUP BY • Needed for aggregate values • After closing the where clause – ... WHERE {?x ?y ?z} GROUP BY ?x © 2012 SIBTuesday, December 4, 2012
  • GROUP BY © 2012 SIBTuesday, December 4, 2012
  • HAVING I have carrot ! © 2012 SIBTuesday, December 4, 2012
  • HAVING • FILTER for aggregates • After the GROUP BY clause – ... GROUP BY ?x HAVING (count(?y) > 2) – ... GROUP BY ?x HAVING (min(?y) = 2) – etc... © 2012 SIBTuesday, December 4, 2012
  • HAVING © 2012 SIBTuesday, December 4, 2012
  • LIMITS & OFFSET © 2012 SIBTuesday, December 4, 2012
  • LIMIT and OFFSET • OFFSET is skip first results • LIMIT return no more than x results © 2012 SIBTuesday, December 4, 2012
  • ORDER © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • VALUES • Super BIND • Provide inline data © 2012 SIBTuesday, December 4, 2012
  • © 2012 SIBTuesday, December 4, 2012
  • Examples • Parameter lists are between () VALUES (?annotation) { (core:Disease_Annotation) Text (core:Disulfide_Bond_Annotation) } © 2012 SIBTuesday, December 4, 2012
  • Examples • Undef means no value at – all not bound VALUES (?annotation ?begin) { (core:Disease_Annotation UNDEF) Text (core:Disulfide_Bond_Annotation 2) } © 2012 SIBTuesday, December 4, 2012
  • VALUES • After declaring a set of values you can use them in your query. SELECT ?comment WHERE { VALUES (?annotation ?begin) { (core:Disease_Annotation UNDEF) (core:Disulfide_Bond_Annotation 2) } ?annotation rdfs:comment ?comment . } © 2012 SIBTuesday, December 4, 2012
  • SERVICE: Using other sparql endpoints • SERVICE<URL of other endpoint> – Runs a sub query on the other endpoint and merges it back into your query. © 2012 SIBTuesday, December 4, 2012
  • “Life is better with friends who understand you.” © 2012 SIBTuesday, December 4, 2012
  • SERVICE © 2012 SIBTuesday, December 4, 2012
  • SERVICE • Useful – Quick experimenting with combing multiple datasources – Quick for queries where not to much data is send to the remote point • Slow – When you ask for to much data – Remote endpoint not resourced for your questions © 2012 SIBTuesday, December 4, 2012
  • Lets make some triples © 2012 SIBTuesday, December 4, 2012
  • Construction • CONSTRUCT – New triples • downloads RDF – Does not update store © 2012 SIBTuesday, December 4, 2012
  • New triples © 2012 SIBTuesday, December 4, 2012
  • Constructing an owl:sameAs between two URI © 2012 SIBTuesday, December 4, 2012
  • INSERT • Adds data – like construct © 2012 SIBTuesday, December 4, 2012
  • Modifies data © 2012 SIBTuesday, December 4, 2012
  • DELETE • Removes data – Triples matching are removed from the data – Triples can be bound using where clause © 2012 SIBTuesday, December 4, 2012
  • DELETE © 2012 SIBTuesday, December 4, 2012
  • DELETE INSERT • Single atomic operation. © 2012 SIBTuesday, December 4, 2012
  • Atomic operation © 2012 SIBTuesday, December 4, 2012
  • I’m exhausted now © 2012 SIBTuesday, December 4, 2012
  • QuestionsTuesday, December 4, 2012