Project:Secondary Type Query

From DiSSCo Modelling Framework
Revision as of 15:16, 30 August 2022 by Jgrieb (talk | contribs) (Include fetching contains relations from second-level parent class)
Jump to navigation Jump to search
# Attention: This can only get "contains" items/properties inherited from the parent class one the parent's parent class
# but not from classes higher in the hierarchy - hierarchy is not iterated
SELECT DISTINCT ?item ?conceptName ?itemLabel ?itemDescription ?example ?dataType ?min ?max ?mandatory WHERE {
 #the type to export is ImageObject but can also be applied to other types (change "wd:Q45")
 BIND(wd:Q45 as $type).


 #get all contains statements for this class and potentially from the parent class
 {?type wdt:P14?/p:P44 ?statement. }
 UNION {
  # get the parent class
  ?type wdt:P14 ?superclass .
  # get all contains statements for the parent class and the parent's parent class
  ?superclass wdt:P14?/p:P44 ?statement .
 } 
 ?statement ps:P44 ?item.
 OPTIONAL{
   ?statement pqv:P9/wikibase:quantityAmount ?mandatoryInternal.      
 }

 #additional optional properties
 OPTIONAL {?item wdt:P26 ?conceptName}
 OPTIONAL {?item wdt:P18 ?example}
 OPTIONAL {?item wdt:P10 ?dataType}
 OPTIONAL {?item wdt:P37 ?min}
 OPTIONAL {?item wdt:P38 ?max}
 BIND(IF(BOUND(?mandatoryInternal),?mandatoryInternal,"0") AS ?mandatory)
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }

}ORDER BY ?order