0

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.

Chavi
  • 31
  • 1
  • 4
  • your request is too vague as you didn't provide a proper SPARQL query. But you usually check if there is no value with the binding of your current value. like `?s :p1 ?obj filter not exists {?s :p2 ?val filter (?val = ?obj)}` - (or simply use ` filter not exists {?s :p2 ?obj}` -can't give better advice without seeing query and sample data – UninformedUser Aug 02 '20 at 09:51
  • Thank you. I will try that too. In the meantime I solved the issue by using 2 Select. In one I counted all values in the other I filtered the values that are different and counted them. Then I used HAVING to check if the 2 counts are the same. – Chavi Aug 02 '20 at 19:02

1 Answers1

0

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)
Chavi
  • 31
  • 1
  • 4
  • are you sure this is correct? I mean, you're not comparing the types itself but just the number of types. for me, this sounds weird. Also, shouldn't you use `DISTINCT` in the `COUNT` - I mean, there could be duplicates or not? But maybe I just don't understand the dataset which I don't know – UninformedUser Aug 02 '20 at 21:00
  • I also do not understand what your current query is supposed to do. Can you explain this please? – UninformedUser Aug 02 '20 at 21:00