-
Notifications
You must be signed in to change notification settings - Fork 1
Examples
This document provides practical examples of SPARQL queries in SPARQLWorksβ’, demonstrating different patterns and visualization techniques.
Endpoint: https://dbpedia.org/sparql
Basic Mode:
?movie dbo:creator ?creator;
rdfs:label ?movieName.
FILTER(?creator = dbr:Spike_Lee)
Advanced Mode:
CONSTRUCT {
?movie dbo:creator ?creator;
rdfs:label ?movieName.
}
WHERE {
?movie dbo:creator ?creator;
rdfs:label ?movieName.
FILTER(?creator = dbr:Spike_Lee)
}
LIMIT 50Visualization: Shows Spike Lee's movies connected to their creators with title labels.
Basic Mode:
?movie dbo:director ?director;
dbo:genre ?genre;
rdfs:label ?title.
FILTER(?genre = dbr:Drama_film)
Advanced Mode:
CONSTRUCT {
?movie dbo:director ?director;
dbo:genre ?genre;
rdfs:label ?title.
}
WHERE {
?movie a dbo:Film;
dbo:director ?director;
dbo:genre ?genre;
rdfs:label ?title.
FILTER(?genre = dbr:Drama_film)
}
LIMIT 100Visualization: Drama films connected to directors and genre classifications.
Endpoint: https://dbpedia.org/sparql
Basic Mode:
?person foaf:name ?name;
foaf:knows ?friend.
?friend foaf:name ?friendName.
Advanced Mode:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT {
?person foaf:name ?name;
foaf:knows ?friend.
?friend foaf:name ?friendName.
}
WHERE {
?person foaf:name ?name;
foaf:knows ?friend.
?friend foaf:name ?friendName.
}
LIMIT 200Visualization: Social network graph showing people and their friendships.
Basic Mode:
?person foaf:name ?name;
org:memberOf ?org.
?org rdfs:label ?orgName.
Advanced Mode:
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX org: <http://www.w3.org/ns/org#>
CONSTRUCT {
?person foaf:name ?name;
org:memberOf ?org.
?org rdfs:label ?orgName.
}
WHERE {
?person foaf:name ?name;
org:memberOf ?org.
?org rdfs:label ?orgName.
}
LIMIT 150Visualization: Organizational structure with members connected to organizations.
Endpoint: https://query.wikidata.org/sparql
Basic Mode:
?city wdt:P31 wd:Q515;
wdt:P17 ?country;
rdfs:label ?cityName.
?country rdfs:label ?countryName.
FILTER(LANG(?cityName) = "en")
FILTER(LANG(?countryName) = "en")
Advanced Mode:
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#>
CONSTRUCT {
?city rdfs:label ?cityName;
wdt:P17 ?country.
?country rdfs:label ?countryName.
}
WHERE {
?city wdt:P31 wd:Q515;
wdt:P17 ?country;
rdfs:label ?cityName.
?country rdfs:label ?countryName.
FILTER(LANG(?cityName) = "en")
FILTER(LANG(?countryName) = "en")
}
LIMIT 100Visualization: Cities connected to their countries with English labels.
Basic Mode:
?location wdt:P131 ?parent;
rdfs:label ?name.
?parent rdfs:label ?parentName.
FILTER(?location = wd:Q84)
Advanced Mode:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
CONSTRUCT {
?location wdt:P131 ?parent;
rdfs:label ?name.
?parent rdfs:label ?parentName.
}
WHERE {
?location wdt:P131* ?parent;
rdfs:label ?name.
?parent rdfs:label ?parentName.
FILTER(?location = wd:Q84)
}
LIMIT 50Visualization: Hierarchical location relationships using property paths.
Endpoint: https://dbpedia.org/sparql
Basic Mode:
?paper dct:creator ?author;
dct:title ?title;
dct:subject ?subject.
?author foaf:name ?authorName.
Advanced Mode:
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT {
?paper dct:creator ?author;
dct:title ?title;
dct:subject ?subject.
?author foaf:name ?authorName.
}
WHERE {
?paper dct:creator ?author;
dct:title ?title;
dct:subject ?subject.
?author foaf:name ?authorName.
}
LIMIT 75Visualization: Academic papers connected to authors and research subjects.
Basic Mode:
?dept a dbo:University;
dbo:city ?city;
rdfs:label ?deptName.
?city rdfs:label ?cityName.
Advanced Mode:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
CONSTRUCT {
?dept a dbo:University;
dbo:city ?city;
rdfs:label ?deptName.
?city rdfs:label ?cityName.
}
WHERE {
?dept a dbo:University;
dbo:city ?city;
rdfs:label ?deptName.
?city rdfs:label ?cityName.
}
LIMIT 60Visualization: Universities connected to their cities.
Endpoint: https://dbpedia.org/sparql
Basic Mode:
?artist a dbo:MusicalArtist;
dbo:genre ?genre;
rdfs:label ?artistName.
?album dbo:artist ?artist;
rdfs:label ?albumName.
Advanced Mode:
PREFIX dbo: <http://dbpedia.org/ontology/>
CONSTRUCT {
?artist a dbo:MusicalArtist;
dbo:genre ?genre;
rdfs:label ?artistName.
?album dbo:artist ?artist;
rdfs:label ?albumName.
}
WHERE {
?artist a dbo:MusicalArtist;
dbo:genre ?genre;
rdfs:label ?artistName.
?album dbo:artist ?artist;
rdfs:label ?albumName.
}
LIMIT 80Visualization: Music artists connected to their albums and genres.
Basic Mode:
?venue a dbo:Venue;
dbo:location ?city;
rdfs:label ?venueName.
?city rdfs:label ?cityName.
Advanced Mode:
PREFIX dbo: <http://dbpedia.org/ontology/>
CONSTRUCT {
?venue a dbo:Venue;
dbo:location ?city;
rdfs:label ?venueName.
?city rdfs:label ?cityName.
}
WHERE {
?venue a dbo:Venue;
dbo:location ?city;
rdfs:label ?venueName.
?city rdfs:label ?cityName.
}
LIMIT 40Visualization: Music venues connected to their locations.
Endpoint: https://query.wikidata.org/sparql
Basic Mode:
?politician wdt:P102 ?party;
rdfs:label ?name.
?party rdfs:label ?partyName.
FILTER(LANG(?name) = "en")
FILTER(LANG(?partyName) = "en")
Advanced Mode:
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
CONSTRUCT {
?politician wdt:P102 ?party;
rdfs:label ?name.
?party rdfs:label ?partyName.
}
WHERE {
?politician wdt:P102 ?party;
rdfs:label ?name.
?party rdfs:label ?partyName.
FILTER(LANG(?name) = "en")
FILTER(LANG(?partyName) = "en")
}
LIMIT 120Visualization: Politicians connected to their political parties.
Basic Mode:
?org wdt:P31 wd:Q327333;
wdt:P17 ?country;
rdfs:label ?orgName.
?country rdfs:label ?countryName.
FILTER(LANG(?orgName) = "en")
Advanced Mode:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
CONSTRUCT {
?org wdt:P31 wd:Q327333;
wdt:P17 ?country;
rdfs:label ?orgName.
?country rdfs:label ?countryName.
}
WHERE {
?org wdt:P31 wd:Q327333;
wdt:P17 ?country;
rdfs:label ?orgName.
?country rdfs:label ?countryName.
FILTER(LANG(?orgName) = "en")
}
LIMIT 90Visualization: Government organizations connected to countries.
Endpoint: https://dbpedia.org/sparql
Basic Mode:
?compound a dbo:ChemicalCompound;
dbo:molecularWeight ?weight;
rdfs:label ?name.
FILTER(?weight > 100)
Advanced Mode:
PREFIX dbo: <http://dbpedia.org/ontology/>
CONSTRUCT {
?compound a dbo:ChemicalCompound;
dbo:molecularWeight ?weight;
rdfs:label ?name.
}
WHERE {
?compound a dbo:ChemicalCompound;
dbo:molecularWeight ?weight;
rdfs:label ?name.
FILTER(?weight > 100)
}
LIMIT 70Visualization: Chemical compounds with molecular weights.
Basic Mode:
?dataset dct:creator ?researcher;
dct:subject ?topic;
rdfs:label ?title.
?researcher foaf:name ?researcherName.
Advanced Mode:
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
CONSTRUCT {
?dataset dct:creator ?researcher;
dct:subject ?topic;
rdfs:label ?title.
?researcher foaf:name ?researcherName.
}
WHERE {
?dataset dct:creator ?researcher;
dct:subject ?topic;
rdfs:label ?title.
?researcher foaf:name ?researcherName.
}
LIMIT 55Visualization: Research datasets connected to creators and topics.
Endpoint: https://dbpedia.org/sparql
Basic Mode:
?artwork dbo:museum ?museum;
dbo:artist ?artist;
rdfs:label ?title.
?museum rdfs:label ?museumName.
Advanced Mode:
PREFIX dbo: <http://dbpedia.org/ontology/>
CONSTRUCT {
?artwork dbo:museum ?museum;
dbo:artist ?artist;
rdfs:label ?title.
?museum rdfs:label ?museumName.
}
WHERE {
?artwork dbo:museum ?museum;
dbo:artist ?artist;
rdfs:label ?title.
?museum rdfs:label ?museumName.
}
LIMIT 65Visualization: Artworks connected to museums and artists.
Basic Mode:
?book dbo:author ?author;
dbo:genre ?genre;
rdfs:label ?title.
?author rdfs:label ?authorName.
Advanced Mode:
PREFIX dbo: <http://dbpedia.org/ontology/>
CONSTRUCT {
?book dbo:author ?author;
dbo:genre ?genre;
rdfs:label ?title.
?author rdfs:label ?authorName.
}
WHERE {
?book dbo:author ?author;
dbo:genre ?genre;
rdfs:label ?title.
?author rdfs:label ?authorName.
}
LIMIT 85Visualization: Books connected to authors and literary genres.
Endpoint: https://query.wikidata.org/sparql
Basic Mode:
?condition wdt:P31 wd:Q12136;
wdt:P1995 ?specialty;
rdfs:label ?name.
?specialty rdfs:label ?specialtyName.
FILTER(LANG(?name) = "en")
Advanced Mode:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
CONSTRUCT {
?condition wdt:P31 wd:Q12136;
wdt:P1995 ?specialty;
rdfs:label ?name.
?specialty rdfs:label ?specialtyName.
}
WHERE {
?condition wdt:P31 wd:Q12136;
wdt:P1995 ?specialty;
rdfs:label ?name.
?specialty rdfs:label ?specialtyName.
FILTER(LANG(?name) = "en")
}
LIMIT 95Visualization: Medical conditions connected to medical specialties.
Basic Mode:
?hospital wdt:P31 wd:Q16917;
wdt:P131 ?city;
rdfs:label ?name.
?city rdfs:label ?cityName.
FILTER(LANG(?name) = "en")
Advanced Mode:
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
CONSTRUCT {
?hospital wdt:P31 wd:Q16917;
wdt:P131 ?city;
rdfs:label ?name.
?city rdfs:label ?cityName.
}
WHERE {
?hospital wdt:P31 wd:Q16917;
wdt:P131 ?city;
rdfs:label ?name.
?city rdfs:label ?cityName.
FILTER(LANG(?name) = "en")
}
LIMIT 110Visualization: Hospitals connected to their cities.
- Start Simple: Begin with basic patterns and add complexity
- Use LIMIT: Always include reasonable limits for performance
- Add Filters: Use FILTER clauses to focus results
- Include Labels: Ensure entities have readable labels
- Test Endpoints: Verify queries work on target endpoints
- Node Types: Mix IRI and literal nodes for rich graphs
- Relationship Depth: Balance breadth and depth
- Label Quality: Prefer datasets with good multilingual labels
- Performance: Consider graph size and rendering complexity
- Entity-Attribute: Basic subject-predicate-object triples
- Entity-Relationship: Connections between entities
- Hierarchies: Parent-child or type-subtype relationships
- Networks: Complex interconnected structures