Dan Scott <https://dscott.ca/#i>
PhD student, McGill University
Associate Librarian, Laurentian University
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-or-value |
---|---|---|
https://dscott.ca/#i | member of | McGill University |
McGill University | location | Montreal |
McGill University | founding date | 1821 |
Subject | Predicate | Object-or-value |
---|---|---|
https://dscott.ca/#i | member of | https://mcgill.ca/ |
https://mcgill.ca/ | location | Montreal |
https://mcgill.ca/ | founding date | 1821 |
Subject | Predicate | Object-or-value |
---|---|---|
https://dscott.ca/#i | member of | https://mcgill.ca/ |
https://mcgill.ca/ | location | https://ville.montreal.qc.ca/ |
https://mcgill.ca/ | founding date | 1821 |
Subject | Predicate | Object-or-value |
---|---|---|
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 |
Subject | Predicate | Object-or-value |
---|---|---|
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 |
https://ville.montreal.qc.ca/ | http://schema.org/name | "Montreal"@en |
https://ville.montreal.qc.ca/ | http://schema.org/name | "Montréal"@fr |
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 wantJOIN
s: relationships between entitiesFILTER
attribute values to narrow furtherSELECT * WHERE {
?s ?p ?o
}
LIMIT 10
CTRL + ENTER
, or click the arrow button on the left, to submit the query.?o
to "McGill University"
:
SELECT * WHERE {
?s ?p "McGill University"
}
LIMIT 10
wdt: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 100
ORDER 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 100
P625
(coordinates) and store it in a ?coords
variable:
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") .
?s wdt:P625 ?coords .
}
ORDER BY ?countryLabel
LIMIT 100
Let's focus on Canadian universities
# show instances & subclasses of Canadian universities on a map
#defaultView:Map
SELECT * WHERE {
?s wdt:P31/wdt:P279* wd:Q3918 . # instances of and subclasses of university
?s wdt:P31 ?instanceOf . # instance of what?
?s wdt:P17 wd:Q16 . # in Canada
?s rdfs:label ?sLabel .
?instanceOf rdfs:label ?instanceLabel .
FILTER(LANG(?sLabel) = "en") . # give us the English label
FILTER(LANG(?instanceLabel) = "en") . # give us the English label
OPTIONAL{?s wdt:P625 ?coords} . # and coordinates, if possible
}
ORDER BY ?sLabel
SELECT
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 100
HAVING(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
Help users learn while searching by tapping into Wikidata: