Search code examples
sparqlrdfsemantic-webowlontology

how to exclude one instance from SPARQL query result


I have a query to get some similar instances for a specific instance, which is owbes:Dies_Irae instance. This is the query:

CONSTRUCT { ?recommendable0 ?predicate0 ?similarity0 } WHERE {
  ?recommendable0 ?predicate0 ?object0.
  owbes:Dies_Irae ?predicate0 ?object0.
  ?predicate0 owbes:hasSimilarityValue ?similarity0.
  ?recommendable0 rdf:type ?someType.
  ?someType rdfs:subClassOf owbes:Recommendable.
}

It works fine, I get in the results what I'm supposed to. However, I also get the same instance owbes:Dies_Irae. Is there a way to exclude it from the result?

Well, I'm sure there is. I tried to search, I found that there is a filter, I tried to use it, but no succeed. This is the filter that I apply FILTER (?recmmendable0 != owbes:Dies_Irae)

I also tried to check if both of them have the same rdf:about but it didn't work.

Here you go the result:

<http://www.welovethesemanticweb.com/recommendation-systems#Requiem:_Sequentia>
        recommendation-systems:hasArtist
                "0.4"^^xsd:double .

recommendation-systems:Le_nozze_di_Figaro
        recommendation-systems:hasArtist
                "0.4"^^xsd:double .

recommendation-systems:Dies_Irae
        recommendation-systems:hasArtist
                "0.4"^^xsd:double .

as you see, the last instance is the one that I'd like to exclude


Solution

  • FILTER (?recmmendable0 != owbes:Dies_Irae)
    

    You didn't spell recommendable0 correctly in your filter. Since the variable isn't used anywhere else, it never has a value, so the filter doesn't have anything to compare.