FactGrid:Sample queries

From FactGrid
Revision as of 16:14, 14 July 2022 by Katharina Brunner (talk | contribs) (→‎SPARQL patterns for reuse)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search


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

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





  • no functional query yet, but a first attempt is here, modeled after the "academic tree" graph in Scholia's author aspect




Grammatically intricate searches

Wimimedia sources

Statements with sources

Get information from connected items

Search for specific Qualifiers on a Statement

You already know one related value

  • 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:

  ?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)

State all statements that are made on an item


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

  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

Try it

 # 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
     ?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


  1. Adapted from here.