Does SPARQL return data only if found the whole pattern?

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Does SPARQL return data only if found the whole pattern?

emir
Consider a query:
SELECT DISTINCT ?A ?B ?C {
    ?A a ClassA .
    ?B a ClassB .
    ?C a ClassC .
   
    ?A ns:has_brother ?C;
        ns:has_sister ?B .

    ?A rdfs:label "John" .
    ?B rdfs:label "Marry" .
    ?C rdfs:label "Michael" .
}

Suppose, it is true only that John has a sister Marry but doesn't have a brother Michael. If my understanding of SPARQL is correct, it won't return anything. Is there a way to make it return A, C and blank for B?

Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Does SPARQL return data only if found the whole pattern?

Jiba
Administrator
Hi,

I think you can achieve that by using an OPTIONAL block:

OPTIONAL {
    ?A ns:has_sister ?B .
    ?B rdfs:label "Marry" .
}

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Does SPARQL return data only if found the whole pattern?

emir
Okay, thank you! I will give it a try!