SPARQL query service/queries/examples/en
Basic functions
select - where: Select all items where the author is Tiphaigne de la Roche
SELECT all the items and their labels WHERE the author is Tiphaigne de la Roche
#title:novels by Tiphaigne de la Roche, with labels
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?item ?itemLabel
WHERE
{
?item mmdt:P5 mmd:Q940.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Bind: Publication years of the novels
Retrieve the publication years of the novels.
#title:Publication years of the novels
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?work ?workLabel ?year #display work as Link, the Label and the year
WHERE
{
?work mmdt:P9 ?pubyear . # P9 : date of publication
?work rdfs:label ?workLabel . # get the label of your item (work)
FILTER(lang(?workLabel) = "fr") . # filter the language, otherwise you will get triple the amount of results
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], fr". }
BIND(YEAR(?pubyear) as ?year). # extract the year of the datetime-formatted ?pubyear and bind it to ?year
}
ORDER BY ?year # sort the results by ascending (default) year
Limit: Authors and their count of novels limited to top 10
Authors and novels limited to top 10 This query takes all items whose value of BGRF_tone_intention (P31) is MYLNE, Vivienne Gower (Q5) and count the total number of items using COUNT function.
#title:Authors and their count of novels limited to top 10
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?authorName (count (?authorName) as ?count)
WHERE {
?work mmdt:P5 ?author . # work has author.
?author rdfs:label ?authorName . # get author label (not only Link to author)
FILTER(LANG(?authorName) = "en") . # other options: "fr", "de". Filter is needed as there is more than one label (language dependent)
}
group by ?authorName
order by desc (?count)
limit 10
Filter: Filter for all authors that published a novel in 1800
Filter for all authors that published a novel in 1800
#title:authors that published a novel in 1800
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT DISTINCT ?authorName (YEAR(?pubdate) as ?year)
WHERE {
?work mmdt:P5 ?author; mmdt:P9 ?pubdate. # work has author and a publication date
?author rdfs:label ?authorName . # get author label (not only Link to author)
FILTER(LANG(?authorName) = "en"). # other options: "fr", "de". Filter is needed as there is more than one label (language dependent)
FILTER(YEAR(?pubdate) = 1800). # filter for the publication date of interest
}
Filter: Get all authors whose name contains “beau”
Get all authors whose name contains “beau”
- title:Authors whose name contains "beau"
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/> PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
#title:Authors whose name contains "beau"
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?authorName ?author
WHERE {
?author mmdt:P11 mmd:Q11 . # item has property "occupation"(P11) namely "author"(Q11).
?author rdfs:label ?authorName . # get author label (not only URL to author)
FILTER(LANG(?authorName) = "fr") .
FILTER(CONTAINS(LCASE(?authorName), "beau")).
}
Optional: Novels by François-Thomas-Marie de Baculard d’ARNAUD and their tonality if available
Get all novels written by François-Thomas-Marie de Baculard d’ARNAUD and their tonality
#title:Novels by François-Thomas-Marie de Baculard d’ARNAUD
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?work ?workLabel ?tonality
WHERE
{
?work mmdt:P5 mmd:Q68 # work has author François-Thomas-Marie de Baculard d’ARNAUD
OPTIONAL { ?work mmdt:P31 ?tonality. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
Get all Items that have Matches to wikidata
Example on how to use the "Close Match" or "Exact Match" properties to query the MiMoText database.
#title:Items with a close match to other knowledge graphs
#defaultView:Dimensions
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT
?item ?itemLabel ?value
WHERE
{
?item mmdt:P16 ?value #items with property "close match“, substitute mmdt:P13 for exact match, other relational properties see Wiki
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
List all Properties
This shows how to list all properties defined in the database.
#title:List of all properties used in the MiMoText graph
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?property ?propertyLabel ?prop
WHERE {
?property a wikibase:Property .
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
BIND(STRAFTER(STR(?property), "entity/") as ?prop)
}
ORDER BY ASC(xsd:integer(STRAFTER(STR(?property), 'P')))
Basic Data Extraction: Overview over some data and handling of missing data statements
This query shows hoe to extract data from our database by querying different properties of authors. It is also an example on how to handle missing values (see comments).
#title: Some data about the MiMoTextBase such as Authors, Novels, publication years, tone etc.
# Prefix declarations for shortening URIs
prefix mmd: <http://data.mimotext.uni-trier.de/entity/>
prefix mmdt: <http://data.mimotext.uni-trier.de/prop/direct/>
# Selecting distinct data fields for analysis
SELECT DISTINCT ?bgrf ?item ?authorlabel ?itemLabel ?year ?narrpers ?tonality ?pages ?normalized WHERE {
?item mmdt:P5 ?author; # Who is the author?
mmdt:P4 ?title; # What is the title?
mmdt:P22 ?bgrf; # What is the identifier in the bibliographic metadata?
mmdt:P9 ?date; # What is the publication date?
# Optional data fields for more details (some novels may not have these)
OPTIONAL { ?item mmdt:P27 ?narrpers. } # Narrator's perspective
OPTIONAL { ?item mmdt:P31 ?tonality. } # Tone or writing style
OPTIONAL { ?item mmdt:P25 ?pages. } # Number of pages
# Extracting the year from the publication date
BIND(YEAR(?date) as ?year).
# Handling cases where narrpers is not available
BIND(if(bound(?narrpers), ?narrpers, "unbekannt") as ?normalized)
# Fetching the author's label in English
?author rdfs:label ?authorlabel.
FILTER(LANG(?authorlabel) = "en")
# Wikibase service for label translation
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], fr". }
} ORDER BY ?year
Authors
Timeline: authors and their novels on a timeline by publication date
This query finds and displays the first 100 authors found in the database in a timeline.
#title:Authors on a timeline, limited to 100 results
#defaultView:Timeline{"hide":["?date"]}
#line above necessary to display results in a time line!
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
Select ?authorlabel ?titel (YEAR(?date) as ?year) ?date
where{
?item mmdt:P5 ?author;
mmdt:P9 ?date;
mmdt:P4 ?titel .
?author rdfs:label ?authorlabel .
FILTER(lang(?authorlabel) = "fr") .
SERVICE wikibase:label {bd:serviceParam wikibase:language "{AUTO_LANGUAGE}".}
}LIMIT 100
Authors and Awards
Display of moments in time when authors in the database received awards in the form of a timeline.
#title:Points in time when authors of the MiMoTextBase received an award
#defaultView:Timeline
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
# visualize the point in time when authors got an award
PREFIX wd: <http://www.wikidata.org/entity/> #wikidata wd
PREFIX wdt: <http://www.wikidata.org/prop/direct/> #wikidata wdt
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?item ?award ?itemLabel ?awardLabel ?time
WHERE {
?item mmdt:P11 mmd:Q11.
?item mmdt:P13 ?WikiLink.
#Federated Query -> Wikidata
SERVICE <https://query.wikidata.org/sparql> {
?WikiLink p:P166 ?awardProperty. # get the property
?awardProperty ps:P166 ?award. # get the statement of the propery
?award rdfs:label ?awardLabel. # get the Label
FILTER(LANG(?awardLabel) ="en").
OPTIONAL{?awardProperty pq:P585 ?time.} # get the qualifiert point in time when available
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
Authors and Organizations
This shows a graph display of authors that are members of an organization. There are also examples of federated sub-queries in this example.
#defaultView:Graph
#title:Authors that are members of an organisation
PREFIX wd: <http://www.wikidata.org/entity/> #wikidata wd
PREFIX wdt: <http://www.wikidata.org/prop/direct/> #wikidata wdt
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?item ?memberOf ?itemLabel ?memberOfLabel
WHERE {
#Federated Query -> Wikidata
?item mmdt:P11 mmd:Q11.
?item mmdt:P13 ?WikiLink.
#Federated Queries, pulling information from wikidata
SERVICE <https://query.wikidata.org/sparql> {
?WikiLink wdt:P463 ?memberOf.
?memberOf rdfs:label ?memberOfLabel.
FILTER(LANG(?memberOfLabel)="en").
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
Novels
Novels per Author
This query shows how to extract authors who have written more than 10 novels. See comments on how to modify this query to extract every author and how many novels they have written in general.
#title:Authors with more than 10 novels
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?authorName (count (?authorName) as ?count)
WHERE {
?work mmdt:P5 ?author . # work has author.
?author rdfs:label ?authorName . # get author label (not only URL to author)
FILTER(LANG(?authorName) = "en") # other options: "fr", "de". Filter is needed as there is more than one label (language dependent)
}
group by ?authorName
having (count(?authorName) > 10) #can be left out to get count of written novels per author a limit can be added eg limit 20
order by desc (?count)
Publication Years
This query shows how to query the publication year of the novels in the database. Keep in mind, that this (and other) information is presented in three different languages ("en", "de", "fr") in the database, it is very important to filter the results using one of them.
#title:Publication years of the novels
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?work ?workLabel ?year #display work as Link, the Label and the year
WHERE
{
?work mmdt:P9 ?pubyear . # P9 : date of publication
?work rdfs:label ?workLabel . # get the label of your item (work)
FILTER(lang(?workLabel) = "fr") . # filter the language, otherwise you will get triple the amount of results
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], fr". }
BIND(YEAR(?pubyear) as ?year). # extract the year of the datetime-formatted ?pubyear and bind it to ?year
}
ORDER BY ?year # sort the results by ascending (default) year
Narrative Perspective
This query is for displaying the different narrative perspectives present in the database in a Bar Chart. See comments for querying the narrative perspective of each individual novel.
#title:Narrative perspectives of the novels
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT (count(?narrativePerspectiveLabel) as ?count) ?narrativePerspectiveLabel
WHERE
{
?work mmdt:P33 ?narrativePerspective. # work (novel) has property P33 (narrative perspective)
?narrativePerspective rdfs:label ?narrativePerspectiveLabel. # using of rdfs:label to display labels
FILTER(lang(?narrativePerspectiveLabel) = "en") # filter is neccessary to display only one occurence. Other possibilites would be "en" or "de".
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE], en". }
}
group by ?narrativePerspectiveLabel
#defaultView:BarChart
#if narrative perspective of each novel is of interest, delete the last two lines and add - order by asc(?workLabel) -
Distribution Formats
This shows how to display the different distribution formats and how many novels have this property in a Bar Chart.
#title:Distribution formats of publications
#defaultView:BarChart
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
Select (str(SAMPLE(year(?date))) as ?year) (count(?format) as ?count) ?format
WHERE{
?item mmdt:P26 ?format.
?item mmdt:P9 ?date .
FILTER(lang(?format) = "fr")
# FILTER(lcase(?format) = "12-in"@fr)
Filter (regex(lcase(?format), "in-\\d+[\\s\\S]"))
BIND(str(year(?date)) as ?year)
SERVICE wikibase:label {bd:serviceParam wikibase:language "{AUTO_LANGUAGE}","fr" .}
}
GROUP BY ?format ?year ?count
#having (?count> 2)
Narrative Locations
This queries the different narrative locations that are present in the database.
#title:Distinct narrative locations in the corpus
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT DISTINCT ?locLabel ?loc # use distinct to get all results only one time
WHERE
{
?work mmdt:P32 ?loc .
?loc rdfs:label ?locLabel .
FILTER (LANG(?locLabel) = "en").
}
ORDER BY ?locLabel
Tone
This shows the tone of each novel present in the database in a Tree Map.
#title:Tone of the novels
#defaultView:TreeMap
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT
?tonality ?itemLabel
WHERE
{
?item mmdt:P31 ?tonality. #tonality
?item mmdt:P9 ?date.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr". }
}
First Publication
This shows how to extract the first publication dates of all French novels in the database and group the results per year.
#title:First publication dates of all French novels 1751-1800
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT (str(SAMPLE(year(?date))) as ?year) (COUNT(*) AS ?count)
WHERE {
?item mmdt:P9 ?date .
}
GROUP BY ?date
ORDER BY DESC(?date)
Novel Settings
This shows how to get the settings of a specific type of novel (here: epistolary).
#title:Settings of epistolary novels
prefix md:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?narr_loc_name (count(*) as ?count) where {
?item mmdt:P33 ?narrative_form ;
mmdt:P32 ?narrative_location .
?narrative_form rdfs:label ?narr_form_name .
?narrative_location rdfs:label ?narr_loc_name .
filter(lang(?narr_form_name) = "en")
filter(lang(?narr_loc_name) = "en")
filter(contains(lcase(?narr_form_name), "epistolary")) #to get settings of heterodiegetic novels, you can also try "heterodiegetic" instead of "epistolary" in this line
}
group by ?narr_loc_name
order by desc(?count)
#defaultView:BubbleChart
Token Count and Narrative Form
This shows the dimension (or relation) between token count and narrative form.
#title:Dimension between token count and narrative form
#defaultView:Dimensions
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?tokencount ?formLabel WHERE {
?novel mmdt:P40 ?tokencount.
?novel mmdt:P33 ?form.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Themes
List all Themes
This query shows how to get a list of all themes (or narrative locations) with their corresponding QID and occurence.
#title:List of all themes with corresponding Q-identifier & occurrence
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?theme
(sample(?themeLabel) as ?name)
(count(*) as ?count)
WHERE {
?item mmdt:P36 ?theme. #change mmdt:P32 to get list of all narrative locations
#variable names can be changed for clarification ?theme -> ?narrativeLocation etc.
?theme rdfs:label ?themeLabel .
FILTER (LANG(?themeLabel) = "en").
}
GROUP BY ?theme
ORDER BY DESC(?count)
LIMIT 35
Thematic Concepts
View the different thematic concepts present in the database as a Bubble Chart.
#title:Thematic concepts
#defaultView:BubbleChart
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?topLabel (count(*) as ?count)
WHERE {
?item mmdt:P36 ?top .
?top rdfs:label ?topLabel .
filter(lang(?topLabel) = "en")
}
GROUP BY ?topLabel
ORDER BY desc(?count)
Query Specific Theme
View all authors who wrote novels about a specified theme in a Bubble Chart.
#title:Authors with novels about sentimentalism
#defaultView:BubbleChart
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?name (COUNT(*) as ?count) WHERE {
?item mmdt:P36 ?theme ;
mmdt:P5 ?author .
?theme rdfs:label ?about .
?author rdfs:label ?name .
FILTER(lang(?about) = "en")
FILTER(lang(?name) = "en")
FILTER(contains(lcase(?about), "sentimentalism")) #can be changed to other themes contained in database
}
GROUP BY ?name
ORDER BY DESC (?count)
Query Specific Theme #2
View all publication places of novels about a specified theme in a World Map.
#title:Publication places of novels about "travel"
#defaultView:Map{"hide": ["?nar_loc", "?topic"], "layer": "?themeLabel"}
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/> #wikidata wd
PREFIX wdt: <http://www.wikidata.org/prop/direct/> #wikidata wdt
SELECT DISTINCT ?item ?itemLabel ?placeOfPub ?placeOfPubLabel ?wikidataEntityLink ?coordinateLocation ?theme ?themeLabel WHERE {
?item mmdt:P36 mmd:Q3126. # about travel
?item mmdt:P36 ?theme. # work with 0 or more topics
?item mmdt:P10 ?placeOfPub. # work has place publication
?placeOfPub mmdt:P13 ?WikiLink. # place of publication ist mit Wikidata-Link verknüpft
#Federated Query -> Wikidata
SERVICE <https://query.wikidata.org/sparql> {
?WikiLink wdt:P625 ?coordinateLocation .
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
}
Display Themes
This shows how to view the themes of the novels in the database in a Bar Chart. See comments on how to view all of the narrative forms present per novel.
#title:Themes of French novels 1751-1800
#defaultView:BarChart
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
Select (str(SAMPLE(year(?date))) as ?year) (count(?themelabel) as ?count) ?themelabel
WHERE{
?item mmdt:P36 ?theme. #replace with mmdt:P33 to get narrative forms of these novels
#variable names can be adjusted too (like ?formlabel instead of ?themelabel for clarity)
?theme rdfs:label ?themelabel .
?item mmdt:P9 ?date .
FILTER(lang(?themelabel) = "fr")
BIND(str(year(?date)) as ?year)
SERVICE wikibase:label {bd:serviceParam wikibase:language "{AUTO_LANGUAGE}","fr" .}
}
GROUP BY ?themelabel ?year ?count
#having (?count> 1)
All Themes
This shows how to display all themes present in the database.
#title:All themes in the MiMoText graph
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
Select ?themeLabel
WHERE{
?item mmdt:P36 ?theme.
?theme rdfs:label ?themeLabel .
FILTER(lang(?themeLabel) = "en")
BIND(str(year(?date)) as ?year)
SERVICE wikibase:label {bd:serviceParam wikibase:language "en".}
}
GROUP BY ?themeLabel
Query Specific Theme given Area
This shows how to extract themes from the database given a specific narrative location (here: rural area).
#title:Themes of novels set in "rural areas"
#defaultView:TreeMap
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?theme ?themeLabel ?item ?itemLabel WHERE {
?item mmdt:P36 ?theme .
?item mmdt:P32 mmd:Q3243 # items with narrative location (P32): rural area
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Thematic Concepts
This shows how to query the thematic concepts given all novels and view them in a Bubble Chart.
#title:Thematic concepts per novel
#defaultView:BubbleChart
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?topicLabel (COUNT(?topicLabel) as ?count)
WHERE {
?item mmdt:P2 mmd:Q2. # get all instances of literary work
?item mmdt:P36 ?topic . # get the thematic concepts of the items
?topic rdfs:label ?topicLabel .
FILTER(LANG(?topicLabel) = "en") .
}
GROUP BY ?topicLabel
ORDER BY desc(?count)
Spaces
Most Common Publication Places
#title:Most common publication places
#defaultView:Map{"hide": ["?pub_loc"]}
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/> #wikidata wd
PREFIX wdt: <http://www.wikidata.org/prop/direct/> #wikidata wdt
SELECT DISTINCT ?item ?itemLabel ?pub_loc ?pub_locLabel ?wikidataEntityLink ?coordinateLocation ?theme ?themeLabel WHERE {
?item mmdt:P10 ?pub_loc.
?pub_loc mmdt:P13 ?WikiLink.
#Federated Query -> Wikidata
SERVICE <https://query.wikidata.org/sparql> {
?WikiLink wdt:P625 ?coordinateLocation
}
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
Federated queries
Narrative Places, their Wikidata matches and geographic coordinates
This query shows how to display the narrative (or publication) locations using the world map by extracting coordinate locations from Wikidata. Every time information from Wikidata is required, a federated query is necessary. Optionally, an added layer of token count can be added.
#title:Narrative places (using Wikidata coordinate locations)
#defaultView:Map{"hide": ["?nar_loc"], "markercluster":"true"}
#remove {"hide": ["?nar_loc"], "markercluster":"true"} if publication locations are queried
PREFIX wd: <http://www.wikidata.org/entity/> #wikidata wd
PREFIX wdt: <http://www.wikidata.org/prop/direct/> #wikidata wdt
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT DISTINCT ?item ?itemLabel ?nar_loc ?nar_locLabel ?WikiDataEntity ?coordinateLocation
WHERE { ?item mmdt:P32 ?nar_loc. # change mmdt:P10 if publication locations are of interest
?nar_loc mmdt:P13 ?WikiDataEntity.
#add an additional layer of token count
#?item mmdt:P40 ?tokencount.
#BIND(
#IF(?tokencount <= 50000, "short",
#IF(?tokencount <= 150000, "medium",
#"long"))
#AS ?layer).
#Federated Query -> Wikidata
SERVICE <https://query.wikidata.org/sparql> {
?WikiDataEntity wdt:P625 ?coordinateLocation
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
Exact Wikidata Matches (Authors)
This query shows pictures of authors that are present in the MiMoText base and in Wikidata.
#title:Authors in the MiMoTextBase with exact Wikidata match and Wikidata image
#defaultView:ImageGrid
PREFIX mmd: <http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt: <http://data.mimotext.uni-trier.de/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
SELECT ?author ?authorLabel ?img
WHERE {
?author mmdt:P11 mmd:Q11;
mmdt:P13 ?wikiLink.
SERVICE <https://query.wikidata.org/sparql>{
?wikiLink wdt:P18 ?img.
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Change over time
Display Change over Time
This query will show changes in publication places in a Bar Chart.
#title:Change of publication places over time
#defaultView:BarChart
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?year ?placelabel (COUNT(*) as ?countyearplace) WHERE {
#Identify items with a specified place and retrieve the place label (P10 = place of publication)
?item mmdt:P10 ?place.
?place rdfs:label ?placelabel .
#Extract their publication date (P9)
?item mmdt:P9 ?date .
FILTER(lang(?placelabel) = "fr")
BIND(str(year(?date)) as ?year)
SERVICE wikibase:label {bd:serviceParam wikibase:language "{AUTO_LANGUAGE}","fr" .}
}
GROUP BY ?year ?placelabel #group results by year and place of publication
HAVING (?countyearplace > 1) #only include instance in which the count is greater than 1
Changes in Theme
This query will display the changes in a specific theme (here: travel) over time in a Bar Chart.
#title:Evolution of "travel" theme in French novels 1751-1800
#defaultView:BarChart
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?date ?countTravel ?countAll (?countTravel / ?countAll AS ?rel)
WHERE {
{
# Subquery to count novels with the "travel" theme
SELECT ?date (count(*) AS ?countTravel)
WHERE {
?item mmdt:P9 ?date;
mmdt:P36 ?topic .
?topic rdfs:label ?topicLabel .
# Filtering for English labels with "travel"
FILTER(lang(?topicLabel) = "en")
FILTER(lcase(?topicLabel) = "travel"@en)
}
GROUP BY ?date
}
{
# Subquery to count all novels
SELECT ?date (count(*) AS ?countAll)
WHERE {
?item mmdt:P9 ?date;
mmdt:P36 ?topic .
?topic rdfs:label ?topicLabel .
filter(lang(?topicLabel) = "en")
}
GROUP BY ?date
}
}
Comparing sources
Comparing Topics
#Title:Statements on consistent topics in novels from both sources (TM & bibl. metadata)
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
prefix mmps:<http://data.mimotext.uni-trier.de/prop/statement/>
prefix mmpr: <http://data.mimotext.uni-trier.de/prop/reference/>
PREFIX mmp: <http://data.mimotext.uni-trier.de/prop/>
SELECT ?item ?itemLabel ?value ?valueLabel
WHERE
{
?item mmp:P36 ?statement.
?statement mmps:P36 ?value .
?statement prov:wasDerivedFrom ?refnode. #statement has a reference
?refnode mmpr:P18 mmd:Q21. #reference statement uses 'P18'='stated in' topic modeling
?statement prov:wasDerivedFrom ?refnodeB.
?refnodeB mmpr:P18 mmd:Q1 .#reference statement uses 'P18'='stated in' bibliographie
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Visualizations
Bubble Chart: topics exctracted via Topic Modelling
Here, you can display the different topics present in the database in a Bubble Chart.
#title:Topics referenced by topic modeling (Q21)
#do not delete following line. it looks like a comment but is important for the presentation of the results as a Bubble Chart.
#defaultView:BubbleChart
prefix mmd:<http://data.mimotext.uni-trier.de/entity/>
prefix mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
prefix mmps:<http://data.mimotext.uni-trier.de/prop/statement/>
prefix mmpr:<http://data.mimotext.uni-trier.de/prop/reference/>
SELECT ?themeLabel
(count(*) as ?count)
WHERE
{
?statement mmps:P36 ?theme. #statement has property 'about'
?statement prov:wasDerivedFrom ?refnode. #statement has a reference
?refnode mmpr:P18 mmd:Q21. #reference statement uses 'P18'=stated in; stated in: Q21. use mmd:Q1 to see topics referenced by Bibliographie du genre romanesque français
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?themeLabel
ORDER BY ?name
Line Chart: Average Token Count
This example shows hoe you can display information in different Charts. Here, you can see the average token count for each possible narrative form/year.
#title:average token count for each possible narrative form per year
#defaultView:LineChart
#replace LineChart with BarChart or ScatterChart if you prefer that presentation of your data
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?year (avg(?tokencount) as ?avgtokencount) ?narrForm ?narrFormLabel
WHERE{
?item mmdt:P9 ?publicationdate. # get publication date
?item mmdt:P40 ?tokencount. # get tokencount
BIND(str(YEAR(?publicationdate)) as ?year). # extract year from pubdate
?item mmdt:P33 ?narrForm. # get narrative form
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
}
GROUP BY ?narrForm ?year ?narrFormLabel
ORDER BY ?year
Animated Bar Chart: Count of different Tone per Intention over the years
This is a way to dynamically display information that is dependent on more than one variable. Here, the count of different tones per intention is shown. The Bar Chart is animated and changes as the years go on.
#title:Count of different tones per intention and year (animated)
#defaultView:BarChart
PREFIX mmd: <http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt: <http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?intentionLabel (COUNT(?tone) AS ?toneCount) ?toneLabel ?year
WHERE{
?item mmdt:P2 mmd:Q2; # item is instance of literary work
mmdt:P9 ?pubdate; # get the publication date
mmdt:P38 ?tone; # get tone of work-item
mmdt:P39 ?intention. # get intention of work-item
?tone rdfs:label ?toneLabel. # get the tone label
?intention rdfs:label ?intentionLabel. # get the intention label
FILTER(LANG(?toneLabel) = "en"). # filter for language
FILTER(LANG(?intentionLabel)="en"). # filter for language
BIND(str(YEAR(?pubdate)) as ?year). # filter year of the publication date
}
GROUP BY ?year ?toneLabel ?intentionLabel
Publication Places
This example shows how to display information in an Area Chart. Here, the publication places with at least 5 instances per year are queried.
#title:Publication places that occur at least 5 times per year
#defaultView:AreaChart
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?date (count(?pubPlace) as ?count) ?pubPlaceLabel
WHERE{
?item mmdt:P2 mmd:Q2;
mmdt:P9 ?date;
mmdt:P10 ?pubPlace.
?pubPlace rdfs:label ?pubPlaceLabel.
FILTER(LANG(?pubPlaceLabel) = "en").
}
GROUP BY ?date ?pubPlaceLabel
HAVING (count(?pubPlaceLabel) > 4)
Thematic Concepts, Novels and Authors
Here is an example on how to display information in an expandable list. The result will be a list of authors with the second level being their works, and the third being the topic labels of these works.
#title:Authors, their novels and thematic concepts
#defaultView:Tree
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?author ?authorLabel
?item ?itemLabel
?topic ?topicLabel
WHERE{
?item mmdt:P2 mmd:Q2; # item is instance of literary work
mmdt:P36 ?topic; # item has a thematic concept
mmdt:P33 ?narrForm; # item has a narrative form
mmdt:P5 ?author.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}ORDER BY ?authorLabel
Authors and Organizations (at least 2 Members)
This is how to display information in an intricate Graph. Here, the authors in the MiMoText database are queried and are connected to the societies they were members. To identify their membership, federated queries are used to extract that information from Wikidata.
#defaultView:Graph
#title:MiMoText authors that are members of an organisation having at least two members
PREFIX wd: <http://www.wikidata.org/entity/> #wikidata wd
PREFIX wdt: <http://www.wikidata.org/prop/direct/> #wikidata wdt
PREFIX mmd:<http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt:<http://data.mimotext.uni-trier.de/prop/direct/>
SELECT ?author ?authorLabel ?img ?memberOf ?memberOfLabel
WHERE {
?author mmdt:P11 mmd:Q11.
?author mmdt:P13 ?WikiLink. #important for federated query!
#federated query: extracts the organization the author is a member of and optionally their picture
SERVICE <https://query.wikidata.org/sparql> {
?WikiLink wdt:P463 ?memberOf.
?memberOf rdfs:label ?memberOfLabel.
OPTIONAL{?WikiLink wdt:P18 ?img}.
FILTER(LANG(?memberOfLabel)="en").
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
{
#Count the number of authors for each organization and include only those with more than 1 author
SELECT ?memberOf (COUNT(?author) as ?countmember)
WHERE {
?author mmdt:P11 mmd:Q11.
?author mmdt:P13 ?WikiLink.
SERVICE <https://query.wikidata.org/sparql> {
?WikiLink wdt:P463 ?memberOf.
}
}
GROUP BY ?memberOf
HAVING (?countmember > 1)
}
}