Study Vault Search notes, aliases and full text
Graph
ConceptADISAI-written · not yet proofread

Property Path

Also Property Paths

A property path is a pattern over predicates, written in the predicate position of a SPARQL query triple, that matches a whole path of edges from subject to object; `p1/p2` is an edge p1 followed by an edge p2, and `p*` is zero or more edges p.

Properties#

  • Sequence = hidden intermediate variable. ?s p1/p2 ?o matches the same (s,o)(s, o) as the two triples ?s p1 ?x . ?x p2 ?o, except that the intermediate node ?x gets no column in the result.
  • * has no fixed-size equivalent. A path of unbounded length can’t be written as a fixed number of triples, so * is needed for transitive relations such as “subclass of”.
  • Duplicates and DISTINCT. The lecture’s query yields one result per path. If a city is reachable from wd:Q515 via several paths, it appears several times, hence SELECT DISTINCT.
  • Typical Wikidata use. wdt:P31/wdt:P279* (instance of, then any number of subclass-of edges) finds all instances of a class including instances of its subclasses (Wikidata Prefix System).
  • Property paths also save typing for plain chains, e.g. ?building geo:hasGeometry/geo:asWKT ?wkt in the Spatial Join example.

Example#

Toy knowledge graph:

<Freiburg> <instance_of> <University_Town> .
<University_Town> <subclass_of> <Town> .
<Town> <subclass_of> <Settlement> .
<Ulm> <instance_of> <Town> .
SELECT ?x WHERE { ?x <instance_of>/<subclass_of>* <Settlement> . }
  • Freiburg: instance_of to University_Town, then 2 subclass_of edges.
  • Ulm: instance_of to Town, then 1 subclass_of edge.

With <instance_of> <Settlement> alone, the result would be empty.

Lecture query (Wikidata, Slide 17):

SELECT DISTINCT ?city ?name ?population WHERE {
  ?city wdt:P31/wdt:P279* wd:Q515 .   # instance of (a subclass of) city
  ?city wdt:P17 wd:Q183 .             # country: Germany
  ?city wdt:P1082 ?population .
  ?city rdfs:label ?name FILTER (LANG(?name) = "de")
}
ORDER BY DESC(?population)

Sources#

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only