Question

I am using rdflib in Python and running SPARQL SELECT queries to get relevant data.

It is very easy to filter data for some criteria using FILTER command like FILTER regex(?pname,'"""+samplepersnalisedexpertise+"""',"i") described below, but if I have to select data that does not matches, then how do we need to use FILTER? I have tried using FILTER (?personuri != '"""+imURI+"""') below but that does not work.

exprtppl=  GraphR.query(""" 
PREFIX foaf: <http://xmlns.com/foaf/0.1/>         
PREFIX owl: <http://www.w3.org/2002/07/owl#>      
PREFIX dc: <http://purl.org/dc/elements/1.1/>         
PREFIX bibo: <http://purl.org/ontology/bibo/>

SELECT ?nname 
{ 
    ?puburi dc:title ?pname. 
    FILTER regex(?pname,'"""+samplepersnalisedexpertise+"""',"i")
    ?personuri foaf:publications ?puburi.
    ?personuri foaf:nick ?nname
    FILTER (?personuri != '"""+imURI+"""')

 }""")

Can anyone of you please help out for solution. Thanks in Advance.

Was it helpful?

Solution

You are trying to compare with a URI value, which should not be surrounded by quotes, but by fish hooks:

FILTER(?personuri != <"""+imURI+""">)

By the way, the suggestion @morphyn gives above (using the str() function) will also work, but is less efficient.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top