How to get halfbrothers/sisters in SPARQL?
I have this RDF dataset with a family that has the hasParent realtionship. To search for all brother and sisters pairs I have the following query:
SELECT DISTINCT ?name1 ?name2
WHERE {
?subject1 oranje:hasParent ?object .
?subject2 oranje:hasParent ?object .
?subject1 rdfs:label ?name1 .
?subject2 rdfs:label ?name2 .
FILTER (?subject1 != ?subject2)
}
However, How do I get all the halfbrother/sisters pair? This means: brothers and sisters that have only one parent in common.
Edit: maybe important, the d开发者_如何学Goataset also contains the marriedWith relationship
Does this work for you?
SELECT DISTINCT ?name1 ?name2
WHERE {
?child1 oranje:hasParent ?parent , ?otherparent1 .
?child2 oranje:hasParent ?parent , ?otherparent2 .
?child1 rdfs:label ?name1 .
?child2 rdfs:label ?name2 .
FILTER (?child1 != ?child2)
FILTER (?otherparent1 != ?parent)
FILTER (?otherparent2 != ?parent)
FILTER (?otherparent1 != ?otherparent2)
}
精彩评论