query-f1837ece776070eff20504908772a273
, recrusive) optimally like this: (P1647)subproperty of . Now I also need all subproperties ((P161)cast member which is only (P161)cast member (P371)presenter (P161)cast member (P725)voice actor (P161)cast member parent prop 07:32, 20 August 2022 (UTC)) talk (ShismaThank you : I renamed the variable ?item to ?property as I found it confusing to call a variable binding to properties for ?item.Shisma@
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX p: <http://www.wikidata.org/prop/>
SELECT DISTINCT ?prop ?parent
{
{
?property p:P1628/ps:P1628 <http://schema.org/actor>
} UNION {
?property p:P1628/ps:P1628 <https://schema.org/actor>
}
?property wikibase:propertyType wikibase:WikibaseItem .
?subproperty wdt:P1647 * ?property .
OPTIONAL { ?subproperty p:P1628 [ wikibase:rank ?rank ] }
BIND (REPLACE(STR(?subproperty), 'http://www.wikidata.org/entity/', '') AS ?prop)
BIND (IF(?property = ?subproperty, "", REPLACE(STR(?property), 'http://www.wikidata.org/entity/', '')) AS ?parent)
BIND (IF(?rank = wikibase:PreferredRank, 1, IF(?rank = wikibase:NormalRank, 2, 3)) AS ?order)
}
ORDER BY ?order
Query found at
graph TD
classDef projected fill:lightgreen;
classDef literal fill:orange;
classDef iri fill:yellow;
v7("?order")
v6("?parent"):::projected
v5("?prop"):::projected
v2("?property")
v4("?rank")
v3("?subproperty")
a1((" "))
a2((" "))
a3((" "))
c4([https://schema.org/actor]):::iri
c3([http://schema.org/actor]):::iri
c6(["wikibase:WikibaseItem"]):::iri
subgraph union0[" Union "]
subgraph union0l[" "]
style union0l fill:#abf,stroke-dasharray: 3 3;
v2 --"p:P1628"--> a2
a2 --"p:statement/P1628"--> c4
end
subgraph union0r[" "]
style union0r fill:#abf,stroke-dasharray: 3 3;
v2 --"p:P1628"--> a1
a1 --"p:statement/P1628"--> c3
end
union0r <== or ==> union0l
end
v2 --"wikibase:propertyType"--> c6
v3 --"p:direct/P1647"--> v2
subgraph optional0["(optional)"]
style optional0 fill:#bbf,stroke-dasharray: 5 5;
a3 -."wikibase:rank".-> v4
v3 --"p:P1628"--> a3
end
bind0[/"replace(str(?subproperty),'http://www.wikidata.org/entity/','')"/]
v3 --o bind0
bind0 --as--o v5
bind1[/"if(?property = ?subproperty,'',replace(str(?property),'http://www.wikidata.org/entity/',''))"/]
v2 --o bind1
v3 --o bind1
bind1 --as--o v6
bind2[/"if(?rank = 'wikibase:PreferredRank','1^^xsd:integer',if(?rank = 'wikibase:NormalRank','2^^xsd:integer','3^^xsd:integer'))"/]
v4 --o bind2
bind2 --as--o v7