You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by Adeeb Noor <ad...@colorado.edu> on 2014/03/11 20:37:18 UTC
Removing String with SparqlUpdates
Hi All:
I have a question that is really driving me crazy:
-------------------------------------------------------------------------------------------
| s | Label1 | Label2
|
===========================================================================================
| ddidd:C1412333 | "ALDH1A1 gene" | "ALDEHYDE DEHYDROGENASE 1"
|
| ddidd:C1412335 | "ALDH2 gene" | "ALDEHYDE DEHYDROGENASE 2"
|
This is a result of query that asks to give a subject with more than one
label.
SELECT DISTINCT ?s
WHERE {
?s ddids:label ?label1.
?s ddids:label ?label2.
FILTER (?label1 != ?label2 ) .
}
I have this a lot one my dataset due to the integration. FYI, there is no
more than two labels for each subject
I was trying to keep one label and remove the other using a sparqlupdate.
For example by doing:
DELETE { ddidd:C1412333 ddids:label ?label2 .
ddidd:C1412333 ddids:label ?label1 .}
INSERT { ddidd:C1412333 ddids:label ?label1 . }
WHERE {
ddidd:C1412333 ddids:label ?label1 .
ddidd:C1412333 ddids:label ?label2.
FILTER (?label1 != ?label2 )} ;
However, after querying the ddidd:C1412333 I still got two labels. Am I
doing something wrong.
Thanks
--
Adeeb Noor
Ph.D. Candidate
Dept of Computer Science
University of Colorado at Boulder
Cell: 571-484-3303
Email: Adeeb.noor@colorado.edu
Re: Removing String with SparqlUpdates
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Tue, Mar 11, 2014 at 5:17 PM, Adeeb Noor <ad...@colorado.edu> 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/
Re: Removing String with SparqlUpdates
Posted by Adeeb Noor <ad...@colorado.edu>.
Thanks Andy and Joshua, I tried ?label1 < ?label2 and it worked.
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.
thanks
On Tue, Mar 11, 2014 at 1:58 PM, Joshua TAYLOR <jo...@gmail.com>wrote:
> On Tue, Mar 11, 2014 at 3:37 PM, Adeeb Noor <ad...@colorado.edu>
> wrote:
> >
> > I was trying to keep one label and remove the other using a sparqlupdate.
> > For example by doing:
> >
> > DELETE { ddidd:C1412333 ddids:label ?label2 .
> >
> > ddidd:C1412333 ddids:label ?label1 .}
> >
> > INSERT { ddidd:C1412333 ddids:label ?label1 . }
> >
> > WHERE {
> >
> > ddidd:C1412333 ddids:label ?label1 .
> >
> > ddidd:C1412333 ddids:label ?label2.
> >
> > FILTER (?label1 != ?label2 )} ;
> >
> >
> > However, after querying the ddidd:C1412333 I still got two labels. Am I
> > doing something wrong.
>
> I think your update is doing what's supposed to. After all, if you have
>
> :x :label "a", "b" .
>
> You'll match twice: once with label1 and label2 bound to "a" and "b",
> and once with them bound to "b" and "a". I think you need some policy
> for _which_ of the two labels to delete. E.g., instead of filter(
> ?label1 != ?label2 ), which is symmetric, how about filter( ?label1 <
> ?label2 )?
>
> --
> Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
>
--
Adeeb Noor
Ph.D. Candidate
Dept of Computer Science
University of Colorado at Boulder
Cell: 571-484-3303
Email: Adeeb.noor@colorado.edu
Re: Removing String with SparqlUpdates
Posted by Joshua TAYLOR <jo...@gmail.com>.
On Tue, Mar 11, 2014 at 3:37 PM, Adeeb Noor <ad...@colorado.edu> wrote:
>
> I was trying to keep one label and remove the other using a sparqlupdate.
> For example by doing:
>
> DELETE { ddidd:C1412333 ddids:label ?label2 .
>
> ddidd:C1412333 ddids:label ?label1 .}
>
> INSERT { ddidd:C1412333 ddids:label ?label1 . }
>
> WHERE {
>
> ddidd:C1412333 ddids:label ?label1 .
>
> ddidd:C1412333 ddids:label ?label2.
>
> FILTER (?label1 != ?label2 )} ;
>
>
> However, after querying the ddidd:C1412333 I still got two labels. Am I
> doing something wrong.
I think your update is doing what's supposed to. After all, if you have
:x :label "a", "b" .
You'll match twice: once with label1 and label2 bound to "a" and "b",
and once with them bound to "b" and "a". I think you need some policy
for _which_ of the two labels to delete. E.g., instead of filter(
?label1 != ?label2 ), which is symmetric, how about filter( ?label1 <
?label2 )?
--
Joshua Taylor, http://www.cs.rpi.edu/~tayloj/
Re: Removing String with SparqlUpdates
Posted by Andy Seaborne <an...@apache.org>.
Consider the output of the query:
SELECT *
WHERE {
?s ddids:label ?label1.
?s ddids:label ?label2.
FILTER (?label1 != ?label2 ) .
}
then the query:
SELECT *
WHERE {
?s ddids:label ?label1.
?s ddids:label ?label2.
FILTER (?label1 < ?label2 ) .
}
Andy
On 11/03/14 19:37, Adeeb Noor wrote:
> Hi All:
>
> I have a question that is really driving me crazy:
>
> -------------------------------------------------------------------------------------------
>
> | s | Label1 | Label2
> |
>
> ===========================================================================================
>
> | ddidd:C1412333 | "ALDH1A1 gene" | "ALDEHYDE DEHYDROGENASE 1"
> |
>
> | ddidd:C1412335 | "ALDH2 gene" | "ALDEHYDE DEHYDROGENASE 2"
> |
>
> This is a result of query that asks to give a subject with more than one
> label.
>
> SELECT DISTINCT ?s
Different query.
>
> WHERE {
>
> ?s ddids:label ?label1.
>
> ?s ddids:label ?label2.
>
> FILTER (?label1 != ?label2 ) .
>
> }
>
> I have this a lot one my dataset due to the integration. FYI, there is no
> more than two labels for each subject
>
> I was trying to keep one label and remove the other using a sparqlupdate.
> For example by doing:
>
> DELETE { ddidd:C1412333 ddids:label ?label2 .
>
> ddidd:C1412333 ddids:label ?label1 .}
>
> INSERT { ddidd:C1412333 ddids:label ?label1 . }
>
> WHERE {
>
> ddidd:C1412333 ddids:label ?label1 .
>
> ddidd:C1412333 ddids:label ?label2.
>
> FILTER (?label1 != ?label2 )} ;
>
>
> However, after querying the ddidd:C1412333 I still got two labels. Am I
> doing something wrong.
>
>
> Thanks
>