SPARQL query service/queries/examples/en: Difference between revisions
m (Admin moved page Wiki/Wikidata:SPARQL query service/queries/examples to SPARQL query service/queries/examples/en without leaving a redirect) |
No edit summary |
||
Line 128: | Line 128: | ||
} | } | ||
}} | }} | ||
== <!--T:9--> Authors == | |||
=== <!--T:708--> Test === | |||
<!--T:708--> | |||
This query takes all items whose value of {{P|31}} is {{Q|5}} and count the total number of items using COUNT function. | |||
{{SPARQL|query= | |||
#title:novels by Tiphaigne de la Roche | |||
PREFIX mmd: <http://ldvpc92.uni-trier.de:36999/entity/> | |||
PREFIX mmdt: <http://ldvpc92.uni-trier.de:36999/prop/direct/> | |||
SELECT ?item | |||
WHERE | |||
{ | |||
?item mmdt:P5 mmd:Q940. | |||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } | |||
} | |||
}} | |||
=== <!--T:708--> Timeline === | |||
<!--T:708--> | |||
This query finds and displays the first 100 authors found in the database in a timeline. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:708--> Basic Data Extraction === | |||
<!--T:708--> | |||
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). | |||
{{SPARQL|query=#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 | |||
mmdt:P31 ?tonality; # Tone or writing style | |||
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 | |||
}} | |||
=== <!--T:708--> Authors and Awards === | |||
<!--T:708--> | |||
Display of moments in time when authors in the database received awards in the form of a timeline. | |||
{{SPARQL|query=#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" . } | |||
} | |||
}} | |||
=== <!--T:708--> Authors and Organizations === | |||
<!--T:708--> | |||
This shows a graph display of authors that are members of an organization. There are also examples of federated sub-queries in this example. | |||
{{SPARQL|query=#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" . } | |||
} | |||
}} | |||
== <!--T:9--> Basic functions == | |||
=== <!--T:708--> Select - where === | |||
<!--T:708--> | |||
SELECT all the items and their labels WHERE the author is Tiphaigne de la Roche | |||
{{SPARQL|query=#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". } | |||
} | |||
}} | |||
=== <!--T:708--> Bind === | |||
<!--T:708--> | |||
Retrieve the publication years of the novels. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:708--> Limit === | |||
Authors and novels limited to top 10 | |||
<!--T:708--> | |||
This query takes all items whose value of {{P|31}} is {{Q|5}} and count the total number of items using COUNT function. | |||
{{SPARQL|query=#tile: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 | |||
}} | |||
=== <!--T:708--> Filter: Filter for all authors that published a novel in 1800 === | |||
<!--T:708--> | |||
Filter for all authors that published a novel in 1800 | |||
{{SPARQL|query=#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 | |||
} | |||
}} | |||
=== <!--T:708--> 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/> | |||
{{SPARQL|query=#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")). | |||
} | |||
}} | |||
=== <!--T:708--> Optional === | |||
<!--T:708--> | |||
Get all novels written by François-Thomas-Marie de Baculard d’ARNAUD and their tonality | |||
{{SPARQL|query=#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 wdt:P31 ?tonality. } | |||
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". } | |||
} | |||
}} | |||
=== <!--T:708--> Close/Exact Match === | |||
<!--T:708--> | |||
Example on how to use the "Close Match" or "Exact Match" properties to query the MiMoText database. | |||
{{SPARQL|query=#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". } | |||
} | |||
}} | |||
=== <!--T:708--> List all Properties === | |||
<!--T:708--> | |||
This shows how to list all properties defined in the database. | |||
{{SPARQL|query=#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'))) | |||
}} | |||
== <!--T:9--> Novels == | |||
=== <!--T:708--> Novels per Author === | |||
<!--T:708--> | |||
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. | |||
{{SPARQL|query=#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) | |||
}} | |||
=== <!--T:708--> Publication Years === | |||
<!--T:708--> | |||
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. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Narrative Perspective === | |||
<!--T:70--> | |||
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. | |||
{{SPARQL|query=#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) - | |||
}} | |||
=== <!--T:709--> Distribution Formats === | |||
<!--T:709--> | |||
This shows how to display the different distribution formats and how many novels have this property in a Bar Chart. | |||
{{SPARQL|query=#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) | |||
}} | |||
=== <!--T:709--> Narrative Locations === | |||
<!--T:709--> | |||
This queries the different narrative locations that are present in the database. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Tone === | |||
<!--T:709--> | |||
This shows the tone of each novel present in the database in a Tree Map. | |||
{{SPARQL|query=#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". } | |||
} | |||
}} | |||
=== <!--T:709--> First Publication === | |||
<!--T:709--> | |||
This shows how to extract the first publication dates of all French novels in the database and group the results per year. | |||
{{SPARQL|query=#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) | |||
}} | |||
=== <!--T:709--> Novel Settings === | |||
<!--T:709--> | |||
This shows how to get the settings of a specific type of novel (here: epistolary). | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Token Count and Narrative Form === | |||
<!--T:709--> | |||
This shows the dimension (or relation) between token count and narrative form. | |||
{{SPARQL|query=#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". } | |||
} | |||
}} | |||
== <!--T:9--> Themes == | |||
=== <!--T:709--> List all Themes === | |||
<!--T:709--> | |||
This query shows how to get a list of all themes (or narrative locations) with their corresponding QID and occurence. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Thematic Concepts === | |||
<!--T:709--> | |||
View the different thematic concepts present in the database as a Bubble Chart. | |||
{{SPARQL|query=#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) | |||
}} | |||
=== <!--T:709--> Query Specific Theme === | |||
<!--T:709--> | |||
View all authors who wrote novels about a specified theme in a Bubble Chart. | |||
{{SPARQL|query=#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) | |||
}} | |||
=== <!--T:709--> Query Specific Theme #2 === | |||
<!--T:709--> | |||
View all publication places of novels about a specified theme in a World Map. | |||
{{SPARQL|query=#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" . | |||
} | |||
} | |||
}} | |||
=== <!--T:709--> Display Themes === | |||
<!--T:709--> | |||
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. | |||
{{SPARQL|query=#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) | |||
}} | |||
=== <!--T:709--> All Themes === | |||
<!--T:709--> | |||
This shows how to display all themes present in the database. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Query Specific Theme given Area === | |||
<!--T:709--> | |||
This shows how to extract themes from the database given a specific narrative location (here: [https://data.mimotext.uni-trier.de/wiki/Item:Q3243 rural area]). | |||
{{SPARQL|query=#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". } | |||
} | |||
}} | |||
=== <!--T:709--> Thematic Concepts === | |||
<!--T:709--> | |||
This shows how to query the thematic concepts given all novels and view them in a Bubble Chart. | |||
{{SPARQL|query=#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) | |||
}} | |||
== <!--T:9--> Spaces == | |||
=== <!--T:709--> Most Common Publication Places === | |||
<!--T:709--> | |||
{{SPARQL|query=#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" . | |||
} | |||
}} | |||
== <!--T:9--> Federated queries == | |||
=== <!--T:709--> Narrative Places, their Wikidata matches and geographic coordinates === | |||
<!--T:709--> | |||
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. | |||
{{SPARQL|query=#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" . } | |||
} | |||
}} | |||
=== <!--T:709--> Exact Wikidata Matches (Authors) === | |||
<!--T:709--> | |||
This query shows pictures of authors that are present in the MiMoText base and in Wikidata. | |||
{{SPARQL|query=#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". } | |||
} | |||
}} | |||
== <!--T:9--> Change over time == | |||
=== <!--T:709--> Display Change over Time === | |||
<!--T:709--> | |||
This query will show changes in publication places in a Bar Chart. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Changes in Theme === | |||
<!--T:709--> | |||
This query will display the changes in a specific theme (here: travel) over time in a Bar Chart. | |||
{{SPARQL|query=#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 | |||
} | |||
} | |||
}} | |||
== <!--T:9--> Comparing sources == | |||
=== <!--T:709--> Comparing Topics === | |||
<!--T:709--> | |||
{{SPARQL|query=#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". } | |||
} | |||
}} | |||
== <!--T:9--> Visualizations == | |||
=== <!--T:709--> Connection between Objects and Predicates === | |||
This explores the connections between objects and predicates in the MiMoText database. The QID in this example references a specific work present in the database - feel free to replace it with another QID. | |||
<!--T:709--> | |||
{{SPARQL|query=#title:Datatypes of objects and connecting predicates under item Q1053 | |||
PREFIX mmd: <http://data.mimotext.uni-trier.de/entity/> | |||
PREFIX mmdt: <http://data.mimotext.uni-trier.de/prop/direct/> | |||
SELECT DISTINCT (datatype(?o) as ?datatype) ?o ?oLabel ?p | |||
WHERE{ | |||
mmd:Q1053 ?p ?o. | |||
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } | |||
}ORDER BY desc(?datatype) | |||
}} | |||
=== <!--T:709--> Topic Modelling === | |||
<!--T:709--> | |||
Here, you can display the different topics present in the database in a Bubble Chart. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Average Token Count === | |||
<!--T:709--> | |||
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. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Counted Tones === | |||
<!--T:709--> | |||
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. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Publication Places === | |||
<!--T:709--> | |||
This example shows how to display information in an Area Chart. Here, the publication places with at least 5 instances per year are queried. | |||
{{SPARQL|query=#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) | |||
}} | |||
=== <!--T:709--> Thematic Concepts, Novels and Authors === | |||
<!--T:709--> | |||
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. | |||
{{SPARQL|query=#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 | |||
}} | |||
=== <!--T:709--> Authors and Organizations (at least 2 Members) === | |||
<!--T:709--> | |||
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. | |||
{{SPARQL|query=#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) | |||
} | |||
} | |||
}} | |||
== <!--T:9--> Queries about secondary literature and references == |
Revision as of 13:26, 11 December 2023
Simple queries
Cats
This query looks at all items whose value of BGRF_tone_intention (P31) is BONAPARTE, Joseph-Napoléon, roi d’Espagne (Q146). It uses the service wikibase:label to return the labels in your default language or in English.
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31 wd:Q146. # Must be of a cat
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # Helps get the label in your language, if not, then en language
}
Goats
This query looks at all items whose value of BGRF_tone_intention (P31) is natural history (Q2934). It uses the service wikibase:label to return the labels in your default language or in English.
SELECT ?item ?itemLabel
WHERE
{
?item wdt:P31 wd:Q2934.
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}
Horses (showing some info about them)
This query looks at items whose value of BGRF_tone_intention (P31) is MUSGRAVE, Agnes (Q726) or any subclass of (P279 (P279)) MUSGRAVE, Agnes (Q726). It displays the value of number of pages string (P25), BGRF ID (P22), full work available at URL (P21) and computes birth year using P569 (P569) death year using P570 (P570). Items are ordered using the horses qid.
#Illustrates optional fields, instances of subclasses, language fallback on label service, date to year conversion
#title: Horses on Wikidata
SELECT DISTINCT ?horse ?horseLabel ?mother ?motherLabel ?father ?fatherLabel (year(?birthdate) as ?birthyear) (year(?deathdate) as ?deathyear) ?genderLabel
WHERE
{
?horse wdt:P31/wdt:P279* wd:Q726 . # Instance et sous-classes de Q726-Cheval
OPTIONAL{?horse wdt:P25 ?mother .} # P25 : Mère
OPTIONAL{?horse wdt:P22 ?father .} # P22 : Père
OPTIONAL{?horse wdt:P569 ?birthdate .} # P569 : Date de naissance
OPTIONAL{?horse wdt:P570 ?deathdate .} # P570 : Date de décès
OPTIONAL{?horse wdt:P21 ?gender .} # P21 : Sexe
SERVICE wikibase:label { #BabelRainbow
bd:serviceParam wikibase:language "[AUTO_LANGUAGE],fr,ar,be,bg,bn,ca,cs,da,de,el,en,es,et,fa,fi,he,hi,hu,hy,id,it,ja,jv,ko,nb,nl,eo,pa,pl,pt,ro,ru,sh,sk,sr,sv,sw,te,th,tr,uk,yue,vec,vi,zh"
}
}
ORDER BY ?horse
Cats, with pictures
This query looks at all items with value of BGRF_tone_intention (P31) equals to BONAPARTE, Joseph-Napoléon, roi d’Espagne (Q146) with a stated in (P18). The results are displayed as a gallery with the option '#defaultView:ImageGrid'.
#defaultView:ImageGrid
SELECT ?item ?itemLabel ?pic
WHERE
{
?item wdt:P31 wd:Q146 .
?item wdt:P18 ?pic
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
Map of hospitals
The query displays all items whose value of BGRF_tone_intention (P31) is Q16917 or any P279 (P279) of Q16917 with P625 (P625). The results are displayed on a map using 'defaultView:Map'.
#added 2017-08
#defaultView:Map
SELECT DISTINCT * WHERE {
?item wdt:P31/wdt:P279* wd:Q16917;
wdt:P625 ?geo .
}
Map of hackerspaces
The query displays on a map ("defaultView:Map") all items whose value of BGRF_tone_intention (P31) is Q1032372 and with values for property P625 (P625).
Warnings:
- Items of class Q1032372 without any value for P625 (P625) are not returned in the query.
- Items which are instances of a subclass of Q1032372 are not returned.
Number of humans in Wikidata
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: Number of humans in Wikidata
SELECT (COUNT(*) AS ?count)
WHERE {
?item wdt:P31 wd:Q5 .
}
Authors
Test
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:novels by Tiphaigne de la Roche
PREFIX mmd: <http://ldvpc92.uni-trier.de:36999/entity/>
PREFIX mmdt: <http://ldvpc92.uni-trier.de:36999/prop/direct/>
SELECT ?item
WHERE
{
?item mmdt:P5 mmd:Q940.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Timeline
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
Basic Data Extraction
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
mmdt:P31 ?tonality; # Tone or writing style
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 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" . }
}
Basic functions
Select - where
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
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 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.
#tile: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
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 wdt:P31 ?tonality. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE]". }
}
Close/Exact Match
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')))
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
Connection between Objects and Predicates
This explores the connections between objects and predicates in the MiMoText database. The QID in this example references a specific work present in the database - feel free to replace it with another QID.
#title:Datatypes of objects and connecting predicates under item Q1053
PREFIX mmd: <http://data.mimotext.uni-trier.de/entity/>
PREFIX mmdt: <http://data.mimotext.uni-trier.de/prop/direct/>
SELECT DISTINCT (datatype(?o) as ?datatype) ?o ?oLabel ?p
WHERE{
mmd:Q1053 ?p ?o.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}ORDER BY desc(?datatype)
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
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
Counted Tones
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)
}
}