0% found this document useful (0 votes)
89 views10 pages

SPARQL Cheat Sheet

This document provides a summary of a workshop on SPARQL and Linked Open Data. It includes 4 cases with example SPARQL queries to explore patent and biomedical data from the EPO, KIPO, UniProt and Wikidata. It also includes 2 appendix examples for finding airports near Oslo and retrieving mathematician data from Wikidata. Participants are guided through exercises to modify example queries and learn key SPARQL syntax and techniques.

Uploaded by

Amine Bouyanzer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views10 pages

SPARQL Cheat Sheet

This document provides a summary of a workshop on SPARQL and Linked Open Data. It includes 4 cases with example SPARQL queries to explore patent and biomedical data from the EPO, KIPO, UniProt and Wikidata. It also includes 2 appendix examples for finding airports near Oslo and retrieving mathematician data from Wikidata. Participants are guided through exercises to modify example queries and learn key SPARQL syntax and techniques.

Uploaded by

Amine Bouyanzer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

SPARQL

CHEAT SHEET
2
This Cheat Sheet was designed for the Exploring Opportunities of Linked Open Innovation Data workshop at NIPO. It allows the participants
to go through the exercises faster. The workshop is part of the IPLODB project. The IP LODB team gratefully acknowledges this work has
been co-sponsored by the Academic Research Programme of the European Patent Office. The research results and views contained inside
these materials or during the workshop are those of the researchers only. They do not necessarily represent the views of the EPO. We also
thank the NIPO and Nord University for their support for preparing and organizing this workshop event.
3

CASE 1: simplest SPARQL queries (PPT slide 13)


In this first case we see two simplest SPARQL queries. The first one will first list 10 triples of the data and the second will first list 10 patent titles.
If you want to try them for yourself, you can go to EPO SPARQL ENDPOINT at https://data.epo.org/linked-data/sparql.html.

SELECT ?subject ?predicate ?object


WHERE {
?subject ?predicate ?object.
} LIMIT 10

SELECT ?title
WHERE {
?pub <http://data.epo.org/linked-data/def/patent/titleOfInvention> ?title.
} LIMIT 100
4

EXERCISE 1: EP LOD SPARQL (PPT slide 14)


For this exercise you need to go to EP LOD SPARQL ENDPOINT at: https://data.epo.org/linked-data/sparql.html.
The code below will connect patent publication number, date, and title of invention together.
Please pay attention to the presenter as he will explain to you what parts of the code do and the exercise.

SELECT ?pubnr ?pubdate ?title


WHERE {
?pub <http://data.epo.org/linked-data/def/patent/publicationNumber> ?pubnr.
?pub <http://data.epo.org/linked-data/def/patent/publicationDate> ?pubdate.
?pub <http://data.epo.org/linked-data/def/patent/titleOfInvention> ?title.
FILTER(lang(?title) = 'en')
} LIMIT 10

Exercise: Add publication kind to the query.


5

EXERCISE 2: EP LOD SPARQL (PPT slide 15)


For this exercise you need to remain at the EP LOD SPARQL ENDPOINT.
The code below will add publication label through a connected graph node and some other properties to the previous example as well as use some syntactic
sugars for making the whole query more readable.
Please proceed by completing the exercise as designed below.

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>


PREFIX pat:<http://data.epo.org/linked-data/def/patent/>
SELECT ?pubnr ?label ?pubdate ?applnrepodoc ?title
WHERE {
?pub pat:publicationNumber ?pubnr;
pat:publicationDate ?pubdate;
pat:application ?appl;
pat:titleOfInvention ?title;
pat:publicationKind ?kind.
?appl pat:applicationNumberEpodoc ?applnrepodoc.
?kind skos:notation ?label.
FILTER(lang(?title) = 'en')
} LIMIT 10

Exercise: Add applicant name to the query.


6

CASE 2: USING FILTERS (PPT slide 17)


This query builds on the previous one by adding filters for applicant name and year of publication.
If you want to try them for yourself, you can use the EPO SPARQL ENDPOINT.

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>


PREFIX pat:<http://data.epo.org/linked-data/def/patent/>
PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>

SELECT ?pubnr ?label ?pubdate ?applnrepodoc ?title ?name


WHERE {
?pub pat:publicationNumber ?pubnr;
pat:publicationDate ?pubdate;
pat:application ?appl;
pat:titleOfInvention ?title;
pat:publicationKind ?kind;
pat:applicantVC ?applicant.
?appl pat:applicationNumberEpodoc ?applnrepodoc.
?kind skos:notation ?label.
?applicant vcard:fn ?name.
FILTER(lang(?title) = 'en')
FILTER(contains(lcase(?name), 'norsk hydro asa'))
FILTER(year(?pubdate) > 2000)
} LIMIT 10
7

CASE 3 :Connecting EPO and UNIPROT data EXAMPLE (PPT slide 19)
This query requires you to go to the UNIPROT SPARQL endpoint at https://sparql.uniprot.org/sparql/.
The query will connect UNIPROT and EP LOD data through patent citations in UNIPROT dataset and patent publication number and publication authority
in EPO dataset.

PREFIX patent:<http://data.epo.org/linked-data/def/patent/>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>
PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
PREFIX up:<http://purl.uniprot.org/core/>
PREFIX vcard: <http://www.w3.org/2006/vcard/ns#>

SELECT ?UPpatentPublication ?EPOpublication ?publicationNo ?EPOapplication ?inventorVCfn ?applicantF ?citationText


WHERE
{
?citation a up:Patent_Citation;
skos:exactMatch ?UPpatentPublication .

# ?UPatentPublication of format
# http://purl.uniprot.org/patents/EP0959131
BIND(SUBSTR(STR(?UPpatentPublication), 35) AS ?publicationNo)
BIND(SUBSTR(STR(?UPpatentPublication), 33, 2) AS ?publicationAuthority)

SERVICE<https://data.epo.org/linked-data/query>{
?EPOpublication patent:publicationNumber ?publicationNo;
patent:publicationAuthority/skos:notation ?publicationAuthority;
patent:application ?EPOapplication;
patent:inventorVC ?inventorVC.
?inventorVC vcard:fn ?inventorVCfn.
?EPOpublication patent:applicantVC ?applicantVC.
8
?applicantVC vcard:fn ?applicantFn.
OPTIONAL {
?EPOpublication patent:citationNPL ?citationNPL.
?citationNPL patent:citationText ?citationText.
}
}
} LIMIT 100

Code based on: https://forums.epo.org/uniprot-to-patent-data-8318?sid=351096b76db7c3545a55f0fd4afb366b

CASE 4 :KIPO (PPT slide 20)


This case would take you to KIPO SPARQL endpoint at http://lod.kipo.kr/data/sparql.
Feel free to check the predesigned queries there, for more please listen to the explanation given. There is no code pre-prepared for this case
9

Appendix 1: Finding airports around Oslo (PPT appendix)


This query is designed just as an introduction. It will select all airports around the 100 km radius around Oslo and uses the WIKIDATA SPARQL endpoint
at https://query.wikidata.org/.
This is neither a case or an exercise, but it is just meant to show you an example of a query. The other cases and exercises take you in a structured manner
through queries and allow you to construct some built-upon queries.

SELECT ?place ?placeLabel ?location


WHERE
{
# find Oslo coordinates
wd:Q585 wdt:P625 ?oslo .
SERVICE wikibase:around {
?place wdt:P625 ?location .
bd:serviceParam wikibase:center ?oslo .
bd:serviceParam wikibase:radius "100" .
} .
# Is an airport
FILTER EXISTS { ?place wdt:P31/wdt:P279* wd:Q1248784 } .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" .
}
}
10

Appendix 2 :WIKIDATA SPARQL (PPT slide 21)


This query requires you to go to the WIKIDATA SPARQL endpoint at https://query.wikidata.org/.
This query will select first 100 people male mathematicians and connect their birth dates, birth places, birth place coordinates and images.

SELECT ?person ?personLabel ?image ?birthDate ?birthPlaceLabel ?coordinates


WHERE {
?person wdt:P106 wd:Q170790 .
?person wdt:P21 wd:Q6581097 .
OPTIONAL{
?person wdt:P18 ?image .
?person wdt:P569 ?birthDate .
?person wdt:P19 ?birthPlace.
?birthPlace wdt:P625 ?coordinates .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
LIMIT 100

You might also like