5

Following sparql query will give the persons who are dead.

select distinct ?item{
?item <http://freebase.com/ns/common/topic/notable_types> <http://freebase.com/ns/people/person> .
?item <http://freebase.com/ns/people/deceased_person/date_of_death> ?y .
}

I want to get all the persons who are alive. How to express this in SPARQL syntax? Its more like asking, get me all the nodes which doesn't have a specific edge. Is it possible in SPARQL?

Thanks in Advance. Any help is appreciated.

nizam.sp
  • 4,002
  • 5
  • 39
  • 63

2 Answers2

3

Sure. You can use this construction:

SELECT DISTINCT ?item {
    ?item <http://freebase.com/ns/common/topic/notable_types> <http://freebase.com/ns/people/person> .
    OPTIONAL {?item <http://freebase.com/ns/people/deceased_person/date_of_death> ?y}
    FILTER (!BOUND(?y))
}
Lev Khomich
  • 2,247
  • 14
  • 18
  • 4
    Note that this will not give you only people who are alive. It only gives you people who do not have a recorded date of death in freebase. – Antoine Zimmermann Dec 23 '12 at 09:07
3

In SPARQL 1.1

SELECT DISTINCT ?item {
    ?item <http://freebase.com/ns/common/topic/notable_types> <http://freebase.com/ns/people/person> .
    FILTER NOT EXISTS { ?item <http://freebase.com/ns/people/deceased_person/date_of_death> ?y}
}
AndyS
  • 16,345
  • 17
  • 21
  • This also works! Unfortunately I couldn't accept two answers. So, given an upvote. Thanks a lot. Where can I find the documentation of all the possible things on SPARQL and SPARQL 1.1 ? Please point me if there are any nice tutorials. – nizam.sp Dec 16 '12 at 17:24