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} values Array 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'); + assert.deepEqual(!!res.body[0].pages, true, 'Missing pages'); + assert.deepEqual(res.body[0].itemType, 'journalArticle', 'Wrong itemType; expected journalArticle, got' + res.body[0].itemType); + + }); + }); + // The following tests require the WMF fork of the zotero translators, as found // here: https://gerrit.wikimedia.org/r/mediawiki/services/zotero/translators describe(' uses WMF translator fork', function() { diff --git a/test/features/unit/coins.js b/test/features/unit/coins.js index b04b583..3c47964 100644 --- a/test/features/unit/coins.js +++ b/test/features/unit/coins.js @@ -7,6 +7,20 @@ var result; var expected; var input; + var metadata; + + it('Correctly adds pages from spage and epage', function(){ + metadata = { + spage : '97', + epage : '102' + }; + expected = { + itemType : 'bookSection', + pages: '97-102' + }; + result = coins.other.spage({itemType: 'bookSection'}, metadata); + assert.deepEqual(result, expected); + }); it('Correctly adds date', function() { expected = { -- To view, visit https://gerrit.wikimedia.org/r/237385 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Ic307c6112fe1c30c3fe78e79646fa64ebaac6388 Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/services/citoid Gerrit-Branch: master Gerrit-Owner: Mvolz <mv...@wikimedia.org> Gerrit-Reviewer: Mobrovac <mobro...@wikimedia.org> Gerrit-Reviewer: Mvolz <mv...@wikimedia.org> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits