[MediaWiki-commits] [Gerrit] Use spage and epage in coins metadata - change (mediawiki...citoid)
Mobrovac has submitted this change and it was merged. Change subject: Use spage and epage in coins metadata .. Use spage and epage in coins metadata Use spage and epage fields in coins metadata to create pages field from crossRef. Bug: T107647 Change-Id: Ic307c6112fe1c30c3fe78e79646fa64ebaac6388 --- M lib/Scraper.js M lib/translators/coins.js M test/features/scraping/index.js M test/features/unit/coins.js 4 files changed, 47 insertions(+), 10 deletions(-) Approvals: Mobrovac: Looks good to me, approved diff --git a/lib/Scraper.js b/lib/Scraper.js index 94a6128..f69a8cd 100644 --- a/lib/Scraper.js +++ b/lib/Scraper.js @@ -294,6 +294,7 @@ // Add universal (non genre specific) coins properties citation = coins.general.addAuthors(citation, metadata); + citation = coins.other.spage(citation, metadata); citation = translate(citation, metadata, coins.general); // Add type specific coins properties diff --git a/lib/translators/coins.js b/lib/translators/coins.js index fdb9b6e..b233887 100644 --- a/lib/translators/coins.js +++ b/lib/translators/coins.js @@ -184,6 +184,27 @@ }; /** + * Convert spage and epage fields to Zotero pages + * + * This function does not get used in the translate function- + * it must be called explicitly. Citation itemType must + * already be set before calling. + * + * @type {Function} + */ +exports.other.spage = function(citation, metadata){ + if (!citation.itemType || metadata.pages || !metadata.spage || !metadata.epage || + typeof metadata.spage !== 'string' || typeof metadata.epage !== 'string'){ + return citation; + } + // Add page range if pages is a valid field for the type + if (['journalArticle', 'book', 'conferencePaper','bookSection', 'report'].indexOf(citation.itemType) >= 0) { + citation.pages = metadata.spage + '-' + metadata.epage; + } + return citation; +}; + +/** * Add parameters in a list to a string * @param {Object}citation citation object * @param {Array} valuesArray of string values @@ -229,8 +250,6 @@ quarter: null, part: null, isbn: null, // Invalid Zotero field - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: null, // Invalid Zotero field series: makeTranslator('series'), @@ -251,8 +270,6 @@ edition: makeTranslator('edition'), tpages: null, // Total pages bici: null, // Book item and component identifier - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('series'), @@ -270,8 +287,6 @@ atitle: makeTranslator('title'), title: makeTranslator('proceedingsTitle'), // Deprecated jtitle: makeTranslator('proceedingsTitle'), - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('series'), @@ -290,8 +305,6 @@ btitle: makeTranslator('bookTitle'), stitle: makeTranslator('shortTitle'), edition: makeTranslator('edition'), - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('series'), @@ -322,8 +335,6 @@ jtitle: makeTranslator('seriesTitle'), stitle: makeTranslator('shortTitle'), title: makeTranslator('seriesTitle'), - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('seriesTitle'), diff --git a/test/features/scraping/index.js b/test/features/scraping/index.js index 67adc7f..75ce5be 100644 --- a/test/features/scraping/index.js +++ b/test/features/scraping/index.js @@ -187,6 +187,17 @@ }); }); + it('doi spage and epage fields in crossRef coins data', function() { + return server.query('http://dx.doi.org/10.1002/jlac.18571010113').then(function(res) { + assert.status(res, 200); + assert.checkZotCitation(res, 'Ueber einige Derivate des Naphtylamins'); + assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI'); +
[MediaWiki-commits] [Gerrit] Use spage and epage in coins metadata - change (mediawiki...citoid)
Mvolz has uploaded a new change for review. https://gerrit.wikimedia.org/r/237385 Change subject: Use spage and epage in coins metadata .. Use spage and epage in coins metadata Use spage and epage fields in coins metadata to create pages field from crossRef. Bug: T107647 Change-Id: Ic307c6112fe1c30c3fe78e79646fa64ebaac6388 --- M lib/Scraper.js M lib/translators/coins.js M test/features/scraping/index.js M test/features/unit/coins.js 4 files changed, 47 insertions(+), 10 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid refs/changes/85/237385/1 diff --git a/lib/Scraper.js b/lib/Scraper.js index 94a6128..f69a8cd 100644 --- a/lib/Scraper.js +++ b/lib/Scraper.js @@ -294,6 +294,7 @@ // Add universal (non genre specific) coins properties citation = coins.general.addAuthors(citation, metadata); + citation = coins.other.spage(citation, metadata); citation = translate(citation, metadata, coins.general); // Add type specific coins properties diff --git a/lib/translators/coins.js b/lib/translators/coins.js index fdb9b6e..b233887 100644 --- a/lib/translators/coins.js +++ b/lib/translators/coins.js @@ -184,6 +184,27 @@ }; /** + * Convert spage and epage fields to Zotero pages + * + * This function does not get used in the translate function- + * it must be called explicitly. Citation itemType must + * already be set before calling. + * + * @type {Function} + */ +exports.other.spage = function(citation, metadata){ + if (!citation.itemType || metadata.pages || !metadata.spage || !metadata.epage || + typeof metadata.spage !== 'string' || typeof metadata.epage !== 'string'){ + return citation; + } + // Add page range if pages is a valid field for the type + if (['journalArticle', 'book', 'conferencePaper','bookSection', 'report'].indexOf(citation.itemType) >= 0) { + citation.pages = metadata.spage + '-' + metadata.epage; + } + return citation; +}; + +/** * Add parameters in a list to a string * @param {Object}citation citation object * @param {Array} valuesArray of string values @@ -229,8 +250,6 @@ quarter: null, part: null, isbn: null, // Invalid Zotero field - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: null, // Invalid Zotero field series: makeTranslator('series'), @@ -251,8 +270,6 @@ edition: makeTranslator('edition'), tpages: null, // Total pages bici: null, // Book item and component identifier - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('series'), @@ -270,8 +287,6 @@ atitle: makeTranslator('title'), title: makeTranslator('proceedingsTitle'), // Deprecated jtitle: makeTranslator('proceedingsTitle'), - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('series'), @@ -290,8 +305,6 @@ btitle: makeTranslator('bookTitle'), stitle: makeTranslator('shortTitle'), edition: makeTranslator('edition'), - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('series'), @@ -322,8 +335,6 @@ jtitle: makeTranslator('seriesTitle'), stitle: makeTranslator('shortTitle'), title: makeTranslator('seriesTitle'), - spage: null, // Start page // TODO: Add function to use this - epage: null, // end page // TODO: Add function to use this pages: makeTranslator('pages'), place: makeTranslator('place'), series: makeTranslator('seriesTitle'), diff --git a/test/features/scraping/index.js b/test/features/scraping/index.js index 696b9b0..09cdb26 100644 --- a/test/features/scraping/index.js +++ b/test/features/scraping/index.js @@ -187,6 +187,17 @@ }); }); + it('doi spage and epage fields in crossRef coins data', function() { + return server.query('http://dx.doi.org/10.1002/jlac.18571010113').then(function(res) { + assert.status(res, 200); + assert.checkZotCitation(res, 'Ueber einige Derivate des Naphtylamins'); +