Dan Scott <https://dscott.ca/#i>
PhD student, McGill University
Associate Librarian, Laurentian University
| Type or class | Instance |
|---|---|
| Professor | Dr. Guastavino |
| Student | You* |
| Teaching assistant | Richard Yanaky |
| Guest lecturer | Dan Scott |
| Subject | Predicate | Object |
|---|---|---|
| Dan Scott | member of | McGill University |
| McGill University | location | Montreal |
| McGill University | founding date | 1821 |
Use HTTP URIs (web addresses) to identify things:
| Subject | Predicate | Object |
|---|---|---|
| https://dscott.ca/#i | http://schema.org/memberOf | https://mcgill.ca/ |
| https://mcgill.ca/ | http://schema.org/location | https://ville.montreal.qc.ca/ |
| https://mcgill.ca/ | http://schema.org/foundingDate | "1821"^^xsd:gYear |
These three-part statements are called triples.
owl:equivalentClass, owl:equivalentProperty) and things (owl:sameAs)
SELECT variables rather than columnsFROM clause: just the entire dataset of triples!WHERE clause creates a pattern for the triples you wantJOINs: relationships between entitiesFILTER attribute values to narrow furtherSELECT * WHERE {
?s ?p ?o
}
LIMIT 10CTRL + ENTER, or click the arrow button on the left, to submit the query.?o to "McGill University":
SELECT * WHERE {
?s ?p "McGill University"
}
LIMIT 10wdt:P31 (instance of).wd:Q3918 (university).
SELECT * WHERE {
?s wdt:P31 wd:Q3918
}wdt: = "truthiness"wd: = entity.) to your first statement.wdt:P17) for the subject and store the value in a new variable, ?country.
SELECT * WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country
}rdfs:label of the subject.rdfs:label of the country.LIMIT 100 clause to keep things fast.SELECT * WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
?s rdfs:label ?sLabel .
?country rdfs:label ?countryLabel .
}
LIMIT 100
Don't forget the "AND" operator (period .) for your statements!
FILTER(LANG(?countryLabel) = "en"))
SELECT * WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
?s rdfs:label ?sLabel .
?country rdfs:label ?countryLabel .
FILTER(LANG(?sLabel) = "en") .
FILTER(LANG(?countryLabel) = "en") .
}
LIMIT 100ORDER BY ?countryLabel clause just before the LIMIT clause:
SELECT * WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
?s rdfs:label ?sLabel .
?country rdfs:label ?countryLabel .
FILTER(LANG(?sLabel) = "en") .
FILTER(LANG(?countryLabel) = "en") .
}
ORDER BY ?countryLabel
LIMIT 100SELECT clause to select ?countryLabel (COUNT (?s) AS ?cnt).GROUP BY DESC(?cnt) clause just before the ORDER BY clause:
SELECT ?countryLabel (COUNT (?s) AS ?cnt) WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
?country rdfs:label ?countryLabel .
FILTER(LANG(?countryLabel) = "en") .
}
GROUP BY ?countryLabel
ORDER BY DESC(?cnt)
LIMIT 100HAVING(COUNT(?s) <= 50) clause just before the ORDER BY clause:
SELECT ?countryLabel (COUNT (?s) AS ?cnt) WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
?country rdfs:label ?countryLabel .
FILTER(LANG(?countryLabel) = "en") .
}
GROUP BY ?countryLabel
HAVING(COUNT(?s) <= 50)
ORDER BY DESC(?cnt)
LIMIT 100