FactGrid:Sample queries: Difference between revisions
Olaf Simons (talk | contribs) |
Olaf Simons (talk | contribs) |
||
Line 114: | Line 114: | ||
== Grammatically intricate searches == | == Grammatically intricate searches == | ||
=== Wimimedia sources === | === Wimimedia sources === | ||
* [https:// | * [https://database.factgrid.de/query/#SELECT%20%3Fitem%20%3FitemLabel%20%3Flink%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%20%20%3Fitem%20wdt%3AP91%20wd%3AQ22423.%0A%20%20OPTIONAL%20%7B%20%3Flink%20schema%3Aabout%20%3Fitem%20%3B%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fwww.wikidata.org%2F%3E%20.%20%7D%0A%7D all Members of "Theodor zum guten Rat" with their respective Wikidata numbers] | ||
* [https://database.factgrid.de/query/#SELECT%20%3Fplace%20%3FplaceLabel%20%3Flink%20%3Fname%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%20%20%3Fplace%20wdt%3AP2%20wd%3AQ8.%0A%20%20%3Flink%20schema%3Aabout%20%3Fplace%20%3B%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fuk.wikipedia.org%2F%3E%3B%0A%20%20%20%20%20%20%20%20schema%3Aname%20%3Fname%20.%0A%7D All places that have an article on the Ukrainian Wikipedia; link with the respective uk.wp lemma] | * [https://database.factgrid.de/query/#SELECT%20%3Fplace%20%3FplaceLabel%20%3Flink%20%3Fname%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%20%20%3Fplace%20wdt%3AP2%20wd%3AQ8.%0A%20%20%3Flink%20schema%3Aabout%20%3Fplace%20%3B%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fuk.wikipedia.org%2F%3E%3B%0A%20%20%20%20%20%20%20%20schema%3Aname%20%3Fname%20.%0A%7D All places that have an article on the Ukrainian Wikipedia; link with the respective uk.wp lemma] | ||
* [https://database.factgrid.de/query/#SELECT%20%3Fitem%20%3FitemLabel%20%3Flink%20%3Fis%20%3FisLabel%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%20%20%3Flink%20schema%3Aabout%20%3Fitem%3B%0A%20%20%20%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fwww.wikidata.org%2F%3E.%0A%20%20OPTIONAL%20%7B%20%3Fitem%20wdt%3AP2%20%3Fis.%20%7D%0A%20%20%20%20%20%20minus%20%7B%0A%20%20%20%20%20%20values%20%3Fis%20%7B%0A%20%20%20%20%20%20%20%20wd%3AQ7%20%0A%20%20%20%20%20%20%20%20wd%3AQ8%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%7D%0A%20%20%0A%7D All items with a Wikidata equivalent, without humans and localities] | * [https://database.factgrid.de/query/#SELECT%20%3Fitem%20%3FitemLabel%20%3Flink%20%3Fis%20%3FisLabel%20WHERE%20%7B%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%20%20%3Flink%20schema%3Aabout%20%3Fitem%3B%0A%20%20%20%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fwww.wikidata.org%2F%3E.%0A%20%20OPTIONAL%20%7B%20%3Fitem%20wdt%3AP2%20%3Fis.%20%7D%0A%20%20%20%20%20%20minus%20%7B%0A%20%20%20%20%20%20values%20%3Fis%20%7B%0A%20%20%20%20%20%20%20%20wd%3AQ7%20%0A%20%20%20%20%20%20%20%20wd%3AQ8%20%20%20%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%7D%20%7D%0A%20%20%0A%7D All items with a Wikidata equivalent, without humans and localities] |
Revision as of 22:04, 4 September 2024
Help:
- https://www.wikidata.org/wiki/Wikidata:SPARQL_query_service/Wikidata_Query_Help/Result_Views/en
- https://en.wikibooks.org/wiki/SPARQL/FILTER
Looking for people
- Search all people of the same family name, sort by given names, state everyone with information about life dates and family details. Table
- Name of people who ever were residents of a given place with basic personal information. Table
- Two Persons, when and where did they meet timeline
- All people with a FactGrid account by gender
- search all people of a research project, Labels and Aliases
Looking for documents
- All documents written by N.N. with corresponding documents. Table
- All documents sent to N.N. with corresponding documents. Table
- All documents mentioning N.N. with corresponding documents. Table
- All documents of a file listed in sequence. Table
- All documents sent from (place) by date. Table
- All documents of a specific archive and research interest by date. Table
Looking for dates
Dates are still a problem with wikibase. The manual input is very sophisticated. You can set the precision of date and you can define the calendar format. The QuickStatements mass input allows a definition of precision with a defining component on each date (for instance "/9" precision year, "/11" precision day...) but regular searches as formulated with the Query Service's Query Helper do not grab these additional details. A 1650 year input is downloaded as a "1 January 1650" value unless you specifically ask for the precision:
- All the members of the "Fruchtbringende Gesellschaft" with dates of birth and statement of exactness
Maps
Dots
- All persons of a certain profession in a town (here merchants) / Poets in Paris / Authors in Paris in 1834 with comments / Authors in Paris in 1834 with direct links to the viewer with comments / Scholars and playwrights in Paris in 1834, map with two layers with comments
Lines
- The second missionary journey of the French Prophets 1712-1714
- The Illuminati correspondence, who wrote whom, from where, whereto
- Arthur Schopenhauer, Places of residence
- Liszt's homes in Paris
- Comte's homes in Paris
- Chopin's homes in Paris
Tables
- Was a member of the Illuminati
- All guided compositions, where written? when? plus links to FactGrid transcripts.
- no functional query yet, but a first attempt is here, modelled after the "academic tree" graph in Scholia's author aspect
- all 18th-century addresses in Gotha (which have already received geo-coordinates)
- when was the Gregorian calendar introduced?
- Lodges and their rites, how to get the qualifiers
Graphs
Timelines
Statistics
- The members of Frankfurt's Union-Lodge, branches of occupation, bubble chart
- Followers of the "French Prophets", gender ratio, bar chart
- Adherents of the French Prophets and their religious affiliation
- Those with a FactGrid account - first languages
- The Illuminati membership statements The intricate thing is that this search excludes the two 100% bubbles of Illuminati and Freemasons that are of course given with every Illuminati membership.
- J.J.C. Bode's Library (1793), profile by date of publication of the copies
- Bar chart of a historical book production by decade, script by Bruno Belhoste, books on Mesmerism by language
- Area chart of a historical book production by decade, script by Bruno Belhoste, books on Mesmerism by language
Prevent double listings
Especially important if you are working with the wdt:P2/wdt:P3* switch that can lead to double hits of the same object - the DISTINCT command:
Grammatically intricate searches
Wimimedia sources
- all Members of "Theodor zum guten Rat" with their respective Wikidata numbers
- All places that have an article on the Ukrainian Wikipedia; link with the respective uk.wp lemma
- All items with a Wikidata equivalent, without humans and localities
Statements with sources
Statements with unit information
- inherited sums of money, Lübeck late Middle Ages
- get the silver-equivalent for a computation in Reichsthaler
Get information from connected items
- The graduates of Gotha's Gymnasium Illustre/Ernestinum: their fathers with career information, their mothers and the fathers of the mothers (i.e. maternal grandfathers) with the respective career information] The search is intricate as it goes into related database objects and brings information located there into the table.
Search for specific Qualifiers on a Statement
- All documents authored by J.C.C. Bode, locations and shelf-marks
- All Teachers with begin/ end/ date information
- Authors writing all kind of satires
- Authors writing satire and all its subclasses (you just add /wdt:P3* to pq:P122)
- The people writing all kind of satires (not necessarily authors) (very simple: remove ps:P165 wd:Q23190)
Search for all the Qualifiers on Statements with the same property
- all the qualifiers for the people holding position at the pastorates of the Duchy of Gotha-Anstalt useful when you want to delete a specific qualifier in a batch of items (here the pastorates of the Duchy), because it is not possible to simply delete qualifiers with Quickstatements. You need to delete the statement with all its qualifiers and reinstall it without the qualifier you want to delete.
- all the lodges of Saint Domingue/Haiti the intricate part is, that the lodges only have information on places, the places have information on the territorial affiliation - we ask for Q176240 (Haiti) as the must have value. The bracket can also have more countries.
Looking for a statement - give it with all the qualifying statements
This search is especially useful if the data model needs to be changed. It searches the database for a particular statement and gives all the instances with the respective qualifying sub-statements:
SELECT * WHERE { ?s wdt:P2 wd:Q7. ?s p:P266 ?st. # ?st is the the statement node ?st ps:P266 ?o. # that simulates the predicate ?st ?qualifier ?value. # this is an attribute (a qualifier) }
Missing Statements
These searches are most practical to see where work has to be done or where one has forgotten to make a certain statement.
- All the items that lack a P2 (instance of) statement (2732 on 26 April 2023)
- All the titles of a specific project, that lack a P66 statement
- All people who do not have a GND number but who receive mail from a person with such a number
- all types of non-literary genres that were not listed in Eckard Rolf's book of 1993, with their present position in Rolf's systematisation
Missing connections
Wildcards
State all statements that are made on an item
- State all statements that are made on an item - the respective value has to be set in line 3.
Filters
- all FactGrid people born between 1700 and 1710 A Filter that selects a time frame
- All members of the strict Observance in Frankfurt's Prefecture A Filter that selects an Item in a qualifying statement
Filter based on strings
Filtering results containing certain strings (texts) can be archieved with `FILTER()`
SPARQL patterns for reuse
GROUP_CONCAT Bring several values in one cell (to avoid the repetition of lines)
Count properties
Get all properties of an item
SELECT ?p ?o WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } wd:Q406029 ?p ?o }
count statements per item within a certain project
or within any other property-object relation
SELECT DISTINCT ?item ?itemLabel ?statementcount WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # change property item relation ?item wdt:P131 wd:Q400012 . ?item wikibase:statements ?statementcount. }
Get popular items
Considering outcoming, incoming and sitelinks as proxys for popularity, one can formulate this query.
E.g. for Lodges:
SELECT ?item ?itemLabel ?outcoming ?sitelinks ?incoming { ?item wdt:P2 wd:Q11211. ?item wikibase:statements ?outcoming . ?item wikibase:sitelinks ?sitelinks . { SELECT (count(?s) AS ?incoming) ?item WHERE { ?item wdt:P2 wd:Q11211. ?s ?p ?item . [] wikibase:directClaim ?p } GROUP BY ?item } SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }. } ORDER BY DESC (?incoming)
Federated Queries
Federated queries are those that gather data from multiple data sources. Factgrid can request data from Wikidata and DBpedia.
Get Factgrid IDs that don't have a Wikidata QID, but can be found in Wikidata via its Factgrid ID
#defaultView:Table # Prefixes PREFIX fg: <https://database.factgrid.de/entity/> PREFIX fgt: <https://database.factgrid.de/prop/direct/> PREFIX wdt: <http://www.wikidata.org/prop/direct/> PREFIX wd: <http://www.wikidata.org/entity/> PREFIX wikibase: <http://wikiba.se/ontology#> PREFIX bd: <http://www.bigdata.com/rdf#> PREFIX schema: <http://schema.org/> SELECT DISTINCT ?fg_item ?fg_itemLabel ?fg_item_as_string ?wd_item where { # labels from Factgrid SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } # maybe filter to prevent timeout #?fg_item fgt:P131 fg:Q400012. # get those Factgrid IDs that don't have a Wikidata QID FILTER NOT EXISTS { ?link schema:about ?fg_item . ?link schema:isPartOf <https://www.wikidata.org/> . #Targeting Wikipedia language where subjects has no article. } # Convert Factgrid ID from IRI to string BIND(REPLACE(STR(?fg_item), "https://database.factgrid.de/entity/", "") as ?fg_item_as_string) # get those Items from Wikidata that have that corresponding Factgrid ID SERVICE <https://query.wikidata.org/sparql> { ?wd_item wdt:P8168 ?fg_item_as_string } }
Wishful thinking
- A map of all places a Person has been, using (also) the information from sender's and receiver's places
- visualisations quest on phabricator