Property paths

Property paths

The query construction that allows us to select items that belong to the same class makes use of property paths. Property paths are shorthand for writing down a path of properties between two items. 

To understand how this construction works, take a look at the graphic view of some information about the item Star Wars: Episode I – The Phantom Menace (Q165713):

Item Q165713 has a P31 (instance of) statement with “feature film” (Q24869) as its value. So the Item-Property-Value statement would be:

Q165713 – P31 – Q24869

The path between Q165713 and Q24869 is the simplest path: a single property.

Item Q24869 (feature film) has the property P279 (subclass of) with the value Q11424 (film). So the Item-Property-Value statement would be:

Q24869 – P279 – Q11424

The path between Q24869 and Q11424 is also just a single property.

Path elements can be put together with a forward slash (/). So a query statement that uses the construction wdt:P31/wdt:P279 denotes a property path between two items consisting of P31 (instance of) and P279 (subclass of).

However, if our pattern for matching would be:
?item wdt:P31/wdt:P279 wd:Q11424.
the query would match only items that are an instance of a subclass of film, meaning only items that have a path consisting of P31 and P279 to the item film (Q11424). Items whose P31 property has the value Q11424 would not be retrieved, because they do not match the construction pattern.

The construction wdt:P31/wdt:P279* on line 6 is shorthand for saying that there’s an “instance of” property and then any number of “subclass of” properties between ?item and the item “film” (Q11424).

If you remove the asterisk (*) on line 6 of the query above and run the query again you will see that the query does not retrieve those items that are themselves an instance of film (Q11424).
The asterisk (*) after the path element means “zero or more of this element”. Thus the matching pattern
?item wdt:P31/wdt:P279* wd:Q11424
could match:
?item wdt:P31 wd:Q11424.
?item wdt:P31/wdt:P279 wd:Q11424.
?item wdt:P31/wdt:P279/wdt:P279 wd:Q11424.
?item wdt:P31/wdt:P279/wdt:P279/wdt:P279 wd:Q11424.
and so on.

Skip to content