Search code examples
filtersparqlrdfdbpedia

sparql filter won't work


I want to get all players from a football club and filter those out that are from Germany, I know that it is possible without the filter option, but I'm new to SPARQL and it seems that i don't understand how to use the filter option in that case, so I would be glad if someone could tell a way how to get that working.

SELECT distinct ?player WHERE {
?player a <http://dbpedia.org/ontology/SoccerPlayer>. 
?player <http://dbpedia.org/property/currentclub> <http://dbpedia.org/resource/Hertha_BSC>. 
optional {?subject <http://dbpedia.org/ontology/birthPlace>/<http://dbpedia.org/ontology/country> ?<http://dbpedia.org/resource/Germany>. }
filter (!bound(?subject)).
} 
ORDER BY ASC(?player)

best regards Adrian


Solution

  • I hope you are looking for something like this:

    SELECT distinct ?player WHERE {
        ?player a dbo:SoccerPlayer . 
        ?player dbp:currentclub dbr:Hertha_BSC . 
        ?player dbo:birthPlace/dbo:country? ?country .
        FILTER (?country = dbr:Germany)
        } 
    ORDER BY ASC(?player)
    

    Or this:

    SELECT distinct ?player WHERE {
        ?player a dbo:SoccerPlayer . 
        ?player dbp:currentclub dbr:Hertha_BSC . 
        ?player dbo:birthPlace/dbo:country? ?country .
        FILTER (?country in (dbr:Germany))
        } 
    ORDER BY ASC(?player)
    

    Or even this:

    SELECT distinct ?player WHERE {
        ?player a dbo:SoccerPlayer . 
        ?player dbp:currentclub ?club . 
        ?player dbo:birthPlace/dbo:country? ?country .
        VALUES (?club ?country) { (dbr:Hertha_BSC dbr:Germany) }
        } 
    ORDER BY ASC(?player)