Using IN clause within FILTER clause, in SPARQL query
Asked Answered
T

1

6

I'm new to SPARQL. I'm trying to run this query --

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
SELECT * FROM <http://purl.obolibrary.org/obo/merged/DOID> WHERE {
    ?nodeID owl:annotatedSource <http://purl.obolibrary.org/obo/DOID_11330>.
    #?nodeID rdf:type owl:Annotation.
    ?nodeID owl:annotatedProperty ?annotatedProperty.
    ?nodeID owl:annotatedTarget ?annotatedTarget.
    ?nodeID ?aaProperty ?aaPropertyTarget.
    OPTIONAL {?annotatedProperty rdfs:label ?annotatedPropertyLabel}.
    OPTIONAL {?aaProperty rdfs:label ?aaPropertyLabel}.
    FILTER (isLiteral(?annotatedTarget)).   
    FILTER (not exists {?aaProperty in(owl:annotatedSource, rdf:type, owl:annotatedProperty, owl:annotatedTarget)
    })}

-- but I got this error and I don't know what to do. Please help me. Thanks.

Encountered " "in" "in "" at line 13, column 41.
Was expecting one of:
    <IRIref> ...
    <PNAME_NS> ...
    <PNAME_LN> ...
    <VAR1> ...
    <VAR2> ...
    "a" ...
    "distinct" ...
    "multi" ...
    "shortest" ...
    "(" ...
    "!" ...
    "^" ...
Tailback answered 8/8, 2016 at 9:8 Comment(1)
What are you trying to o with the not exist? Are you trying to say that your value is not one of the list that you've mentioned?Scudo
K
6

NOT EXISTS expects a graph pattern. What you want is probably (just guessed)

PREFIX  rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX  owl:  <http://www.w3.org/2002/07/owl#>
PREFIX  rdf:  <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT  *
FROM <http://purl.obolibrary.org/obo/merged/DOID>
WHERE
  { ?nodeID owl:annotatedSource <http://purl.obolibrary.org/obo/DOID_11330> .
    ?nodeID owl:annotatedProperty ?annotatedProperty .
    ?nodeID owl:annotatedTarget ?annotatedTarget .
    ?nodeID ?aaProperty ?aaPropertyTarget
    OPTIONAL
      { ?annotatedProperty rdfs:label ?annotatedPropertyLabel}
    OPTIONAL
      { ?aaProperty rdfs:label ?aaPropertyLabel}
    FILTER isLiteral(?annotatedTarget)
    FILTER ( ?aaProperty NOT IN (owl:annotatedSource, rdf:type, owl:annotatedProperty, owl:annotatedTarget) )
  }
Kalidasa answered 8/8, 2016 at 10:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.