query-6e72eff03e083c99f626a73a28ab479d
Traversing graph of "owned by" propertiesHi! pointing to the starting entity. Ideally the query should recursively execute the same traversing on the found entities, crawling a graph of ownership relations. (P127)owned by points to and also looks for entities that have (P127)owned by I am trying to implement a query that, starting from an entity, looks at the objects its . If I don't manage to have the query traverse the graph on its own, I could reproduce the traversing by repeating the query on its results until no parents nor children are found. (Q3295867)The Coca-Cola Company and the entities that are directly owned by (Q3295867)The Coca-Cola Company I have managed to get started only with a query that looks at the entities that directly own So, here are the questions: 1. Is there a way to avoid repeating the query on the results previously obtained from the same query to traverse the ownership graph? 2. Right now I have implemented this, which returns wrong values for the ?ownerProportion variable. It repeats the values for Berkshire Hathaway and The Vanguard Group twice. ?ownerProportion would be the proportion of shares owned by a company.
Use at
- https://query.wikidata.org/sparql
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
SELECT DISTINCT ?owner ?ownerProportion ?ownerLabel ?owned ?ownedLabel WHERE {
{
wd:Q3295867 wdt:P127 ?owner .
OPTIONAL {
wd:Q3295867 p:P127 ?statement1 .
?statement1 pq:P1107 ?ownerProportion .
}
} UNION {
?owned wdt:P127 wd:Q3295867 .
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en,[AUTO_LANGUAGE]". }
}