What the asterisk mean in this SPARQL query?
Asked Answered
W

2

4

What the asterisk mean in this SPARQL query?

SELECT ?uri ?type
WHERE{
    ?uri a ?type.
    ?type rdfs:subClassOf* example:Device.
}

Does it mean "subclass of a subclass"? Can I use it with other predicates?

Wintertime answered 8/5, 2017 at 3:0 Comment(3)
Ehm, a question from my side: Have you read my answer of your first question: #43827550 . There I showed you a link to SPARQL 1.1 Property Paths (w3.org/TR/sparql11-query/#propertypaths), right?Onassis
Yes. That reference is very good. Based on that, I think that the meaning is "subclass of a subclass". I'm just trying to confirm.Wintertime
No, p* is the transitive closure of the property p, in your case p = rdfs:subClassOfOnassis
C
8

An asterisk (*) after a path element means “zero or more of this element”.

If there are no other elements in the path, ?a something* ?b means that ?b might also just be ?a directly, with no path elements between them at all.

?item wdt:P31/wdt:P279* ?class.
# means:
?item wdt:P31 ?class
# or
?item wdt:P31/wdt:P279 ?class
# or
?item wdt:P31/wdt:P279/wdt:P279 ?class
# or
?item wdt:P31/wdt:P279/wdt:P279/wdt:P279 ?class

See here for more detailed answer.

Chilly answered 8/5, 2017 at 16:29 Comment(0)
A
3

The asterisk after a predicate means that you want to follow a property path with zero or more occurrences of rdfs:subClassOf.

Your phrase "subclass of a subclass" is about right, although I would say "subclasses of subclasses," because the * property path is recursive. As you can see from the technical document in AKSW's comment, there are several other property path operators that go in either direction, with or without a limit on the number of occerances (or depth.)

Here's a pretty good example from Marklogic... I think this should work within any 1.1 endpoint.

https://developer.marklogic.com/features/semantics/path-examples

Yes, property paths are applicable to any predicate/property, not just rdfs:subClassOf.

Anhanhalt answered 8/5, 2017 at 13:4 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.