Dan Scott <https://dscott.ca/#i>
Associate Librarian, Laurentian University
Subject | Predicate | Object |
---|---|---|
Dan Scott | member of | Laurentian University |
Laurentian University | location | Sudbury |
Laurentian University | founding date | 1960 |
Use HTTP URIs (web addresses) to identify things:
Subject | Predicate | Object-or-value |
---|---|---|
https://dscott.ca/#i | member of | Laurentian University |
Laurentian University | location | Sudbury |
Laurentian University | founding date | 1960 |
Subject | Predicate | Object-or-value |
---|---|---|
https://dscott.ca/#i | member of | https://laurentian.ca/ |
https://laurentian.ca/ | location | Sudbury |
https://laurentian.ca/ | founding date | 1960 |
Subject | Predicate | Object-or-value |
---|---|---|
https://dscott.ca/#i | member of | https://laurentian.ca/ |
https://laurentian.ca/ | location | https://greatersudbury.ca/ |
https://laurentian.ca/ | founding date | 1960 |
Subject | Predicate | Object-or-value |
---|---|---|
https://dscott.ca/#i | http://schema.org/memberOf | https://laurentian.ca/ |
https://laurentian.ca/ | http://schema.org/location | https://greatersudbury.ca/ |
https://laurentian.ca/ | http://schema.org/foundingDate | 1960 |
Subject | Predicate | Object-or-value |
---|---|---|
https://dscott.ca/#i | http://schema.org/memberOf | https://laurentian.ca/ |
https://laurentian.ca/ | http://schema.org/location | https://greatersudbury.ca/ |
https://laurentian.ca/ | http://schema.org/foundingDate | "1960"^^xsd:gYear |
https://greatersudbury.ca/ | http://schema.org/name | "Greater Sudbury"@en |
https://greatersudbury.ca/ | http://schema.org/name | "Grand Sudbury"@fr |
These three-part statements are called triples.
owl:equivalentClass
, owl:equivalentProperty
) and things (owl:sameAs
)
rdfs:label
or dc:creator
rdfs:
is just a shorter way of saying http://www.w3.org/2000/01/rdf-schema#
rdfs:name
really means http://www.w3.org/2000/01/rdf-schema#label
dc:creator
expands to http://purl.org/dc/terms/creator
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 "Laurentian University"
:
SELECT * WHERE {
?s ?p "Laurentian University"
}
LIMIT 10
?p
to wdt:P31
(instance of)."Laurentian University"
to wd:Q3918
(university).
SELECT * WHERE {
?s wdt:P31 wd:Q3918 # instance of university
}
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
SELECT * WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
}
}
LIMIT 100
?s
) in successive statements, use a semi-colon ;
instead of the period (.
):
SELECT * WHERE {
?s wdt:P31 wd:Q3918;
wdt:P17 ?country .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
}
}
LIMIT 100
AND
expressions. But the UNION
operator allows you to create OR expressions. For example, to list universities in Ontario or Québec:
SELECT ?s ?sLabel WHERE {
{ ?s wdt:P31 wd:Q108403040 } # university in Ontario
UNION
{ ?s wdt:P31 wd:Q3551519 } . # university in Quebec
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
}
}
LIMIT 100
ORDER BY ?countryLabel
clause just before the LIMIT
clause:
SELECT ?s ?sLabel ?country ?countryLabel WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
}
}
ORDER BY ?countryLabel
LIMIT 100
P625
(coordinates) and store it in a ?coords
variable:
SELECT ?s ?sLabel ?country ?countryLabel ?coords WHERE {
?s wdt:P31 wd:Q3918 .
?s wdt:P17 ?country .
?s wdt:P625 ?coords . # give us coordinates
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en".
}
}
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
GROUP_CONCAT(?instrument, "; ")
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
SELECT
returns tabular data. CONSTRUCT
returns RDF graphs:
CONSTRUCT {
?s wdt:P625 ?coords .
?s wdt:P17 ?country .
} WHERE {
?s wdt:P31 wd:Q3918;
wdt:P17 ?country;
P625 ?coords . # give us coordinates
}