ralgrad
ralgrad

Reputation: 29

Is it possible to Filter Graphs in a way that they at most contain requested Data?

Let me start with an example query to explain my problem:

SELECT ?g ?s ?p ?o WHERE
{
  {GRAPH ?g
    {   ?s ?p ?o.
        OPTIONAL{ ?s
          ab:temperature ?temperature.}
      FILTER (?temperature = 20)
      FILTER NOT EXISTS {?s ab:person ?person}
    }
  }
}

This query gives me all graphs (in this case representing context data) that have a temperature of 20 but don't have a person associated. My problem is I want to query the graphs for certain optional properties but they shouldn't have any other properties. At the time of the query I only know the OPTIONAL part but I don't know which additional property might be there. Is there an easy way to do this with SPARQL or is that something that would be easier to check after I received the graph and converted it to an object which I can handle with my programm?

Upvotes: 0

Views: 49

Answers (1)

Jörn Hees
Jörn Hees

Reputation: 3428

If i understand your question correctly, you are searching for graphs that only have that subjects with some properties but not others. In that case i'd run something like this:

SELECT ?g ?s ?p ?o WHERE {
 GRAPH ?g {
  ?s ?p ?o.
  FILTER NOT EXISTS {
   ?s ?bad [] .
   FILTER (?bad NOT IN ( ab:temperature, ... ) )
  }
 }
}

Upvotes: 1

Related Questions