What does slash mean in a SPARQL property path?
Asked Answered
D

2

12

In one of the samples for querying Wikidata, I found the following query, which includes p:P6/v:P6 in the line after SELECT. What does it mean?

PREFIX wd: <http://www.wikidata.org/entity/> 
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX v: <http://www.wikidata.org/prop/statement/>

SELECT ?p ?w ?l ?wl WHERE {
   wd:Q30 p:P6/v:P6 ?p .       #-- This line
   ?p wdt:P26 ?w .
   OPTIONAL  {  
     ?p rdfs:label ?l filter (lang(?l) = "en") . 
   }
   OPTIONAL {
     ?w rdfs:label ?wl filter (lang(?wl) = "en"). 
   }
 }
Diarchy answered 8/8, 2015 at 19:51 Comment(1)
Note that you should generally use langMatches to compare language tags, not =. E.g., langMatches(lang(?x), "en").Cordeiro
C
21

It's the SequencePath flavour of a SPARQL 1.1 property path.

wd:Q30 p:P6/v:P6 ?p .

means that there is a triple (wd:Q30, p:P6, ?x), and another triple (?x, v:P6, ?p), without an explicit need to write (or name) the intermediate node ?x. In other words, it says: "?p can be found by starting at wd:Q30, following property p:P6, and then property v:P6.

Carabineer answered 8/8, 2015 at 20:7 Comment(0)
M
0

Just to provide a clear live example with some intuitive context, one of the examples currently available on the Query Service is this which lists "Humans born in New York City":

#Humans born in New York City
#title: Humans born in New York City
SELECT DISTINCT ?item ?itemLabel ?itemDescription ?sitelinks
WHERE {
    ?item wdt:P31 wd:Q5;            # Any instance of a human
          wdt:P19/wdt:P131* wd:Q60; # Who was born in any value (eg. a hospital)
# that has the property of 'administrative area of' New York City or New York City itself.

# Note that using wdt:P19 wd:Q60;  # Who was born in New York City.
# Doesn't include humans with the birth place listed as a hospital
# or an administrative area or other location of New York City.

          wikibase:sitelinks ?sitelinks.

    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY DESC(?sitelinks)

So the line:

wdt:P19/wdt:P131* wd:Q60

breaks down as:

  • wdt:P19: place of birth
  • wdt:P131: located in the administrative territorial entity
  • wd:Q60: New York city

Therefore, we understand that it means:

(place of birth) is (located in the administrative territorial entity) of (New York city)

As a bonus, the * which is also explained at: What the asterisk mean in this SPARQL query? means: "do /wdt:P131" zero or more times. This way, we find all humans that are marked as born e.g. in either of:

  • New York city itself
  • a borough of New York city (/wdt:P131 once)
  • a hospital in a borough of New York city (/wdt:P131 twice)

Without * the query is equivalent to this one with an intermediate variable ?x:

SELECT DISTINCT ?item ?itemLabel ?itemDescription ?sitelinks
WHERE {
    ?item wdt:P31 wd:Q5;
          wdt:P19 ?x;
          wikibase:sitelinks ?sitelinks.
    ?x wdt:P131 wd:Q60
    SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}
ORDER BY DESC(?sitelinks)

TODO come up with the equivalent one with *.

Meetly answered 27/6 at 12:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.