Skip to content

Commit cf68270

Browse files
yarikopticclaude
andcommitted
Use dataset item type with DOI, version, and repository fields
DANDI datasets are now properly represented as "dataset" item type in Zotero instead of "webpage", with native support for dataset-specific fields. Changes to update-zotero-collection: - Map @misc entries to "dataset" item type (not "webpage") - Add DOI as direct field for dataset type (no longer in extra) - Map publisher to "repository" field for datasets - Extract and set versionNumber from DOI for all datasets - Include repository, versionNumber, DOI in comparison logic - Keeps "Current version:" in extra for latest entries Changes to test-citation-key: - Test with "dataset" itemType instead of "webpage" - Demonstrate DOI, versionNumber, repository fields - Show all dataset fields in retrieved item output Dataset entries now look like: itemType: dataset DOI: 10.48324/DANDI.000027/0.210831.2033 versionNumber: 0.210831.2033 repository: DANDI Archive Citation Key: dandi.000027@0.210831.2033 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent b9b9d6a commit cf68270

2 files changed

Lines changed: 58 additions & 21 deletions

File tree

‎sandbox/test-citation-key‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,28 +61,34 @@ def main():
6161

6262
# Create a test item with a custom citation key
6363
test_citation_key = "dandi.000027@0.210831.2033"
64+
test_version = "0.210831.2033"
6465
lgr.info(f"Creating test item with citation key: {test_citation_key}")
6566

67+
# Test with dataset item type (more appropriate for DANDI datasets)
6668
test_item = {
67-
"itemType": "webpage",
68-
"title": "TEST ITEM - Citation Key Test - DELETE ME",
69-
"url": "https://example.com/test",
69+
"itemType": "dataset",
70+
"title": "TEST ITEM - Dataset Citation Key Test - DELETE ME",
71+
"url": "https://dandiarchive.org/dandiset/000027/0.210831.2033",
7072
"date": "2025",
71-
"extra": (
72-
f"DOI: 10.48324/TEST/1.0\n"
73-
f"Publisher: Test Publisher\n"
74-
f"Citation Key: {test_citation_key}\n"
75-
),
73+
"DOI": "10.48324/TEST/1.0", # dataset type supports DOI field directly
74+
"versionNumber": test_version, # dataset supports version field
75+
"repository": "DANDI Archive", # dataset supports repository field
76+
"extra": f"Citation Key: {test_citation_key}\n",
7677
"creators": [
7778
{
7879
"creatorType": "author",
7980
"firstName": "Test",
8081
"lastName": "Author",
8182
}
8283
],
83-
"tags": [{"tag": "test"}],
84+
"tags": [{"tag": "test"}, {"tag": "dataset"}],
8485
}
8586

87+
lgr.info("Testing with itemType: dataset")
88+
lgr.info(f" DOI field: {test_item.get('DOI')}")
89+
lgr.info(f" versionNumber field: {test_item.get('versionNumber')}")
90+
lgr.info(f" repository field: {test_item.get('repository')}")
91+
8692
try:
8793
# Create the item
8894
lgr.info("Creating item...")
@@ -107,8 +113,14 @@ def main():
107113

108114
lgr.info("\n" + "=" * 60)
109115
lgr.info("Retrieved item details:")
116+
lgr.info(f" ItemType: {retrieved['data'].get('itemType', '')}")
110117
lgr.info(f" Title: {retrieved['data'].get('title', '')}")
111118
lgr.info(f" ItemKey: {retrieved['data'].get('key', '')}")
119+
lgr.info(f" DOI: {retrieved['data'].get('DOI', '(not set)')}")
120+
lgr.info(f" Version: {retrieved['data'].get('versionNumber', '(not set)')}")
121+
lgr.info(f" Repository: {retrieved['data'].get('repository', '(not set)')}")
122+
lgr.info(f" URL: {retrieved['data'].get('url', '')}")
123+
lgr.info(f" Date: {retrieved['data'].get('date', '')}")
112124
lgr.info(f" Extra field:\n{retrieved['data'].get('extra', ' (empty)')}")
113125
lgr.info("=" * 60)
114126

‎sandbox/update-zotero-collection‎

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ def bibtex_to_zotero_item(entry: Dict) -> Dict:
5757
"article": "journalArticle",
5858
"book": "book",
5959
"inproceedings": "conferencePaper",
60-
"misc": "webpage", # DANDI uses @misc for datasets
60+
"misc": "dataset", # DANDI uses @misc for datasets, map to dataset type
6161
"phdthesis": "thesis",
6262
"techreport": "report",
6363
}
6464

6565
entry_type = entry.get("ENTRYTYPE", "misc").lower()
66-
zotero_type = type_mapping.get(entry_type, "webpage")
66+
zotero_type = type_mapping.get(entry_type, "dataset")
6767

6868
# Build the Zotero item
6969
item = {
@@ -75,21 +75,21 @@ def bibtex_to_zotero_item(entry: Dict) -> Dict:
7575
}
7676

7777
# Extract DOI
78-
# Note: Some Zotero item types (like 'webpage') don't accept 'DOI' as a direct field
79-
# So we only add it to 'extra' field for all types to be safe
8078
doi = entry.get("doi", "")
8179
if doi:
82-
# Only add DOI as a direct field for item types that support it
80+
# dataset type supports DOI as a direct field
8381
if zotero_type in [
8482
"journalArticle",
8583
"conferencePaper",
8684
"book",
8785
"thesis",
8886
"report",
87+
"dataset",
8988
]:
9089
item["DOI"] = doi
91-
# Always add to extra field as well for consistency
92-
item["extra"] += f"DOI: {doi}\n"
90+
else:
91+
# For types that don't support DOI, add to extra field
92+
item["extra"] += f"DOI: {doi}\n"
9393

9494
# Extract authors
9595
if "author" in entry:
@@ -117,12 +117,14 @@ def bibtex_to_zotero_item(entry: Dict) -> Dict:
117117
}
118118
)
119119

120-
# Add publisher
121-
# Note: Some Zotero item types (like 'webpage') don't accept 'publisher' as a field
122-
# For those, we'll add it to the 'extra' field instead
120+
# Add publisher / repository
121+
# For datasets, publisher goes to "repository" field; for others use publisher field
123122
if "publisher" in entry:
124123
publisher = entry["publisher"]
125-
if zotero_type in [
124+
if zotero_type == "dataset":
125+
# dataset type has "repository" field instead of publisher
126+
item["repository"] = publisher
127+
elif zotero_type in [
126128
"journalArticle",
127129
"book",
128130
"conferencePaper",
@@ -134,6 +136,16 @@ def bibtex_to_zotero_item(entry: Dict) -> Dict:
134136
# Add to extra field for types that don't support publisher
135137
item["extra"] += f"Publisher: {publisher}\n"
136138

139+
# Extract version from DOI for datasets
140+
# DOI format: 10.48324/DANDI.000027/0.210831.2033
141+
if zotero_type == "dataset" and doi:
142+
doi_parts = doi.split("/")
143+
if len(doi_parts) >= 2:
144+
version = doi_parts[-1]
145+
# Check if it looks like a version (not just a dandiset ID)
146+
if "." in version and len(version) > 6:
147+
item["versionNumber"] = version
148+
137149
# Add keywords as tags
138150
if "keywords" in entry:
139151
keywords = entry["keywords"]
@@ -250,7 +262,17 @@ def items_are_different(existing: Dict, new: Dict) -> bool:
250262
if existing_citation_key != new_citation_key:
251263
return True
252264
# For citation-key items, skip extra field comparison below
253-
fields_to_compare = ["title", "date", "url", "abstractNote", "publisher"]
265+
# Include dataset-specific fields (repository, versionNumber, DOI)
266+
fields_to_compare = [
267+
"title",
268+
"date",
269+
"url",
270+
"abstractNote",
271+
"publisher",
272+
"repository",
273+
"versionNumber",
274+
"DOI",
275+
]
254276
else:
255277
# No citation keys, compare everything including extra
256278
fields_to_compare = [
@@ -259,6 +281,9 @@ def items_are_different(existing: Dict, new: Dict) -> bool:
259281
"url",
260282
"abstractNote",
261283
"publisher",
284+
"repository",
285+
"versionNumber",
286+
"DOI",
262287
"extra",
263288
]
264289

0 commit comments

Comments
 (0)