SPARQL - filter among different objects

588 Views Asked by At

I am new to SPARQL and I have a question how I can filter the cases where the value of the object is different from a set of values collected from different objects? I want to use the query as part of the SPARQL-SHACL.

I have no problem to access the value I want to check, but then somehow the check is done for a single value and not if it is in the list/series of values

example:

  • my variable ?value is 6
  • I want to check if ?value which is 6 does not equal to any of the values of object ?obj ?obj have single values for different triples (different subjects), e.g. 1 for one case, 2 for another, 3 for other,...

If I do FILTER (?value!=?obj) I get all cases where 6!=1 and so on I want to be able to do ?value NOT IN (?obj) where the ?obj is a list 1, 2, 3,.... I assume in that case I will get just one result that 6 is not found in the list.

So maybe 2 questions

  • is it possible to construct a list from ?obj as part of the query so that I could eventually use NOT IN?
  • Is there other way to solve this problem?

Thanks in advance.

1

There are 1 best solutions below

2
On

Thank you very much for the answer. I found a solution myself, but in case more efficient solutions are available I would be glad to know them.

SELECT  $this ?value (COUNT(?type) AS ?types) ?typesall
        WHERE {
    {
    SELECT $this (COUNT(?typeall) AS ?typesall)
    WHERE {
        ?nscpointsa ex:class.assend  $this .
        ?nscpointsa rdf:type ?typeall .
      }
    GROUP BY $this ?typesall
    }
    $this $PATH ?value .
    OPTIONAL {$this ex:class2.control ?contr}.
    $this ex:class3.control1 ?control1 .
    ?nscpoints ex:class.assend  $this .
    ?nscpoints rdf:type ?type .
    ?nscpoints ex:class.attr1 ?attr1 .  
    FILTER (bound(?contr) && ?control1=true && ?value!=?attr1) .
        }
  GROUP BY $this ?value ?types ?typesall
  HAVING(?types=?typesall)