Exporting metadata AND (cached) full-text in some format
188BET靠谱吗I've (sort of) asked this before and we are (sort of) able to do this now, but still: does anybody know of an elegant way to export Zotero libraries/collections in a way that includes both the metadata AND the full text in a single file (JSON, csv, ...) that can then be read by third-party tools (for textmining, corpus annotation, machine learning purposes, etc.)?Thanks!
I apologize for asking this, and we MAY be able to figure this out.But it would take us days or even weeks.With no guarantee of success.
Look at the code for retrieving a list of items in a collection, and the code lower down on retrieving item attachments.
If you're willing to use R, you can do it like this:
#####
# install.packages(c("magrittr", "DBI", "RSQLite", "quanteda", "readtext"))
library(magrittr)
library(DBI)
library(RSQLite)
library(quanteda)
library(readtext)
188BET靠谱吗# connect to Zotero's SQLite database
con = dbConnect(drv = RSQLite::SQLite(),
188BET靠谱吗dbname = "~/Zotero/zotero.sqlite")
# get names of all tables in the database
alltables = dbListTables(con)
# bring the items and itemNotes tables into R
table.items <- dbGetQuery(con, 'select * from items')
table.itemNotes <- dbGetQuery(con, 'select * from itemNotes')
188BET靠谱吗# bring in Zotero fulltext cache plaintext
188BET靠谱吗textDF <- readtext(paste0("~/Zotero/storage", "/*/.zotero-ft-cache"),
docvarsfrom = "filepaths")
# isolate "key" (8-character alphanumeric directory in storage/) in docvar1 associated with plaintext
textDF$docvar1 <- gsub(pattern = "^.*storage\\/", replacement = "", x = textDF$docvar1)
textDF$docvar1 <- gsub(pattern = "\\/.*", replacement = "", x = textDF$docvar1)
# bring in itemID (and some other metadata) and that's all
textDF <- textDF %>%
dplyr::rename(key = docvar1) %>%
dplyr::left_join(table.items) %>%
dplyr::filter(!is.na(itemID), !itemID %in% table.itemNotes$itemID)
#####
188BET靠谱吗For a full example, you can see how I used this to calculate tf-idf for each indexed Zotero item and then added new tags based on those results to the database here: https://ntrlshrp.gitlab.io/post/zotfidf/
188BET靠谱吗*** NB: This directly accesses Zotero's local SQLite database, which is considered programatically more brittle / fragile than working with the local JavaScript API (see 188BET靠谱吗//www.brodersterzo.com/support/dev/client_coding/javascript_api).
Hope that is helpful!
The part that's iffy is the re-writing to the database (i.e.the part in the blogpost that starts with if(NEW_TAGS).That almost certainly breaks the database at a minimum in the sense that it will lead to unpredictable behavior when syncing, so I'd very much discourage anyone to do this with a database they want to keep working with.
I can make this work in RStudio until
Which is where I get:
188BET靠谱吗And so for 'dbname =', I entered the path to my zotero.sqlite.Which I guess it accepted.But what if I only want to use one group collection?How can I specify that?