delete a particular tag by name

6 views
Skip to first unread message

Matt O'Brien

unread,
Mar 12, 2018, 6:43:31 PM3/12/18
to bisque bioimage
Hi,

This works if I'd like to set a tag on some images, given I have a python list of their URIs:

for uri in uris:
    result = session.fetchxml(uri)
    images = factory.from_etree(result)
    for image in images.kids:
        print 'working on: ', image.uri 
        try:
            image.addTag(name='delete_me_someday', type=image.uri ,value='1')
            session.save(image)
            print '     success: ', image.uri 

        except BQCommError:
            print "     fail: ", image.uri


However, what if I want to delete these tags?

There is nothing like  image.removeTag like I would have hoped for...

Thanks,
Matt

Dmitry Fedorov

unread,
Mar 19, 2018, 12:54:32 PM3/19/18
to bisque-...@googlegroups.com
Hi Matt, 

If you have a list of tag URIs you might simply issue multiple DELETE requests to those tags. This will work although will create many requests. If these tags belong to different images there's not much else you can do.

Although if they do belong to the same image you could fetch a resource, remove tags of interest and the PUT the resource back effectively replacing it with your version. Which will remove all the tags deleted in your version. The only issue here might be in concurrent editing, if somebody else made changes to the document then your PUT will overwrite those.

It is easy to remove things using simply etree API, basically you can fetch a resource with  result = session.fetchxml(uri + "?view=deep") 
and then remove nodes form interest and later PUT the xml back. There's not exact reason to parse the document and get BQ objects out as you do in: images = factory.from_etree(result). Although if you need it for some reason you can simply remove a tag from the list of tags in that resource (.tags). Most important is not to forget the do a PUT at the end in order to replace the document.

The POST operation is defined as a merge/update and PUT and a replace.

-d



--
You received this message because you are subscribed to the Google Groups "bisque bioimage" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bisque-bioimage+unsubscribe@googlegroups.com.
To post to this group, send email to bisque-bioimage@googlegroups.com.
Visit this group at https://groups.google.com/group/bisque-bioimage.
For more options, visit https://groups.google.com/d/optout.



--
__________________________________

Dmitry Fedorov Levit <di...@dimin.net>
Web: http://www.dimin.net/
__________________________________

Center for Bio-Image Informatics:
  <http://www.bioimage.ucsb.edu/>

Vision Research Lab, Electrical and Computer Engineering:
  <http://vision.ece.ucsb.edu/>

University of California, Santa Barbara
_________________________________
Reply all
Reply to author
Forward
0 new messages