Dan Scott <https://dscott.ca/#i>
PhD student, McGill University
Associate Librarian, Laurentian University
Type or class | Instance |
---|---|
Organizers | Em, David |
Attendees | You* |
Speakers | Kelsey, Dan |
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 |
---|---|---|
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 |
These three-part statements are called triples.
<head>
<link type="text/css" rel="stylesheet"
href="https://www.gstatic.com/knowledge/kgsearch/widget/1.0/widget.min.css">
<style>.kge-search-picker { width: 25em; }</style>
<script type="text/javascript"
src="https://www.gstatic.com/knowledge/kgsearch/widget/1.0/widget.min.js"></script>
</head>
<body>
<form id='myform'>
<label>Search: <input type="text" id="myinput"></label>
</form>
<script>
KGSearchWidget(API_KEY, document.getElementById('myinput'), {});
</script>
</body>
{ "@context": {
"@vocab": "http://schema.org/",
"goog": "http://schema.googleapis.com/",
"EntitySearchResult": "goog:EntitySearchResult",
"detailedDescription": "goog:detailedDescription",
"resultScore": "goog:resultScore",
"kg": "http://g.co/kg"
},
"@type": "ItemList", "itemListElement": [
{
"@type": "EntitySearchResult",
"result": {
"@id": "kg:/m/02zzm_",
"name": "John Kasich",
"@type": [ "Person", "Thing" ],
"description": "Governor of Ohio",
"image": {
"contentUrl": "http://t1.gstatic.com/images?q=tbn:ANd9GcRoou4pZKD6FoNaE71ngNlv4RGgUS46mgtin5YJtyEoh42CIs4x",
"url": "https://en.wikipedia.org/wiki/John_Kasich"
},
"detailedDescription": {
"articleBody": "John Richard Kasich is an American politician, the 69th and current Governor of Ohio. First elected in 2010 and re-elected in 2014, Kasich is a member of the Republican Party. His term is set to end by January 2019.\n",
"url": "https://en.wikipedia.org/wiki/John_Kasich",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
},
"url": "https://johnkasich.com"
},
"resultScore": 22.28808
}
]
}
"kg": "http://g.co/kg"
...
"@id": "kg:/m/02zzm_"
URIs don't have to resolve, but it's nice when they do!
Note: The Knowledge Graph Search API returns only individual matching entities, rather than graphs of interconnected entities. If you need the latter, we recommend using data dumps from Wikidata instead.https://developers.google.com/knowledge-graph/
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 "Laurentian University"
:
SELECT * WHERE {
?s ?p "Laurentian 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
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
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