Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

collect and normalize tags #1

Open
VladimirAlexiev opened this issue Oct 1, 2022 · 6 comments
Open

collect and normalize tags #1

VladimirAlexiev opened this issue Oct 1, 2022 · 6 comments
Assignees

Comments

@VladimirAlexiev
Copy link
Contributor

VladimirAlexiev commented Oct 1, 2022

cd export
grep '"tag"' better-bibtex-json.json|sort|uniq
grep ' keywords ' better-biblatex.bib|perl -pe 's{keywords = \{(.*)\}}{$1}; s{,}{\n}g'|sort|uniq
  • also consider collecting tag counts, which can guide you into which should be the normalized (most popular) forms,
    and which still need to be normalized (the least used ones)
  • normalize the tags, eg by using OpenRefine's string clustering functions.
    Copy the original tags to a second column normalized, then use clustering to normalize that
  • (OPTIONAL, depending on [Feature] tag cleanup (normalize/canonicalize tags) windingwind/zotero-actions-tags#38) produce a normalization file
    with format tag: alias, alias2, alias3 eg:
Building Information Modeling (BIM): building information modeling, Building Information Modeling (BIM), BIM, Building Information Modeling
Automated Compliance Checking (ACC): automated compliance checking, automated code checking, automated compliance checking system
@VladimirAlexiev
Copy link
Contributor Author

@SCVFlare do you want to take a look?
First read the linked issues as I've added info there (eg Zotero can easily correct a tag using rclick on the bottom-left pane)

@SCVFlare
Copy link
Collaborator

SCVFlare commented Oct 13, 2022

Hi, added information to a readme. The problem with bulk changing the tags is possible via the api of zotero.
https://www.zotero.org/support/dev/web_api/v3/start - the API documentation.
here's sample code from the python library for zotero. For example, we can get all items from the library, iterate them and change the tags and finally update the item in the library

i = zot.items()
# see above for example of returned item structure
# modify the latest item which was added to your library
i[0]['data']['title'] = 'The Sheltering Sky'
i[0]['data']['creators'][0]['firstName'] = 'Paul'
i[0]['data']['creators'][0]['lastName'] = 'Bowles'
zot.update_item(i[0])

@VladimirAlexiev
Copy link
Contributor Author

@SCVFlare That will work, but I think a more efficient way to update is from a JS addon: windingwind/zotero-actions-tags#38.

Zotero has "tag rename & merge" UI functionality:
image
I hope a JS addon can do a similar thing, whereas the API doesn't have any functions on tags

So far the issue asks for normalization through replacement. It would also be great to have tag enrichment: subconcept -> superconcept, eg

CityGML -> GML
IndoorGML -> GML
Prolog -> logic programming, Answer Set Programming (ASP)
B-Prolog -> Prolog # and thereon the other two superconcepts

@VladimirAlexiev
Copy link
Contributor Author

@SCVFlare https://www.wikidata.org/wiki/Wikidata:Zotero#Scripts gives as example:

How does that compare to your API research? Can you update your example to show how to edit tags?

@SCVFlare
Copy link
Collaborator

SCVFlare commented Oct 20, 2022

Hi @VladimirAlexiev,

The JavaScript API is much more powerful than the web API and may have exactly what you're searching for, however, I can't find it.
The ItemFields does not indeed have a tag field.

However, I managed to the same as I did with the web API above - find all the items with the tag and replace it.
Here's some sample code that can be run in the Developer-> Run JavaScript console.

var tag = "<your tag here>";
var s = new Zotero.Search();
s.libraryID = ZoteroPane.getSelectedLibraryID();
s.addCondition('tag', 'is', tag);
var ids = await s.search();
if (!ids.length) {
    return "No items found";
}
await Zotero.DB.executeTransaction(async function () {
    for (let id of ids) {
        let item = Zotero.Items.get(id);
        item.replaceTag(tag, "<new tag name here>");
        await item.save({
            skipDateModifiedUpdate: true
        });
    }
});
return ids.length + " tag(s) updated";

This could be appropriated in the same way. by iterating through the old tags, find the item and update in the same vain as the web API.

@SCVFlare
Copy link
Collaborator

Update:

I actually found the function rename function in the source code of the Tags object and it's even simpler:

var tag = "<old tag>";
var id = new Zotero.Search();
id = ZoteroPane.getSelectedLibraryID();

Zotero.Tags.rename(id,tag,"<new tag here>");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants