From ceb88596c83b7770e2351c60f247bb0518c3d711 Mon Sep 17 00:00:00 2001 From: Will Byrne Date: Thu, 24 Oct 2024 11:50:30 +0100 Subject: [PATCH 1/6] Add the reference published year as a string to meta to preserve any suffixes --- src/codecs/jats/index.ts | 15 +++++++++++++-- src/codecs/jats/jats.test.ts | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/codecs/jats/index.ts b/src/codecs/jats/index.ts index 7cb594b55..f4c91185c 100644 --- a/src/codecs/jats/index.ts +++ b/src/codecs/jats/index.ts @@ -1479,7 +1479,18 @@ export function decodeReference( ] if (identifiers.length === 0) identifiers = undefined - const meta = typeof label === 'string' ? { label } : undefined + let metaEntries: Record = {}; + if (datePublishedString !== undefined) { + metaEntries.yearPublished = datePublishedString; + } + if(typeof label === 'string') { + metaEntries.label = label; + } + + let metaContainer: { meta?: Record} = {}; + if (Object.keys(metaEntries)) { + metaContainer = { meta: {...metaEntries}}; + } return stencila.article({ id, @@ -1492,7 +1503,7 @@ export function decodeReference( publisher, identifiers, url, - meta, + ...metaContainer, }) } diff --git a/src/codecs/jats/jats.test.ts b/src/codecs/jats/jats.test.ts index 9ac7fd414..3b95665c1 100644 --- a/src/codecs/jats/jats.test.ts +++ b/src/codecs/jats/jats.test.ts @@ -197,6 +197,18 @@ test.each([ expect(decodeReference(citation, null, undefined)).toEqual(expected) }) +test('decode: reference datePublished is added to meta.yearPublished to preserve suffixes', () => { + const reference = ` + + Calabrese C, Panuzzo C et al (2020a) Deferasirox-Dependent Iron Chelation Enhances Mitochondrial Dysfunction and Restores p53 Signaling by Stabilization of p53 Family Members in Leukemic Cells. International journal of molecular sciences 21 + + ` + const citation = xml.load(reference).elements?.[0]! + + const result = decodeReference(citation, null, undefined); + expect(result.meta?.yearPublished).toEqual('2020a'); +}); + test('decode: element that has more than one ', () => { const fig = xml.load(` From 3776d6c889cc57f0585ef4a3c0ee60db8f1bcc8c Mon Sep 17 00:00:00 2001 From: "A. K" <74007089+soggy-mushroom@users.noreply.github.com> Date: Thu, 24 Oct 2024 14:52:39 +0100 Subject: [PATCH 2/6] Only add yearPublished if year has a suffix --- src/codecs/jats/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codecs/jats/index.ts b/src/codecs/jats/index.ts index cf5b57c14..b253ef880 100644 --- a/src/codecs/jats/index.ts +++ b/src/codecs/jats/index.ts @@ -1494,7 +1494,7 @@ export function decodeReference( if (identifiers.length === 0) identifiers = undefined let metaEntries: Record = {}; - if (datePublishedString !== undefined) { + if (datePublishedString !== undefined && datePublishedString.length > 4) { metaEntries.yearPublished = datePublishedString; } if(typeof label === 'string') { From e07c03117606e7d825bebf64746da952e1ad489c Mon Sep 17 00:00:00 2001 From: Will Byrne Date: Thu, 24 Oct 2024 14:57:08 +0100 Subject: [PATCH 3/6] update snapshots --- .../c2c3813f-6c98-1014-8ba7-9ee2cd5f4386.json | 2 ++ .../ca7917ff-6cb0-1014-9b19-d05ef1e56b05.json | 2 ++ .../d6f14042-6db3-1014-b228-f9da7cb8e4cc.json | 1 + 3 files changed, 5 insertions(+) diff --git a/src/codecs/jats/__file_snapshots__/c2c3813f-6c98-1014-8ba7-9ee2cd5f4386.json b/src/codecs/jats/__file_snapshots__/c2c3813f-6c98-1014-8ba7-9ee2cd5f4386.json index b34f2f9f8..21b91db54 100644 --- a/src/codecs/jats/__file_snapshots__/c2c3813f-6c98-1014-8ba7-9ee2cd5f4386.json +++ b/src/codecs/jats/__file_snapshots__/c2c3813f-6c98-1014-8ba7-9ee2cd5f4386.json @@ -5877,6 +5877,7 @@ "pageStart": 1303, "title": "Structures of human Nav1.7 channel in complex with auxiliary subunits and animal toxins", "meta": { + "yearPublished": "2019a", "publicationType": "journal" } }, @@ -5948,6 +5949,7 @@ }, "title": "Structures of human Nav1.7 channel in complex with auxiliary subunits and animal toxins", "meta": { + "yearPublished": "2019b", "publicationType": "journal" } }, diff --git a/src/codecs/jats/__file_snapshots__/ca7917ff-6cb0-1014-9b19-d05ef1e56b05.json b/src/codecs/jats/__file_snapshots__/ca7917ff-6cb0-1014-9b19-d05ef1e56b05.json index af9bf1920..81d05557e 100644 --- a/src/codecs/jats/__file_snapshots__/ca7917ff-6cb0-1014-9b19-d05ef1e56b05.json +++ b/src/codecs/jats/__file_snapshots__/ca7917ff-6cb0-1014-9b19-d05ef1e56b05.json @@ -2179,6 +2179,7 @@ "pageStart": 5950, "title": "Gustatory Learning and Processing in the Drosophila Mushroom Bodies", "meta": { + "yearPublished": "2015a", "publicationType": "journal" } }, @@ -2229,6 +2230,7 @@ "pageStart": 5950, "title": "Gustatory Learning and Processing in the Drosophila Mushroom Bodies", "meta": { + "yearPublished": "2015b", "publicationType": "journal" } }, diff --git a/src/codecs/jats/__file_snapshots__/d6f14042-6db3-1014-b228-f9da7cb8e4cc.json b/src/codecs/jats/__file_snapshots__/d6f14042-6db3-1014-b228-f9da7cb8e4cc.json index 83b58f386..0e57e34dc 100644 --- a/src/codecs/jats/__file_snapshots__/d6f14042-6db3-1014-b228-f9da7cb8e4cc.json +++ b/src/codecs/jats/__file_snapshots__/d6f14042-6db3-1014-b228-f9da7cb8e4cc.json @@ -3454,6 +3454,7 @@ "title": "Mplus User’s Guide. Eight Edition", "url": "https://www.statmodel.com", "meta": { + "yearPublished": "1998-2018", "publicationType": "book" } }, From 39e3e3fc7e13a1930ceed6ae81bea782f2a08355 Mon Sep 17 00:00:00 2001 From: "A. K" <74007089+soggy-mushroom@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:05:04 +0100 Subject: [PATCH 4/6] Fix the remainder of yaml snapshots --- src/codecs/jats/__file_snapshots__/elife-46472-v3.yaml | 6 ++++++ src/codecs/jats/__file_snapshots__/elife-46793-v1.yaml | 8 ++++++++ src/codecs/jats/__file_snapshots__/elife-52882-v2.yaml | 2 ++ 3 files changed, 16 insertions(+) diff --git a/src/codecs/jats/__file_snapshots__/elife-46472-v3.yaml b/src/codecs/jats/__file_snapshots__/elife-46472-v3.yaml index a8a26dc23..4f680d667 100644 --- a/src/codecs/jats/__file_snapshots__/elife-46472-v3.yaml +++ b/src/codecs/jats/__file_snapshots__/elife-46472-v3.yaml @@ -1592,6 +1592,7 @@ references: Morphine intake and the effects of naltrexone and buprenorphine on the acquisition of methamphetamine intake meta: + yearPublished: 2014a publicationType: journal - type: Article id: bib20 @@ -1630,6 +1631,7 @@ references: Opioid sensitivity in mice selectively bred to consume or not consume methamphetamine meta: + yearPublished: 2014b publicationType: journal - type: Article id: bib21 @@ -1698,6 +1700,7 @@ references: Postsynaptic D2 dopamine receptor supersensitivity in the striatum of mice lacking TAAR1 meta: + yearPublished: 2015a publicationType: journal - type: Article id: bib22 @@ -1814,6 +1817,7 @@ references: pageStart: 2217 title: TAAR1 modulates cortical glutamate NMDA receptor function meta: + yearPublished: 2015b publicationType: journal - type: Article id: bib23 @@ -3936,6 +3940,7 @@ references: A genetic animal model of differential sensitivity to methamphetamine reinforcement meta: + yearPublished: 2012a publicationType: journal - type: Article id: bib59 @@ -3984,6 +3989,7 @@ references: Profound reduction in sensitivity to the aversive effects of methamphetamine in mice bred for high methamphetamine intake meta: + yearPublished: 2012b publicationType: journal - type: Article id: bib60 diff --git a/src/codecs/jats/__file_snapshots__/elife-46793-v1.yaml b/src/codecs/jats/__file_snapshots__/elife-46793-v1.yaml index 9c08a6271..0a1e35433 100644 --- a/src/codecs/jats/__file_snapshots__/elife-46793-v1.yaml +++ b/src/codecs/jats/__file_snapshots__/elife-46793-v1.yaml @@ -1848,6 +1848,7 @@ references: Bortezomib as the first proteasome inhibitor anticancer drug: current status and future perspectives meta: + yearPublished: 2011a publicationType: journal - type: Article id: bib26 @@ -1926,6 +1927,7 @@ references: Selective and cell-active inhibitors of the USP1/ UAF1 deubiquitinase complex reverse cisplatin resistance in non-small cell lung cancer cells meta: + yearPublished: 2011b publicationType: journal - type: Article id: bib27 @@ -2451,6 +2453,7 @@ references: Reevaluation of telomerase inhibition by quadruplex ligands and their mechanisms of action meta: + yearPublished: 2007a publicationType: journal - type: Article id: bib35 @@ -2503,6 +2506,7 @@ references: pageStart: 1856 title: Highly efficient G-quadruplex recognition by bisquinolinium compounds meta: + yearPublished: 2007b publicationType: journal - type: Article id: bib36 @@ -4058,6 +4062,7 @@ references: Systematic and integrative analysis of large gene lists using DAVID bioinformatics resources meta: + yearPublished: 2009a publicationType: journal - type: Article id: bib60 @@ -4101,6 +4106,7 @@ references: Bioinformatics enrichment tools: paths toward the comprehensive functional analysis of large gene lists meta: + yearPublished: 2009b publicationType: journal - type: Article id: bib61 @@ -4836,6 +4842,7 @@ references: pageStart: 50 title: Targeting the ubiquitin pathway for cancer treatment meta: + yearPublished: 2015a publicationType: journal - type: Article id: bib75 @@ -4880,6 +4887,7 @@ references: associations between human diseases, genes, drugs, metabolites, toxins and more meta: + yearPublished: 2015b publicationType: journal - type: Article id: bib76 diff --git a/src/codecs/jats/__file_snapshots__/elife-52882-v2.yaml b/src/codecs/jats/__file_snapshots__/elife-52882-v2.yaml index efaba0209..a7acb308f 100644 --- a/src/codecs/jats/__file_snapshots__/elife-52882-v2.yaml +++ b/src/codecs/jats/__file_snapshots__/elife-52882-v2.yaml @@ -1544,6 +1544,7 @@ references: title: Programs closed-loop phototaxis url: https://gitlab.com/Phiasso/programs_closed-loop_phototaxis.git meta: + yearPublished: 2019a publicationType: software - type: Article id: bib30 @@ -1562,6 +1563,7 @@ references: title: Analysis behavioral phototaxis url: https://gitlab.com/Phiasso/analysis.git meta: + yearPublished: 2019b publicationType: software - type: Article id: bib31 From 6993aa90f67680c5d9ffd2561f8485e4664d716d Mon Sep 17 00:00:00 2001 From: "A. K" <74007089+soggy-mushroom@users.noreply.github.com> Date: Thu, 24 Oct 2024 15:15:47 +0100 Subject: [PATCH 5/6] fix linter errors --- src/codecs/jats/index.ts | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/codecs/jats/index.ts b/src/codecs/jats/index.ts index b253ef880..297917041 100644 --- a/src/codecs/jats/index.ts +++ b/src/codecs/jats/index.ts @@ -1493,12 +1493,12 @@ export function decodeReference( ] if (identifiers.length === 0) identifiers = undefined - let metaEntries: Record = {}; + const metaEntries: Record = {} if (datePublishedString !== undefined && datePublishedString.length > 4) { - metaEntries.yearPublished = datePublishedString; + metaEntries.yearPublished = datePublishedString } - if(typeof label === 'string') { - metaEntries.label = label; + if (typeof label === 'string') { + metaEntries.label = label } return stencila.article({ @@ -1513,9 +1513,7 @@ export function decodeReference( identifiers, url, meta: { - ...(metaEntries - ? { ...metaEntries } - : {}), + ...(metaEntries ? { ...metaEntries } : {}), ...(publicationType ? { publicationType, From cd3311bd5248d3805391b23d069a0c6e75fe503f Mon Sep 17 00:00:00 2001 From: Will Byrne Date: Fri, 25 Oct 2024 11:10:41 +0100 Subject: [PATCH 6/6] update logic to handle n.d. case --- src/codecs/jats/index.ts | 5 ++++- src/codecs/jats/jats.test.ts | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/codecs/jats/index.ts b/src/codecs/jats/index.ts index 297917041..e224883ae 100644 --- a/src/codecs/jats/index.ts +++ b/src/codecs/jats/index.ts @@ -1494,7 +1494,10 @@ export function decodeReference( if (identifiers.length === 0) identifiers = undefined const metaEntries: Record = {} - if (datePublishedString !== undefined && datePublishedString.length > 4) { + if ( + datePublishedString !== undefined && + (datePublishedString.length > 4 || datePublished === undefined) + ) { metaEntries.yearPublished = datePublishedString } if (typeof label === 'string') { diff --git a/src/codecs/jats/jats.test.ts b/src/codecs/jats/jats.test.ts index e06ae9187..6831a2c60 100644 --- a/src/codecs/jats/jats.test.ts +++ b/src/codecs/jats/jats.test.ts @@ -252,6 +252,18 @@ test('decode: reference datePublished is added to meta.yearPublished to preserve expect(result.meta?.yearPublished).toEqual('2020a'); }); +test('decode: reference n.d. is parsed out of date published', () => { + const reference = ` + + Calabrese C, Panuzzo C et al (n.d.) Deferasirox-Dependent Iron Chelation Enhances Mitochondrial Dysfunction and Restores p53 Signaling by Stabilization of p53 Family Members in Leukemic Cells. International journal of molecular sciences 21 + + ` + const citation = xml.load(reference).elements?.[0]! + + const result = decodeReference(citation, null, undefined); + expect(result.meta?.yearPublished).toEqual('n.d.'); +}); + test('decode: element that has more than one ', () => { const fig = xml.load(`