On Wed, May 14, 2014 at 10:52 AM, Leo Papa <[email protected]> wrote:
> I want to achieve a query result that CONSTRUCT the graph/model constraining
> on the CODEs in g2 that are not in g1, hence:
> CONSTRUCT { ?codeG2 ?p ?x . ?ce2 ?r ?y . }
> WHERE
> { GRAPH <http://example.org/g1>
> { ?codeG1 <http://example.org/code/classifies> ?ce1}
> GRAPH <http://example.org/g2>
> { ?codeG2 <http://example.org/code/classifies> ?ce2 .
> ?ce2 ?r ?y. ?codeG2 ?p ?x }
> FILTER(?codeG2 != ?codeG1)
> }
You're not asking for things that are in G2 that aren't in G1, though.
You're asking for pairs of things from G1 and G2 that aren't the
same. Consider two sets:
S1 : { a, b, c }
S2 : { a, b, d }
If you ask for
{ x in S1 } joined wth { y in S2, x != y }
you'd get the results
a b
a d
b a
b d
c a
c b
c d
You'd get results where the second value is present in the first set,
because you're not asking for second values that aren't present in the
first set; you're asking for pairs where the elements aren't the
same. It's essentially taking the cartesian product, and then
removing individual pairs based on some criteria of the individual
pair, whereas a constraint like "this element doesn't exist in the
other set" requires looking at more than just the pair.
If you want to select data from one graph where there's no counterpart
in the other, you'd want something like this:
# take data from this A
# except when the ?s is a
# subject in B, too.
construct { ?s ?p ?o }
where {
graph <A> { s ?p ?o }
filter not exists { graph <B> { ?s ?p2 ?o2 } }
}
//JT
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/