query-6e72eff03e083c99f626a73a28ab479d

rq turtle/ttl

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

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]". } 
}

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v4("?owned"):::projected v1("?owner"):::projected v3("?ownerProportion"):::projected v2("?statement1") c1(["wd:Q3295867"]):::iri c6(["bd:serviceParam"]):::iri c8(["en,#91;AUTO_LANGUAGE#93;"]):::literal subgraph union0[" Union "] subgraph union0l[" "] style union0l fill:#abf,stroke-dasharray: 3 3; v4 --"p:direct/P127"--> c1 end subgraph union0r[" "] style union0r fill:#abf,stroke-dasharray: 3 3; c1 --"p:direct/P127"--> v1 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; c1 -."p:P127".-> v2 v2 --"p:qualifier/P1107"--> v3 end end union0r <== or ==> union0l end subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c6 --"wikibase:language"--> c8 end