FactGrid:Sample queries: Difference between revisions
Jump to navigation
Jump to search
Olaf Simons (talk | contribs) |
No edit summary |
||
Line 142: | Line 142: | ||
?item wdt:P131 wd:Q400012 . | ?item wdt:P131 wd:Q400012 . | ||
?item wikibase:statements ?statementcount. | ?item wikibase:statements ?statementcount. | ||
} | |||
== 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 === | |||
[https://query.wikidata.org/#%20%20%23defaultView%3ATable%0A%0A%20%20%23%20Prefixes%0A%20%20PREFIX%20fg%3A%20%3Chttps%3A%2F%2Fdatabase.factgrid.de%2Fentity%2F%3E%0A%20%20PREFIX%20fgt%3A%20%3Chttps%3A%2F%2Fdatabase.factgrid.de%2Fprop%2Fdirect%2F%3E%0A%20%20PREFIX%20wdt%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fprop%2Fdirect%2F%3E%0A%20%20PREFIX%20wd%3A%20%3Chttp%3A%2F%2Fwww.wikidata.org%2Fentity%2F%3E%0A%20%20PREFIX%20wikibase%3A%20%3Chttp%3A%2F%2Fwikiba.se%2Fontology%23%3E%0A%20%20PREFIX%20bd%3A%20%3Chttp%3A%2F%2Fwww.bigdata.com%2Frdf%23%3E%0A%20%20PREFIX%20schema%3A%20%3Chttp%3A%2F%2Fschema.org%2F%3E%0A%0A%20%20SELECT%20DISTINCT%20%3Ffg_item%20%3Ffg_itemLabel%20%3Ffg_item_as_string%20%3Fwd_item%20where%20%7B%0A%0A%20%20%20%20%23%20labels%20from%20Factgrid%0A%20%20%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%20%0A%20%20%20%20%23%20maybe%20filter%20to%20prevent%20timeout%0A%20%20%20%20%23%3Ffg_item%20fgt%3AP131%20fg%3AQ400012.%0A%20%20%20%20%23%20get%20those%20Factgrid%20IDs%20that%20don%27t%20have%20a%20Wikidata%20QID%0A%20%20%20%20FILTER%20NOT%20EXISTS%20%7B%0A%20%20%20%20%20%20%3Flink%20schema%3Aabout%20%3Ffg_item%20.%0A%20%20%20%20%20%20%3Flink%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fwww.wikidata.org%2F%3E%20.%20%23Targeting%20Wikipedia%20language%20where%20subjects%20has%20no%20article.%0A%20%20%20%20%7D%0A%20%20%20%20%23%20Convert%20Factgrid%20ID%20from%20IRI%20to%20string%0A%20%20%20%20BIND%28REPLACE%28STR%28%3Ffg_item%29%2C%20%22https%3A%2F%2Fdatabase.factgrid.de%2Fentity%2F%22%2C%20%22%22%29%20as%20%3Ffg_item_as_string%29%20%0A%20%20%20%20%23%20get%20those%20Items%20from%20Wikidata%20that%20have%20that%20corresponding%20Factgrid%20ID%0A%20%20%20%20SERVICE%20%3Chttps%3A%2F%2Fquery.wikidata.org%2Fsparql%3E%20%7B%0A%20%20%20%20%20%20%3Fwd_item%20wdt%3AP8168%20%3Ffg_item_as_string%0A%20%20%20%20%7D%0A%20%20%7D Try it] | |||
#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 | |||
} | |||
} | } | ||
Revision as of 14:49, 30 June 2022
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 a residents of place with basic personal information. Table
- Two Persons, when and where did they meet timeline
- All people with a FactGrid account by gender
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
Maps
Dots
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
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, modeled 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?
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.
Grammatically intricate searches
Wimimedia sources
Statements with sources
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
- 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)
- 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. # ?s is the the statement node ?st ps:P266 ?o. # that simulates the predicate ?st ?qualifier ?value. # this is an attribute (a qualifier) }
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
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. }
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