Batch Removal of Tags
Is there a way to batch remove tags that have that have not been automatically attached to bibliographic items? This appears to be the case when items are imported from database searches. I have deleted all the tags that were attached automatically via the dropdown menu but there are still several hundred that appear when asking Zotero to display all tags in the library. I am hoping to delete every tag in the library without having to delete each one individually.
You can disable automatic tagging of items in Zotero preferences.
Need to delete hundreds of tags that came with an RIS file I imported...thus not "automatic" tags.
Using Zotero standalone
#create list with all tags
all_tags = zot.everything(zot.tags())
#create a first subset of this list
tags_part1 = all_tags[:50]
#delete first 50 tags
zot.delete_tags(*tags_part1)
I then just updated the all_tags list after each deletion and repeated the process. It is not the nicest way to do it (you could also write function for it I guess) but I just wanted to get it done.
Hope that helps!
```
while len(tags_to_remove)>0:
tags = zot.everything(zot.tags())
tags_to_remove = list(set(tags).difference(tags_to_keep))
tags_to_remove_n = tags_to_remove[:min(len(tags_to_remove),50)]
zot.delete_tags(*tags_to_remove_n)
print('Number of Remaining Tags:',len(tags_to_remove))
```
* You can use `tags_to_keep` to preserve a list of tags that you don't want to be deleted.
** Note code indentations are not shown in comments here.
Example screen output:
```
Number of Remaining Tags: 1052
Number of Remaining Tags: 1002
Number of Remaining Tags: 952
Number of Remaining Tags: 902
Number of Remaining Tags: 851
Number of Remaining Tags: 801
Number of Remaining Tags: 752
Number of Remaining Tags: 702
Number of Remaining Tags: 652
Number of Remaining Tags: 601
Number of Remaining Tags: 552
Number of Remaining Tags: 502
Number of Remaining Tags: 451
Number of Remaining Tags: 402
Number of Remaining Tags: 352
Number of Remaining Tags: 302
Number of Remaining Tags: 252
Number of Remaining Tags: 202
Number of Remaining Tags: 152
Number of Remaining Tags: 102
Number of Remaining Tags: 52
Number of Remaining Tags: 2
Number of Remaining Tags: 0
```
(see also https://forums.zotero.org/discussion/78625/feature-suggestion-suggestion-for-renaming-tags#latest)
As what I experienced, the proliferation of tags is mainly because of the import of RIS files for meta analysis or literature review, which downloaded from Scopus or WOS, so the tags are limited with some selected items. As such, every time, after importing RIS files, you can use this function on the imported items to eliminate attached tags.
Zutilo plugin can be accessed by: https://github.com/wshanks/Zutilo
See here:
https://www.zotero.org/support/collections_and_tags
https://www.zotero.org/support/collections_and_tags#tags
# Note: you need to create a new private key at
# https://www.zotero.org/settings/keys,
# and "Allow write access".
from pyzotero import zotero
library_id = ' ' # your id
library_type = 'user'
api_key = ' ' # your key
zot = zotero.Zotero(library_id, library_type, api_key)
zot.key_info() # to skim user's information
while len(tags_to_remove)>0:
tags = zot.everything(zot.tags())
tags_to_remove = list(set(tags))
tags_to_remove_n = tags_to_remove[:min(len(tags_to_remove),50)]
zot.delete_tags(*tags_to_remove_n)
print('Number of Remaining Tags:',len(tags_to_remove))
# Note code indentations are not shown in comments here.
This is quite strange, as this plugin doesn't take care of syncing. If it is locally changed, it should be synced by Zotero. Could you please check your Zotero syncing settings?