On Tue, Mar 11, 2014 at 5:17 PM, Adeeb Noor <[email protected]> wrote:
> However, I still do not understand why the ?label1 != ?label2 did not work.
> I know Joshua you explained it a bit but I would be so grateful if you guys
> can pointe me out to a tutorial that explains all different parameters.


If your data is

:x :label "a" .
:x :label "b" .

and you run a query like this:

select ?x ?l1 ?l2 where {
  ?x :label ?l1 .
  ?x :label ?l2 .
  filter( ?l1 != ?l2 )
}

you get *two* rows in the results:

n ?x ?l1 ?l2
-------------
1. :x "a" "b"
2. :x "b" "a"

So, if you're using an update like

delete {
  ?x :label ?l2 .
  ?x :label ?l1 .
}
insert {
  ?x :label ?l1
}
where {
  ?x :label ?l1 .
  ?x :label ?l2 .
  filter( ?l1 != ?l2 )
}
you'll do a delete and insert for each of the result rows.  For row
one, where l1 = "a" and l2 = "b" you do

delete { :x :label "a" . :x :label "b" }
insert { :x :label "a" }
For row two, where l1 = "b" and l2 = "a", you do

delete { :x :label "b" . :x :label "a" }
insert { :x :label "b" }

Since all of this gets executed, you've deleted the triples you wanted
to remove, but you've also inserted them all back in.  If you use
filter( ?l1 < ?l2 ) instead of filter( ?l1 != ?l2 ), then you only get
one row in the results

n ?x ?l1 ?l2
-------------
1. :x "a" "b"

and thus you only do

delete { :x :label "a" . :x :label "b" }
insert { :x :label "a" }

and end up with just one label.

As an aside, there's no reason to delete and insert the same triple,
so you really should just be using:

delete {
  ?x :label ?l2
}
where {
  ?x :label ?l1, ?l2 .
  filter( ?l1 < ?l2 )
}

//JT

-- 
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/

Reply via email to