Skip to content
Snippets Groups Projects
Verified Commit 78e4d139 authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman :boom:
Browse files

Expanded the SPARQL example

parent ec64d572
No related branches found
No related tags found
No related merge requests found
%% Cell type:code id:4d7d4c73-bd83-4017-abc6-ba394e63b8fb tags: %% Cell type:code id:4d7d4c73-bd83-4017-abc6-ba394e63b8fb tags:
``` sparql ``` sparql
%endpoint http://dbpedia.org/sparql %endpoint http://dbpedia.org/sparql
%lang en %lang en
# This is optional, it would increase the log level. # This is optional, it would increase the log level.
# The default logfile (unless changed upon kernel installation) is [TMPDIR]/sparqlkernel.log, # The default logfile (unless changed upon kernel installation) is [TMPDIR]/sparqlkernel.log,
# where [TMPDIR] is the platform default temporal directory # where [TMPDIR] is the platform default temporal directory
%log debug %log debug
``` ```
%% Output %% Output
%% Cell type:code id:94e96b72-bdb6-4e4f-82ff-1bb5c48821e8 tags: %% Cell type:code id:94e96b72-bdb6-4e4f-82ff-1bb5c48821e8 tags:
``` sparql ``` sparql
%format json %format json
%display table %display table
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT ?person ?name SELECT ?person ?name
WHERE { WHERE {
?person a foaf:Person . ?person a foaf:Person .
?person rdfs:label ?name ?person rdfs:label ?name
FILTER regex(?name,"van gogh","i") FILTER regex(?name,"van gogh","i")
FILTER langMatches(lang(?name),"en") FILTER langMatches(lang(?name),"en")
} LIMIT 20 } LIMIT 20
``` ```
%% Output %% Output
%% Cell type:code id:cc024354-fc00-4221-8f73-54d7100d4837 tags: %% Cell type:code id:cc024354-fc00-4221-8f73-54d7100d4837 tags:
``` sparql ``` sparql
%format json %format json
%display table withtypes %display table withtypes
# We might have more than one triple pointing to the same object, so we group by object # We might have more than one triple pointing to the same object, so we group by object
# and take one arbitrary predicate # and take one arbitrary predicate
SELECT (SAMPLE(?pred) AS ?prop) ?value SELECT (SAMPLE(?pred) AS ?prop) ?value
WHERE { WHERE {
# Places and dates # Places and dates
{ {
dbr:Vincent_van_Gogh ?pred ?value . dbr:Vincent_van_Gogh ?pred ?value .
{ ?pred rdfs:range xsd:date } { ?pred rdfs:range xsd:date }
UNION UNION
{ ?pred rdfs:range dbo:Place } { ?pred rdfs:range dbo:Place }
} }
# People van Gogh relates to # People van Gogh relates to
UNION UNION
{ {
dbr:Vincent_van_Gogh ?pred ?value . dbr:Vincent_van_Gogh ?pred ?value .
?value a foaf:Person ?value a foaf:Person
} }
# People related to van Gogh # People related to van Gogh
UNION UNION
{ {
?value ?pred dbr:Vincent_van_Gogh . ?value ?pred dbr:Vincent_van_Gogh .
?value a foaf:Person ?value a foaf:Person
} }
} GROUP BY ?value ORDER BY ?prop } GROUP BY ?value ORDER BY ?prop
``` ```
%% Output %% Output
%% Cell type:code id:9d7e9f40-3337-47b4-97ee-8e16a42731eb tags: %% Cell type:code id:9d7e9f40-3337-47b4-97ee-8e16a42731eb tags:
``` sparql ``` sparql
%format json %format json
%display table %display table
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT (?picture) ?name SELECT DISTINCT (?picture) ?name
WHERE { WHERE {
?picture ?p1 dbr:Vincent_van_Gogh . ?picture ?p1 dbr:Vincent_van_Gogh .
?picture rdfs:label ?name . ?picture rdfs:label ?name .
FILTER regex(?name,"night", "i") FILTER regex(?name,"night", "i")
FILTER langMatches(lang(?name),"en") FILTER langMatches(lang(?name),"en")
} }
``` ```
%% Output %% Output
%% Cell type:code id:cd4a214a-063e-4abb-9c25-d7b5a09c4e05 tags: %% Cell type:code id:cd4a214a-063e-4abb-9c25-d7b5a09c4e05 tags:
``` sparql ``` sparql
%display raw
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
SELECT DISTINCT (?picture) ?name
WHERE {
?picture ?p1 dbr:Vincent_van_Gogh .
?picture rdfs:label ?name .
FILTER regex(?name,"night", "i")
FILTER langMatches(lang(?name),"en")
}
```
%% Output
%% Cell type:code id:2ecf96c1-d573-4ecd-ac37-f6e5766cb042 tags:
``` sparql
%lsmagics
```
%% Output
%% Cell type:code id:73be378c-ff56-4ec9-ae43-349cbf145e59 tags:
``` sparql
# Modify output format
# Don't show more than 80 results (event if more are fetched)
%show 80
# Request whatever format is appropriate for the query type
%format default
# Activate table output
%display table
```
%% Output
%% Cell type:code id:0923ed22-3d6c-4f93-b992-44e2b5e37dd1 tags:
``` sparql
%endpoint http://dbpedia.org/sparql
%display table withtypes
SELECT DISTINCT ?property
WHERE {
?s ?property ?person .
?person rdf:type foaf:Person .
}
LIMIT 10
```
%% Output
%% Cell type:code id:ccc3543c-1d7d-4a0d-bc4c-016afa828b56 tags:
``` sparql
%endpoint http://dbpedia.org/sparql
%display diagram
CONSTRUCT {
?p1 dbp:successor ?p2 .
?p2 dbp:successor ?p3 .
?p3 dbp:successor ?p4 .
}
WHERE {
?p1 rdf:type foaf:Person .
?p1 dbp:successor ?p2 .
?p2 dbp:successor ?p3 .
?p3 dbp:successor ?p4 .
}
LIMIT 50
```
%% Output
%% Cell type:code id:c92f087a-e033-4f49-9a4c-b8836d91e546 tags:
``` sparql
%endpoint http://dbpedia.org/sparql
%display diagram
%lang es
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
DESCRIBE <http://dbpedia.org/resource/Asturias>
LIMIT 10
```
%% Output
%% Cell type:code id:3cafe219-75ba-4270-b45d-2c5235234f27 tags:
``` sparql
%endpoint http://dbpedia.org/sparql
%format default
%display table
%lang all
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX yago: <http://dbpedia.org/class/yago/>
PREFIX prop: <http://dbpedia.org/property/>
SELECT ?country_name ?population
WHERE {
?country a yago:WikicatLandlockedCountries ;
rdfs:label ?country_name ;
prop:populationEstimate ?population .
FILTER (?population > 15000000) .
FILTER (langMatches(lang(?country_name), "EN")) .
} ORDER BY DESC(?population)
```
%% Output
%% Cell type:code id:3ca048bb-b947-470d-a327-59420d155d35 tags:
``` sparql
%endpoint http://dbpedia.org/sparql
%display table withtypes
%lang all
PREFIX dbpedia-owl: <http://dbpedia.org/ontology/>
SELECT ?label {
dbr:Henrik_Ibsen
dbpedia-owl:birthPlace
[ a dbpedia-owl:Country ;
rdfs:label ?label ]
FILTER langMatches(lang(?label),"en")
}
```
%% Output
%% Cell type:code id:3ea9b0c6-60d3-4f97-b3c1-5d7b97aad234 tags:
``` sparql
%endpoint http://query.wikidata.org/sparql
%display table
%show all
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?president ?cause ?dob ?dod WHERE {
?pid wdt:P39 wd:Q11696 .
?pid wdt:P509 ?cid .
?pid wdt:P569 ?dob .
?pid wdt:P570 ?dod .
OPTIONAL {
?pid rdfs:label ?president filter (lang(?president) = "en") .
}
OPTIONAL {
?cid rdfs:label ?cause filter (lang(?cause) = "en") .
}
}
```
%% Output
%% Cell type:code id:3ad26de8-c0ef-4bce-967b-fee37917b2f3 tags:
``` sparql
%endpoint http://query.wikidata.org/sparql
SELECT ?entityS ?entity (year(?date) as ?year)
WHERE
{
?entityS wdt:P569 ?date .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?entityS rdfs:label ?entity
}
FILTER (datatype(?date) = xsd:dateTime && month(?date) = month(now()) && day(?date) = day(now()))
}
ORDER BY ASC(?year)
LIMIT 20
```
%% Output
%% Cell type:code id:4d023c4c-6fb4-452d-945c-1e952194e909 tags:
``` sparql
%endpoint http://query.wikidata.org/sparql
%display table
SELECT ?discoverer ?name (COUNT(?asteroid) AS ?count)
WHERE
{
?asteroid wdt:P31 wd:Q3863 .
?asteroid wdt:P61 ?discoverer .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
?discoverer rdfs:label ?name
}
}
GROUP BY ?discoverer ?name
ORDER BY DESC(?count)
LIMIT 10
```
%% Output
%% Cell type:code id:c6ff39f7-f952-4aa2-936f-ab27178accb5 tags:
``` sparql
%endpoint http://data.linkedmdb.org/sparql
%format json
%display table
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX movie: <http://data.linkedmdb.org/resource/movie/>
SELECT ?movie ?label
WHERE {
?movie rdf:type movie:film .
?movie rdfs:label ?label .
FILTER regex(?label, "ring", "i")
} LIMIT 10
```
%% Output
%% Cell type:code id:6c50671f-2270-43ae-9ff8-89dbca652f49 tags:
``` sparql
``` ```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment