Query/Examples

From Wikibase
Jump to navigation Jump to search

Example data queries that visualize the data model

Overview of all classes and their subclasses

#defaultView:Graph 

SELECT Distinct ?classes ?classesLabel ?subclasses ?subclassesLabel  WHERE {
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  
  {?classes owl:equivalentClass ?x.} Union
  {?subclasses tibt:P2 ?classes.}
}

Overview of types of of human-made objects and instances

#defaultView:Tree

SELECT ?class ?classLabel ?type ?typeLabel ?item ?itemLabel
WHERE
{  
  VALUES ?class {tib:Q6}
  ?item tibt:P1 ?class.
  ?item tibt:P97 ?type.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Overview of types of conceptual objects and instances

#defaultView:Tree

SELECT ?class ?classLabel ?type ?typeLabel ?item ?itemLabel
WHERE
{  
  VALUES ?class {tib:Q17}
  ?item tibt:P1 ?class.
  ?item tibt:P97 ?type.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Example data queries that showcase items from the case study

All paintings from the cycle "Belagerungsszenen des Langen Türkenkriegs" with some properties

PREFIX tib: <https://wikibase.semantic-kompakkt.de/entity/>
PREFIX tibt: <https://wikibase.semantic-kompakkt.de/prop/direct/>
PREFIX tibp: <https://wikibase.semantic-kompakkt.de/prop/>
PREFIX tibps: <https://wikibase.semantic-kompakkt.de/prop/statement/>
PREFIX tibpq: <https://wikibase.semantic-kompakkt.de/prop/qualifier/>
PREFIX tibpqv: <https://wikibase.semantic-kompakkt.de/prop/qualifier/value/>

#All paintings from "Belagerungsszenen des Langen Türkenkriegs"

SELECT ?item ?itemLabel ?creationDateStart ?creationDateEnd ?inscription ?materialLabel ?techniqueLabel
WHERE { 
    ?item tibt:P6 tib:Q376.
    OPTIONAL { ?item tibp:P8 [ tibps:P8 tib:Q25; tibpqv:P10 [wikibase:timePrecision "9"^^xsd:integer ; wikibase:timeValue ?creationDateStart ] ]. }
    OPTIONAL { ?item tibp:P8 [ tibps:P8 tib:Q25; tibpqv:P11 [wikibase:timePrecision "9"^^xsd:integer ; wikibase:timeValue ?creationDateEnd ] ]. }
    OPTIONAL { ?item tibt:P25 ?inscription. }
    OPTIONAL { ?item tibt:P22 ?material. }
    OPTIONAL {  ?item tibt:P65 ?technique. }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
}

Items that share an Iconclass notation

#defaultView:Graph

SELECT ?item1 ?item1Label  ?iconclassLabel ?iconclass ?rgb ?rgb2
WHERE
{
  ?item1 tibt:P64 ?iconclass.
  ?item2 tibt:P64 ?iconclass.
  BIND('D88888' as ?rgb)
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  FILTER(?item1 != ?item2) .
}

Example federated queries

Simple query to get more information about Weikersheim castle (via owl:sameAs method)

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wdqs: <https://query.wikidata.org/sparql>

SELECT ?weikersheim ?weikersheimLabel ?VIAF ?image
WHERE{
?weikersheim tibt:P97 tib:Q201.
?weikersheim owl:sameAs ?WDMatch. 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  SERVICE wdqs: {
    ?WDMatch wdt:P214 ?VIAF.
    ?WDMatch wdt:P18 ?image
  }
}


Simple query to get more information about Weikersheim castle (via GND external ID method)

PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wdqs: <https://query.wikidata.org/sparql>

SELECT ?weikersheim ?weikersheimLabel ?GNDMatch ?image
WHERE{
?weikersheim tibt:P97 tib:Q201.
?weikersheim tibt:P102 ?GNDMatch. 
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
  SERVICE wdqs: {
    ?WDMatch wdt:P227 ?GNDMatch.
    ?WDMatch wdt:P18 ?image
  }
}

Castles of Renaissance architectural style within 100km of Weikersheim castle

#defaultView:Map

# Find all castles in the Wikibase; look on Wikidata for other renaissance castles nearby
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wdqs: <https://query.wikidata.org/sparql>

SELECT  ?castle ?castleLabel ?location ?image
WHERE {
  #Find all castles and their coordinates
  ?item tibt:P97 tib:Q201.
  ?item tibt:P37 ?coordinates.
  
  #Query wikidata
  SERVICE wdqs: {
    
    #Find castles with renaissance architectural style
    ?castle wdt:P31 wd:Q751876.
    ?castle wdt:P149 wd:Q236122.
    
    #Look for those castles in a radius of 100km around our castle
    SERVICE wikibase:around { 
      ?castle wdt:P625 ?location . 
      bd:serviceParam wikibase:center ?coordinates . 
      bd:serviceParam wikibase:radius "100" . 
    }
    
    #Get labels from Wikidata
    ?castle rdfs:label ?castleLabel.
    OPTIONAL { ?castle wdt:P18 ?image. }
    FILTER((LANG(?castleLabel)) = "de")
  }
}