Update existing items via JSON-LD import

I’m trying to create a workflow between Tropy and R by importing and exporting via JSON-LD. The import works perfectly (thanks to advice on other threads such as here and here).

But is there a way to update an existing item? At the moment, it looks like importing an item duplicates it, rather than replaces/overrides the metadata for the existing item. I have tried with relative and absolute paths to see if Tropy recognises the item, as well as keeping the title and/or the identifier fields identical. Is this expected behaviour? Any thoughts?

The idea is to export an item, alter the JSON-LD in another tool, then re-import to update the original items with the changes, right?

This is interesting because we’re currently designing a new plugin hook to alter existing items with pretty much the same idea: plugin receives the JSON-LD, manipulates it, returns JSON-LD, Tropy figures out how the alterations to the JSON-LD affect the original item and applies the changes to it.

In any case, currently when paste/import JSON-LD you will always get a new item. What you can do is merge the old item into the original one. For example:

  1. Select an item and export it (or copy it and paste the JSON-LD somewhere)
  2. Manipulate the JSON-LD
  3. Import the altered JSON-LD
  4. Drag the original item on the newly imported item to merge them
  5. Remove the duplicate photos in the merged item

Note that when merging items the order is important. For most purposes I think you will want to drag the original item over the new one, to merge the old item into the changed one.

Thanks @inukshuk! Yes that is exactly what I wanted to do; the idea is to be able to look at Tropy annotations in RStudio to explore/quantify them, and then potentially import the data back into Tropy with, for example, a new tag attached to specific subsets.

I’ll be keeping my eyes open for the plugin and will merge individual items until then.

1 Like

I might be poking a dead horse, but is there any update about the plugin? I am developing a workflow to use the JSON-LD to manage dynamic tags outside Tropy (200+ tags I am managing), and I would like to import the JSON-LD into tropy to keep the tag list afresh.

Is it possible to use the checksum or some field (such as photo path) to avoid creating new items?

We have added import plugins in the meantime (for example the IIIF manifest plugin), but this plugin hook is only for creating new items, not changing existing ones. We have also been working with a ‘processing’ plugin hook that can change existing items – we have not released it yet, but it’s probably not perfect for your use case either (with that plugin, you would have to select the items in the UI and then trigger the plugin).

If you’re managing the tags outside of Tropy and each tag can be associated with a photo’s checksum, updating the project database directly could be an option as well. Compared to metadata, manipulating tags in the database should be relatively easy. There’s also an HTTP API that you could use. Here are some quick examples to illustrate how this could work. If you let us know which approach sounds most promising we can go into more detail.

You can use these queries to explore tags directly in the project database (using the project file “tmp/gamma.tropy/project.tpy” as an example:

# All tags
sqlite3 tmp/gamma.tropy/project.tpy "select * from tags"

# All photos (by checksum) and their associated tags
sqlite3 tmp/gamma.tropy/project.tpy "select checksum, name from tags join taggings using (tag_id) join photos on (item_id = taggings.id) order by checksum

You can see the project db schema here. The relevant tables are photos, tags and taggings which links tags and items.

Alternatively, you can use an HTTP API to access the current project. To enable the API, you need to open the Tropy user data folder (via the help menu), then quit Tropy and then edit the state.json file, setting the api property to true. When you start Tropy next, the active project can be accessed via the API.

# To test if the API works you can print the version
curl http://localhost:2019/version
# To list all tags
curl http://localhost:2019/project/tags
# If you have `jq` installed you can improve the output like this:
curl http://localhost:2019/project/tags | jq .

We have no API documentation unfortunately, but you can see all the available endpoints here. Using the API it’s possible to create tags and add or remove tags from existing items.

I think this sums up the current options: there’s an import hook to create new items using JSON input. To change existing items you can use either the API or edit the database directly; alternatively you could look into using the processing plugin hook (but we’re still finalizing that one).