Tutorial
This page provides a brief tutorial of querying EventKG using the SPARQL endpoint.Prerequisites
This tutorial explains the most important concepts, classes and properties that are relevant when querying EventKG via the SPARQL query language and provides a set of simple example queries. This tutorial is not an introduction into RDF or SPARQL. If you are not yet familiar with RDF and SPARQL, please refer to existing tutorials or the SPARQL recommendation of the W3.
The EventKG SPARQL endpoint can be found here.
Schema & Prefixes
EventKG represents temporal and event-centric knowledge extracted from several sources, including Wikidata, Wikipedia, YAGO and different language editions of DBpedia. Data from these sources are integrated into a common schema. You can find a diagram of EventKG's schema here.
Whenever possible, facts extracted from the different sources are integrated into this schema (e.g., DBpedia's dbo:time is transformed into EventKG's sem:hasBeginTimeStamp). If there is no direct representation of a source-specific property in the EventKG schema (e.g., DBpedia's dbo:commander), the source-specific property is directly used in EventKG as well.
Per default, the EventKG SPARQL endpoint already defines some prefixes. You can get a list of them by clicking on "Show prefixes" below the query form. In this tutorial, we focus on the following prefixes:
Prefix | URI | Description | Examples |
---|---|---|---|
eventkg-s: | http://eventKG.l3s.uni-hannover.de/schema/ | Properties and classes in EventKG. | |
eventkg-r: | http://eventKG.l3s.uni-hannover.de/resource/ | Resources in EventKG. | |
eventkg-g: | http://eventKG.l3s.uni-hannover.de/graph/ | Graphs in EventKG that refer to the different sources. |
Identifying Events and other Resources
The following query returns the EventKG resource representing the Battle of Trafalgar. In detail, it searches for all resources which are typed as sem:Event and labeled "Battle of Trafalgar" in English.
?event rdf:type sem:Event .
?event rdfs:label "Battle of Trafalgar"@en .
}
Result
Note: The DISTINCT operator is necessary, as the same event may have been assigned the same label in different sources. We will see later how to use named graphs for restricting search results to specific sources.
An event (or another resource) can be identified in several ways:
Identification via | Description | Examples |
---|---|---|
EventKG ID | Each resource in EventKG is identified by an ID. IDs of events start with "event_", IDs of other resources start with "entity_". | |
Source ID | EventKG resources are linked with the respective resources in other sources. A particulary important ID for identifying EventKG resources are the English DBpedia IDs (via dbr:). | |
Label | Graphs in EventKG that refer to the different sources. |
EventKG also contains non-event entities such as persons, as for example Napoleon (here, we use the DBpedia ID for identification):
Event Characteristics
The schema shows some properties which are used to describe events. You can directly query events for these properties (e.g., "?event sem:hasBeginTimeStamp ?beginTime"). The following table lists the properties and gives examples:
Characteristic | Property | Example |
---|---|---|
begin time | sem:hasBeginTimeStamp | Example: Begin time of the Battle of Trafalgar |
end time | sem:hasEndTimeStamp | Example: End time of the Battle of Trafalgar |
sub event | sem:hasSubEvent | Example: Sub events of the Battle of Trafalgar |
previous event | dbo:previousEvent | Example: Previous event of the 2014 FIFA World Cup |
next event | dbo:nextEvent | Example: Next event of the 2014 FIFA World Cup |
location | sem:hasPlace | Example: Locations of the Battle of Trafalgar |
latitude | so:latitude | Example: Latitude of the Battle of Trafalgar |
longitude | so:longitude | Example: Longitude of the Battle of Trafalgar |
Source Graphs
Surprisingly, the example query for the begin time of the Battle of Trafalgar gives two different results. This can be explained by the fact that EventKG extracts facts from different sources. With the use of named graphs, you can find out from which sources facts were extracted. The following query adds a named graph to the "begin time" fact:
WHERE {
?event owl:sameAs dbr:Battle_of_Trafalgar .
GRAPH ?source {
?event sem:hasBeginTimeStamp ?beginTime .
}
}
Result
This query reveals that begin times have been extracted from several sources. EventKG fuses temporal and spatial information. By using the named graph eventkg-g:event_kg, you can find the fused facts (example query).
(Temporal) Relations
Not all relations in EventKG can be queried via single triples as the event characteristics shown before. Instead, such facts are represented through reification via RDF statements. This is necessary to add additional context to relations, as we will see in later examples. The following image shows an example relation (eventkg-r:relation_1), which is modeled as eventkg-s:Statement and connects the Battle of Trafalgar as a subject to an object via the DBpedia-specific property dbo:commander.
(Resource IDs are fictitious)
The following query selects all relations where the Battle of Trafalgar acts as subject:
WHERE {
?event owl:sameAs dbr:Battle_of_Trafalgar .
?relation rdf:subject ?event .
?relation rdf:object ?object .
?relation sem:roleType ?roleType .
}
Result
With reification, we can add additional context information to a relation. In EventKG, temporal relations are of particular importance. The following query selects all temporal relations where Napoleon acts as a subject, simply by adding one more triple: ?relation sem:hasBeginTimeStamp ?beginTime.
WHERE {
?napoleon owl:sameAs dbr:Napoleon .
?relation rdf:subject ?napoleon .
?relation rdf:object ?object .
?relation sem:roleType ?roleType .
?relation sem:hasBeginTimeStamp ?beginTime .
}
Result
Link Relations
The importance of events varies a lot: For example, while the World War II is of high importance across the world, the German Athletics Championships in 2017 were much less important. Event importance is also differnt depending on the perspective: Barack Obama is highly related to the US presidential elections in 2008 but not to the German federal election in 2009. However, the opposite holds for Angela Merkel. One way to measure event importance is to count links in Wikipedia. The following query selects all resources (?target) where the German Wikipedia page (eventkg-g:wikipedia_de) of the Battle of Trafalgar links to, plus the number of links:WHERE {
?event owl:sameAs dbr:Battle_of_Trafalgar .
?relation rdf:subject ?event .
?relation rdf:object ?target .
GRAPH eventkg-g:wikipedia_de {
?relation eventkg-s:links ?numberOfLinks .
}
}
Result
The following table lists the used properties for retrieving link counts:
Description | Property | Examples |
---|---|---|
Number of links FROM a Wikipedia page | eventkg-s:links (subject) | |
Number of links TO a Wikipedia page | eventkg-s:links (object) | |
Number of sentences which mention a pair of Wikipedia pages | eventkg-s:mentions |
Note 1: eventkg-s:mentions is symmetric.
Note 2: EventKG contains links from/to/between: (i) pairs of events, (ii) pairs of an event and a non-event, (iii) pairs of two non-events, if they are connected through a fact.
Note 3: Typically, pages are only linked at their first appearance on a Wikipedia page. That's why EventKG enriches the link counts in Wikipedia: It looks for re-appearance of the link anchor text on the same Wikipedia page.
Text Events
Events such as the Battle of Trafalgar, the 2014 FIFA World Cup and the 2020 Beirut explosions typically follow some patterns: they are named and represented in typical knowledge graphs and Wikipedia. But how about events such as "Napoleon authorizes the celebration of a Joan of Arc feast in Orléans on 8 May", which are important as well, but nowhere represented as compact as the previously mentioned events? EventKG also contains events like that, extracted from Wikipedia event lists and the Wikipedia Current Events Portal. In contrast to named events, they do not have a link to an external resource via owl:sameAs and they do not have a label. Instead, they have a description (dcterms:description). We will give an example in the next section.Note: In contrast to named events, text events are less interlinked in Wikipedia, i.e., the Wikipedia link counts are lower.
Combined Together
After this introduction to the basic concepts of EventKG, we can now construct more complex queries. We give three examples here.
The following query selects all temporal relation where Napoleon acts as the subject. In addition, it provides the English labels of the object and the property.
WHERE {
# Retrieve all relations where Napoleon is the subject.
?napoleon owl:sameAs dbr:Napoleon .
?relation rdf:subject ?napoleon .
?relation rdf:object ?object .
# Retrieve the English labels of the linked objects.
GRAPH eventkg-g:wikipedia_en {
?object rdfs:label ?objectLabel .
}
# Retrieve the English labels of the properties.
?relation sem:roleType ?roleType .
?roleType rdfs:label ?propertyLabel .
FILTER(LANG(?propertyLabel) = "en" ) .
# Retrieve the begin time and, optionally, the end time of the relation.
?relation sem:hasBeginTimeStamp ?beginTime .
OPTIONAL {
?relation sem:hasEndTimeStamp ?endTime .
}
}
# Order the relations chronologically.
ORDER BY ?beginTime
Result
The following query selects the German DBpedia IDs of all sub events of the 2018 FIFA World Cup, together with their fused start time and the number of common mentions in all covered Wikipedia language editions.
WHERE {
# Find sub events of the 2018 FIFA World Cup.
?event owl:sameAs dbr:2018_FIFA_World_Cup .
?event sem:hasSubEvent+ ?subEvent .
# Find the German DBpedia ID of the sub events.
GRAPH eventkg-g:dbpedia_de {
?subEvent owl:sameAs ?dbpediaId .
}
# Retrieve the fused begin time of the sub event.
GRAPH eventkg-g:event_kg {
?subEvent sem:hasBeginTimeStamp ?beginTime .
}
# Get the number of sentences mentioning both the world cup and the sub event.
?relation rdf:subject ?event .
?relation rdf:object ?subEvent .
?relation eventkg-s:mentions ?numberOfLinks .
}
GROUP BY ?dbpediaId ?beginTime
# Sum together all the link counts from different language editions to get the total link count.
ORDER BY (SUM(?numberOfLinks))
Result
The following query selects all text events which link to Napoleon, together will their start times and all resources they link.
?beginTime
# There could be multiple descriptions of the same event. Take a radom one of them.
SAMPLE(STR(?description))
# Create a list of resources that are linked by the event.
(GROUP_CONCAT(DISTINCT ?linkedLabel; SEPARATOR = ", ") AS ?linkedResources)
WHERE {
# Find events that link to Napoleon
?napoleon owl:sameAs dbr:Napoleon .
?event rdf:type eventkg-s:TextEvent .
?event sem:hasActor ?napoleon.
# Where does the text event link to, except for Napoleon?
?event sem:hasActor ?linked .
FILTER(?linked != ?napoleon) .
?linked skos:prefLabel ?linkedLabel .
# English descriptions only
?event dcterms:description ?description .
FILTER(LANG(?description) = "en" ) .
# Start time of the event
?event sem:hasBeginTimeStamp ?beginTime .
}
# Group by event. This way, we can show all resources linked by this event together.
GROUP BY ?event ?beginTime
# Order events chronologically.
ORDER BY ?beginTime
Result
More Queries
You can more examples of other queries here.