CITE THIS NOTEBOOK: Connecting to Zotero by Arnoud Buzing. Wolfram Community DEC 2 2022.
Zotero is a popular tool to collect, organize, annotate, and cite research papers, books, web articles, and more. This post shows a basic way to connect to the Zotero SQLite database and import its data into a Wolfram Language notebook. This data can be useful for further processing, for example to create a citation in a notebook.
We start with locating the SQLite database file. On my system it is here:
In[]:=
file="/Users/arnoudb/Zotero/zotero.sqlite"
Out[]=
/Users/arnoudb/Zotero/zotero.sqlite
Next we turn this into a relational database object:
In[]:=
rdb=RelationalDatabase[file]
Out[]=
To work with this database directly we convert it to an
EntityStore
which creates a Wolfram Language representation of the data in the database
In[]:=
es=EntityStore[rdb]
Out[]=
To actually use the EntityStore in our Wolfram Language session, we need to register it:
In[]:=
EntityRegister[es]
Out[]=
{savedSearchConditions,version,items,feedItems,itemTypesCombined,fulltextWords,customBaseFieldMappings,relationPredicates,collectionRelations,fileTypeMimeTypes,itemAnnotations,deletedItems,fieldsCombined,customItemTypeFields,itemRelations,itemTypeFields,itemTypeFieldsCombined,users,itemDataValues,customFields,itemTags,fulltextItemWords,fieldFormats,libraries,syncQueue,fields,creatorTypes,baseFieldMappings,collectionItems,savedSearches,syncCache,itemAttachments,groups,itemNotes,groupItems,syncDeleteLog,publicationsItems,customItemTypes,fileTypes,itemTypes,storageDeleteLog,itemCreators,syncedSettings,creators,feeds,itemData,proxyHosts,translatorCache,proxies,retractedItems,collections,syncObjectTypes,baseFieldMappingsCombined,tags,itemTypeCreatorTypes,settings,deletedCollections,fulltextItems,charsets,deletedSearches,dbDebug1}
In my copy of Zotero, I have added a small number of books and research papers. Here is what it looks like in Zotero:
Each one of these items has detailed meta-information. For example, this is from a paper on Arxiv:
We can now get these as “items” entities and we’re interested specifically in the “itemData” property which stores the actual data:
In[]:=
AbsoluteTiming[itemDatas=EntityValue["items","itemData"]]
Out[]=
{0.246844,{EntityClass[itemData,{itemID1}],EntityClass[itemData,{itemID2}],EntityClass[itemData,{itemID3}],EntityClass[itemData,{itemID4}],EntityClass[itemData,{itemID5}],EntityClass[itemData,{itemID6}],EntityClass[itemData,{itemID7}],EntityClass[itemData,{itemID8}],EntityClass[itemData,{itemID9}],EntityClass[itemData,{itemID10}],EntityClass[itemData,{itemID11}],EntityClass[itemData,{itemID12}],EntityClass[itemData,{itemID13}],EntityClass[itemData,{itemID14}],EntityClass[itemData,{itemID15}],EntityClass[itemData,{itemID16}]}}
The field names are stored with a “fieldID” so we can build a table to associate the “fieldID” with the actual “fieldName”. This makes it easier to understand what each field is for:
In[]:=
AbsoluteTiming[fields=Apply[Rule,EntityValue["fields",{"fieldID","fieldName"}],1]]
Out[]=
{0.185475,{1title,2abstractNote,3artworkMedium,4medium,5artworkSize,6date,7language,8shortTitle,9archive,10archiveLocation,11libraryCatalog,12callNumber,13url,14accessDate,15rights,16extra,17audioRecordingFormat,18seriesTitle,19volume,20numberOfVolumes,21place,22label,23publisher,24runningTime,25ISBN,26billNumber,27number,28code,29codeVolume,30section,31codePages,32pages,33legislativeBody,34session,35history,36blogTitle,37publicationTitle,38websiteType,39type,40series,41seriesNumber,42edition,43numPages,44bookTitle,45caseName,46court,47dateDecided,48docketNumber,49reporter,50reporterVolume,51firstPage,52versionNumber,53system,54company,55programmingLanguage,56proceedingsTitle,57conferenceName,58DOI,59dictionaryTitle,60subject,61encyclopediaTitle,62distributor,63genre,64videoRecordingFormat,65forumTitle,66postType,67committee,68documentNumber,69interviewMedium,70issue,71seriesText,72journalAbbreviation,73ISSN,74letterType,75manuscriptType,76mapType,77scale,78country,79assignee,80issuingAuthority,81patentNumber,82filingDate,83applicationNumber,84priorityNumbers,85issueDate,86references,87legalStatus,88episodeNumber,89audioFileType,90repository,91archiveID,92citationKey,93presentationType,94meetingName,95programTitle,96network,97reportNumber,98reportType,99institution,100nameOfAct,101codeNumber,102publicLawNumber,103dateEnacted,104thesisType,105university,106studio,107websiteTitle}}
Now we’re ready to import all the data from the raw entities into a more suitable
Dataset
:
In[]:=
ds=Dataset[​​Map[​​Function[{item},Association[Map[(First[#]/.fields)->Last[#]["value"]&,EntityValue[item,{"fieldID","itemDataValues"}]]]],​​itemDatas]​​]
Out[]=
title
Wolfram: Computation Meets Knowledge
abstractNote
Wolfram, creators of the Wolfram Language, Wolfram|Alpha, Mathematica, Development Platform, Data Science Platform, Finance Platform, SystemModeler...
6 total ›
title
Snapshot
url
https://www.wolfram.com/?source=nav
3 total ›
title
A New Kind of Science
date
2002-05-14 2002-05-14
9 total ›
title
Amazon.com Link
url
https://www.amazon.com/New-Kind-Science-Stephen-Wolfram/dp/1579550088/ref=sr_1_1?crid=2YYA8M38LCF2T&keywords=new+kind+of+science&qid=1669992480&sprefix=new+kind+of+science%2Caps%2C97&sr=8-1
3 total ›
title
A Project to Find the Fundamental Theory of Physics
date
2020-06-19 2020-06-19
8 total ›
title
Amazon.com Link
url
https://www.amazon.com/dp/1579550355/ref=redir_mobile_desktop?_encoding=UTF8&aaxitk=8ff267324538fafe6f0513732a960a62&content-id=amzn1.sym.552bcbb2-81a1-4e8b-b868-3fba7d5af42a%3Aamzn1.sym.552bcbb2-81a1-4e8b-b868-3fba7d5af42a&hsa_cr_id=3417028710901&pd_rd_plhdr=t&pd_rd_r=d11b48bc-69aa-4e7d-b22c-d5291545a6e8&pd_rd_w=QqJED&pd_rd_wg=hcnbr&qid=1669995002&ref_=sbx_be_s_sparkle_mcd_asin_0_img&sr=1-1-9e67e56a-6f64-441f-a281-df67fc737124
3 total ›
title
Combinators: A Centennial View
date
2021-06-17 2021-06-17
9 total ›
title
Amazon.com Link
url
https://www.amazon.com/Combinators-Centennial-View-Stephen-Wolfram/dp/1579550436/ref=pd_bxgy_img_sccl_2/132-2923550-9048248?pd_rd_w=7ROYv&content-id=amzn1.sym.7f0cf323-50c6-49e3-b3f9-63546bb79c92&pf_rd_p=7f0cf323-50c6-49e3-b3f9-63546bb79c92&pf_rd_r=410RV0164HHP6Y881E98&pd_rd_wg=vatRT&pd_rd_r=89a9a478-6f6b-4953-9835-0f177759053f&pd_rd_i=1579550436&psc=1
3 total ›
title
Hands-on Start to Wolfram Mathematica and Programming with the Wolfram Language
date
2020-09-21 2020-09-21
9 total ›
rows 1–10 of 16
We can look up a specific book or paper by its location in the dataset:
Or, perhaps more useful, we can search for a specific keyword like “title” and search inside the value string for that keyword: