CHAT-GPT4 Variant
SPARQL Cheatsheet
Q: Create a rendition of the following table using these guidelines, for the first 6 rows:
- Create a DBpedia SPARQL URL from the Example column values within quotations
- Use the URL to hyperlink values in the “Command” Column
Q: Repeat for the next 6 rows.
Q: Repeat for the last row.
A:
Command | Description | Example |
---|---|---|
SELECT | Retrieves data from one or more RDF graphs | SELECT ?person ?birthdate WHERE { ?person dbo:birthDate ?birthdate } LIMIT 10 |
DISTINCT | Retrieves unique values | SELECT DISTINCT ?category WHERE { ?product dcterms:subject ?category } |
WHERE | Filters RDF triples based on a condition | SELECT ?film WHERE { ?film rdf:type dbo:Film . ?film dbo:starring dbr:Harrison_Ford . } |
FILTER | Filters query results based on a condition | SELECT ?film WHERE { ?film rdf:type dbo:Film . ?film dbo:budget ?budget . FILTER(?budget > 100000000) } |
UNION | Combines the results of two or more queries | SELECT ?name WHERE { { ?person foaf:name ?name } UNION { ?organization foaf:name ?name } } |
OPTIONAL | Retrieves optional RDF triples | SELECT ?book ?author WHERE { ?book rdf:type dbo:Book . OPTIONAL { ?book dbo:author ?author } } |
ORDER BY | Sorts the query results | SELECT ?person ?birthdate WHERE { ?person dbo:birthDate ?birthdate } ORDER BY DESC(?birthdate) LIMIT 10 |
LIMIT | Limits the number of results returned | SELECT ?person WHERE { ?person rdf:type dbo:Person } LIMIT 10 |
GROUP BY | Groups query results based on a variable | SELECT ?category (COUNT(?product) AS ?count) WHERE { ?product dcterms:subject ?category } GROUP BY ?category |
HAVING | Filters groups based on a condition | SELECT ?category (COUNT(?product) AS ?count) WHERE { ?product dcterms:subject ?category } GROUP BY ?category HAVING (COUNT(?product) > 100) |
DESCRIBE | Retrieves RDF triples that describe a resource | DESCRIBE <http://dbpedia.org/resource/Barack_Obama> |
CONSTRUCT | Generates an RDF graph based on a query pattern | CONSTRUCT { ?book dbo:author ?author } WHERE { ?book rdf:type dbo:Book . ?book dbo:author ?author } |
SAMPLE | Selects a random value for a variable within a group | SELECT ?country (SAMPLE(?capital) AS ?sample) WHERE { ?country dbo:capital ?capital } GROUP BY ?country |