simple tag management queries

edited February 6, 2024
I think I will write a tool for (batch) processing tags directly on the Zotero database. The main features that I want:

1. Lowercase everything
2. Expansion based on rules (~hierarchy)
3. Identify "tag monsters"
4. Add tags based on collection(s)

1. Lowercase everything: this is because I always have various upper- and lower-case variants of many tags, I just want to make them all lowercase and be done with it.

2. Expansion based on rules: This is the idea of my own hierarchy of tags that I want apply, except that it need not be a tree (for example, a tag could have multiple independent 'parent' tags). The config file for this would be a simple two-column csv file, each line containing:
tag,parent-tag

for example, my file could look like this:
paris,baguette
paris,france
france,europe

The program would apply to each item that has the tag "paris", the additional tags "baguette" (line 1), "france" (line 2), and "europe" (lines 2 and 3), and any item that already has the tag "france" gets the additional tag "europe" (line 3).

Number 3: Identify "tag monsters": I use the Zotero browser plugin regularly, to get all sorts of publications. I don't always check if the tags are sensible, and sometimes I pull in an article with 20-30 pretty useless tags. Such items could be identified because they have a large number of tags that are mostly used only by the item in question; if the program gives me a list of the offending entries, I can look them up in Zotero and throw out the useless tags.

Number 4. Add tags based on collection(s): This could be a second config file, with a mapping of collection name to tags that should be added to all items in that collection.

for example, my file could contain:
"Philosophy" => philosophy
"AI and Healthcare" => ai,healthcare


My current idea is to simply write SQL queries that can be run on Zotero's SQLite database (probably best while Zotero is not running). Let me know in case you have suggestions! Cheers
  • You should absolutely not write to the sqlite directly and you should most definitely not recommend any tool that does so to anyone here on the forums. It's an almost surefire way to break something in your database.

    Zotero has a robust internal javascript API that you can use via the console or via add-ons as well as a server API with several libraries, either of this would be options for a tool.
  • Tags from collections would help, a lot.
  • > "You should absolutely not write to the sqlite directly and you should most definitely not recommend any tool that does so to anyone here on the forums. It's an almost surefire way to break something in your database."

    OK, duly noted!

    > "Zotero has a robust internal javascript API that you can use via the console or via add-ons as well as a server API with several libraries, either of this would be options for a tool."

    I don't know javascript, therefore that may also be a surefire way to break things. I guess I will check out the server API.

    > "Tags from collections would help, a lot."

    Thanks for your feedback
  • Zotero actions and tags plug-in provides the ability to add tags from collections:
    For plug-in
    https://github.com/windingwind/zotero-actions-tags
    For tags from collections
    https://github.com/windingwind/zotero-actions-tags/discussions/245

    Hope this helps
  • @agam2222 thanks for the link, it looks like zotero-actions-tags could cover my numbers 1, 2 and 4 above, probably with the `customScript` option. Maybe I do have to learn javascript...
Sign In or Register to comment.