Project:SPARQL/examples: Difference between revisions

Line 2,384: Line 2,384:
group by ?item ?itemLabel  ?location ?locationLabel
group by ?item ?itemLabel  ?location ?locationLabel
ORDER BY ?item ?distance
ORDER BY ?item ?distance
</sparql>
=== Working with property paths: instance of [CAVEAT: experimental, probably wrong]===
<sparql tryit="1">
# an attempt to adapt the query above following paths for locations of organisations for (more complex) instance of
# ref https://stackoverflow.com/questions/61984052/wikidata-get-the-full-subhierachy-of-one-class-as-well-as-all-nodes
# distance is in the right *order* so it should be usable for some purposes, but the starting number = number of levels rather than 1. also jumps if there are siblings somewhere along the path.
PREFIX bnwd: <https://beyond-notability.wikibase.cloud/entity/>
PREFIX bnwds: <https://beyond-notability.wikibase.cloud/entity/statement/>
PREFIX bnwdv: <https://beyond-notability.wikibase.cloud/value/>
PREFIX bnwdt: <https://beyond-notability.wikibase.cloud/prop/direct/>
PREFIX bnp: <https://beyond-notability.wikibase.cloud/prop/>
PREFIX bnps: <https://beyond-notability.wikibase.cloud/prop/statement/>
PREFIX bnpq: <https://beyond-notability.wikibase.cloud/prop/qualifier/>
SELECT ?item ?itemLabel ?instance_of ?instance_ofLabel  (count(?item) as ?distance)
WHERE { 
  ?item bnwdt:P12* ?tmp .  # instance of anything.
  ?tmp bnwdt:P12+ ?instance_of . # P2=30. P2+=34
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en-gb, en". }
}
group by ?item ?itemLabel  ?instance_of ?instance_ofLabel
ORDER BY ?item ?distance
</sparql>
</sparql>


579

edits