zotero / translators

Zotero Translators
http://www.zotero.org/support/dev/translators
1.26k stars 750 forks source link

OpenAlex web and JSON translator #3269

Closed adam3smith closed 2 months ago

bjohas commented 6 months ago

This is great, many thanks!

Can I check whether the translator will add the openalex id to the Zotero record?

adam3smith commented 6 months ago

Ah, no. What would be the right format? I understand that they like the namespace prefix to be included? So openalex.org/W12345 ?

adam3smith commented 5 months ago

@AbeJellinek I think this should be all set

quachpas commented 2 months ago

Hello! @adam3smith

As all OA uses the type "article" for journal articles, conference proceedings and preprints, what do you think about adding the following logic into the JSON translator?

Journal articles will have a primary_location.source.type of journal Conference proceedings will have a primary_location.source.type of conference Preprints or "posted content" will have a primary_location.version of submittedVersion

See https://docs.openalex.org/api-entities/works/work-object#type

AbeJellinek commented 2 months ago

@quachpas: We'd need some test cases for those, but makes sense to me.

quachpas commented 2 months ago

@AbeJellinek you need to revert capitalization for OpenAlex JSON.js. It breaks the tests for the field extra.

As for a patch, how about this?

Details

```patch From 8e1c7a396085173a3b52c74bba902f915379c547 Mon Sep 17 00:00:00 2001 From: Pascal Quach Date: Mon, 29 Jul 2024 15:47:30 +0200 Subject: Fix tags, add types and primary source logic to itemType --- OpenAlex JSON.js | 22 ++++-- OpenAlex.js | 173 +++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 178 insertions(+), 17 deletions(-) diff --git a/OpenAlex JSON.js b/OpenAlex JSON.js index 84c9df5d..09ff00d4 100644 --- a/OpenAlex JSON.js +++ b/OpenAlex JSON.js @@ -8,7 +8,7 @@ "priority": 100, "inRepository": true, "translatorType": 1, - "lastUpdated": "2024-04-13 18:27:45" + "lastUpdated": "2024-07-29 13:38:39" } /* @@ -71,6 +71,7 @@ var PDFversionMap = { publishedVersion: "Full Text PDF" }; /* eslint-disable camelcase*/ +/* https://docs.openalex.org/api-entities/works/work-object#type */ var mappingTypes = { article: "journalArticle", book: "book", @@ -86,7 +87,12 @@ var mappingTypes = { letter: "journalArticle", "peer-review": "document", // up for debate erratum: "journalArticle", - grant: "manuscript" // up for debate + grant: "manuscript", // up for debate + preprint: "preprint", + review: "journalArticle", + libguides: "encyclopediaArticle", + "supplementary-materials": "journalArticle", + retraction: "journalArticle", }; function doImport() { @@ -130,6 +136,15 @@ function parseIndividual(data) { item.publisher = data.primary_location.source.host_organization_name; } item.ISSN = data.primary_location.source.issn; + if (data.primary_location.source.type == "journal") { + item.itemType = "journalArticle"; + } + if (data.primary_location.source.type == "conference") { + item.itemType = "conferencePaper"; + } + if (data.primary_location.version == "submittedVersion") { + item.itemType = "preprint"; + } } @@ -163,13 +178,12 @@ function parseIndividual(data) { } let tags = data.keywords; for (let tag of tags) { - item.tags.push(tag.keyword); + item.tags.push(tag.display_name); } item.extra = "OpenAlex: " + data.ids.openalex; item.complete(); } - /** BEGIN TEST CASES **/ var testCases = [ { diff --git a/OpenAlex.js b/OpenAlex.js index a7fd7399..e04415cb 100644 --- a/OpenAlex.js +++ b/OpenAlex.js @@ -9,7 +9,7 @@ "inRepository": true, "translatorType": 12, "browserSupport": "gcsibv", - "lastUpdated": "2024-04-13 18:27:11" + "lastUpdated": "2024-07-29 13:44:52" } /* @@ -102,7 +102,6 @@ async function scrape(ids) { await translator.translate(); } - /** BEGIN TEST CASES **/ var testCases = [ { @@ -142,13 +141,10 @@ var testCases = [ ], "tags": [ { - "tag": "labor" - }, - { - "tag": "male-female" + "tag": "Gender Pay Gap" }, { - "tag": "markets" + "tag": "Job Polarization" } ], "notes": [], @@ -270,22 +266,173 @@ var testCases = [ ], "tags": [ { - "tag": "access" + "tag": "Open Access Publishing" + } + ], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://openalex.org/works/w2964121744", + "detectedItemType": "journalArticle", + "items": [ + { + "itemType": "preprint", + "title": "Adam: A Method for Stochastic Optimization", + "creators": [ + { + "firstName": "Diederik P.", + "lastName": "Kingma", + "creatorType": "author" }, { - "tag": "articles" + "firstName": "Jimmy", + "lastName": "Ba", + "creatorType": "author" + } + ], + "date": "2014-01-01", + "DOI": "10.48550/arxiv.1412.6980", + "extra": "OpenAlex: https://openalex.org/W2964121744", + "genre": "preprint", + "language": "en", + "libraryCatalog": "OpenAlex", + "repository": "Cornell University", + "shortTitle": "Adam", + "attachments": [], + "tags": [ + { + "tag": "Approximation Algorithms" }, { - "tag": "large-scale" + "tag": "Convex Optimization" }, { - "tag": "oa" + "tag": "Global Optimization" }, { - "tag": "open" + "tag": "Optimization Software" + }, + { + "tag": "Stochastic Gradient Descent" + } + ], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://openalex.org/works/W2962935454", + "detectedItemType": "journalArticle", + "items": [ + { + "itemType": "conferencePaper", + "title": "Generalizing to Unseen Domains via Adversarial Data Augmentation", + "creators": [ + { + "firstName": "Riccardo", + "lastName": "Volpi", + "creatorType": "author" + }, + { + "firstName": "Hongseok", + "lastName": "Namkoong", + "creatorType": "author" + }, + { + "firstName": "Ozan", + "lastName": "Şener", + "creatorType": "author" + }, + { + "firstName": "John C.", + "lastName": "Duchi", + "creatorType": "author" }, { - "tag": "prevalence" + "firstName": "Vittorio", + "lastName": "Murino", + "creatorType": "author" + }, + { + "firstName": "Silvio", + "lastName": "Savarese", + "creatorType": "author" + } + ], + "date": "2018-05-01", + "extra": "OpenAlex: https://openalex.org/W2962935454", + "language": "en", + "libraryCatalog": "OpenAlex", + "pages": "5334-5344", + "proceedingsTitle": "Neural Information Processing Systems", + "volume": "31", + "attachments": [], + "tags": [ + { + "tag": "Adversarial Examples" + }, + { + "tag": "Domain Adaptation" + }, + { + "tag": "Representation Learning" + }, + { + "tag": "Transfer Learning" + }, + { + "tag": "Unsupervised Learning" + } + ], + "notes": [], + "seeAlso": [] + } + ] + }, + { + "type": "web", + "url": "https://openalex.org/works/w2979586175", + "items": [ + { + "itemType": "journalArticle", + "title": "Two-Way Fixed Effects Estimators with Heterogeneous Treatment Effects", + "creators": [ + { + "firstName": "Clément de", + "lastName": "Chaisemartin", + "creatorType": "author" + }, + { + "firstName": "Xavier", + "lastName": "D’Haultfœuille", + "creatorType": "author" + } + ], + "date": "2020-09-01", + "DOI": "10.1257/aer.20181169", + "ISSN": "0002-8282,1944-7981", + "extra": "OpenAlex: https://openalex.org/W2979586175", + "issue": "9", + "language": "en", + "libraryCatalog": "OpenAlex", + "pages": "2964-2996", + "publicationTitle": "American Economic Review", + "volume": "110", + "attachments": [ + { + "title": "Submitted Version PDF", + "mimeType": "application/pdf" + } + ], + "tags": [ + { + "tag": "Treatment Effects" } ], "notes": [], -- 2.45.2 ```

AbeJellinek commented 2 months ago

Thanks. Not sure why I did that...

AbeJellinek commented 2 months ago

Let me know if it looks good now with the suggested changes!

quachpas commented 2 months ago

As far as I can see, I believe it's good to go.

AbeJellinek commented 2 months ago

Thank you @quachpas!