Mobrovac has submitted this change and it was merged.
Change subject: Ensure page ranges use en dash
......................................................................
Ensure page ranges use en dash
* Replace hyphen minus with en dash in
coins translator.
* Validate Zotero pages field output
Bug: T113570
Change-Id: I4c162a3786f34e0612a71b9a43f8c064d0cc3db4
---
M lib/Exporter.js
M lib/translators/coins.js
M test/features/scraping/index.js
M test/features/scraping/noZotero.js
M test/features/unit/exporter.js
M test/features/unit/translators/coins.js
6 files changed, 66 insertions(+), 24 deletions(-)
Approvals:
Mobrovac: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/Exporter.js b/lib/Exporter.js
index ef95b7b..bccf161 100644
--- a/lib/Exporter.js
+++ b/lib/Exporter.js
@@ -394,11 +394,12 @@
var citation = cr.response.citation[0];
delete citation.itemKey;
delete citation.itemVersion;
- stripCitation(citation);
- fixURL(url, citation);
- fixAccessDate(citation);
- fixLang(citation);
- fixDate(citation);
+ citation = stripCitation(citation);
+ citation = fixURL(url, citation);
+ citation = fixAccessDate(citation);
+ citation = fixLang(citation);
+ citation = fixDate(citation);
+ citation = fixPages(citation);
//TODO: Possibly validate ISSN & ISBN / throw out duplicates
@@ -465,11 +466,26 @@
return citation;
}
+/**
+ * Replace and hyphen minuses with en dashes
+ * @param {Object} citation Zotero citation
+ * @return {Object} Zotero citation
+ */
+function fixPages(citation){
+ if (citation.pages){
+ citation.pages = citation.pages.replace('-', '–');
+ }
+ return citation;
+}
+
/* Exports */
module.exports = Exporter;
+
module.exports.validateZotero = validateZotero;
module.exports.addPubMedIdentifiers = addPubMedIdentifiers;
-module.exports.fixURL = fixURL;
module.exports.stripCitation = stripCitation;
+
module.exports.fixDate = fixDate;
module.exports.fixLang = fixLang;
+module.exports.fixPages = fixPages;
+module.exports.fixURL = fixURL;
diff --git a/lib/translators/coins.js b/lib/translators/coins.js
index 7caa8f1..ac3cf98 100644
--- a/lib/translators/coins.js
+++ b/lib/translators/coins.js
@@ -1,11 +1,10 @@
'use strict';
-
-var fixDate = require('../Exporter.js').fixDate;
-var makeTranslator = require('./util/index.js').makeTranslator;
-var generateCreatorObj = require('./util/index.js').generateCreatorObj;
var eg = require('./util/index.js').extendGeneral;
-
+var generateCreatorObj = require('./util/index.js').generateCreatorObj;
+var fixDate = require('../Exporter.js').fixDate;
+var fixPages = require('../Exporter.js').fixPages;
+var makeTranslator = require('./util/index.js').makeTranslator;
/**
* COinS 'genre' field values : Zotero type field values
@@ -212,10 +211,11 @@
}
// 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;
+ citation.pages = metadata.spage + '–' + metadata.epage;
}
return citation;
};
+
/**
* Add parameters in a list to a string
@@ -263,7 +263,7 @@
quarter: null,
part: null,
isbn: null, // Invalid Zotero field
- pages: makeTranslator('pages'),
+ pages: makeTranslator('pages', fixPages),
place: null, // Invalid Zotero field
series: makeTranslator('series'),
pub: makeTranslator('publisher')
@@ -283,7 +283,7 @@
edition: makeTranslator('edition'),
tpages: null, // Total pages
bici: null, // Book item and component identifier
- pages: makeTranslator('pages'),
+ pages: makeTranslator('pages', fixPages),
place: makeTranslator('place'),
series: makeTranslator('series'),
pub: makeTranslator('publisher')
@@ -300,7 +300,7 @@
atitle: makeTranslator('title'),
title: makeTranslator('proceedingsTitle'), // Deprecated
jtitle: makeTranslator('proceedingsTitle'),
- pages: makeTranslator('pages'),
+ pages: makeTranslator('pages', fixPages),
place: makeTranslator('place'),
series: makeTranslator('series'),
pub: makeTranslator('publisher')
@@ -318,7 +318,7 @@
btitle: makeTranslator('bookTitle'),
stitle: makeTranslator('shortTitle'),
edition: makeTranslator('edition'),
- pages: makeTranslator('pages'),
+ pages: makeTranslator('pages', fixPages),
place: makeTranslator('place'),
series: makeTranslator('series'),
pub: makeTranslator('publisher')
@@ -348,7 +348,7 @@
jtitle: makeTranslator('seriesTitle'),
stitle: makeTranslator('shortTitle'),
title: makeTranslator('seriesTitle'),
- pages: makeTranslator('pages'),
+ pages: makeTranslator('pages', fixPages),
place: makeTranslator('place'),
series: makeTranslator('seriesTitle'),
pub: makeTranslator('institution'),
diff --git a/test/features/scraping/index.js b/test/features/scraping/index.js
index 8808a75..79a32f1 100644
--- a/test/features/scraping/index.js
+++ b/test/features/scraping/index.js
@@ -70,7 +70,7 @@
assert.status(res, 200);
assert.checkZotCitation(res);
assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
- assert.deepEqual(res.body[0].pages, '1764-1772', 'Wrong pages
item; expected e1002947, got ' + res.body[0].pages);
+ assert.deepEqual(res.body[0].pages, '1764–1772', 'Wrong pages
item; expected e1002947, got ' + res.body[0].pages);
assert.deepEqual(res.body[0].itemType, 'journalArticle',
'Wrong itemType; expected journalArticle, got' + res.body[0].itemType);
});
});
@@ -81,7 +81,7 @@
assert.status(res, 200);
assert.checkZotCitation(res);
assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
- assert.deepEqual(res.body[0].pages, '1764-1772', 'Wrong pages
item; expected e1002947, got ' + res.body[0].pages);
+ assert.deepEqual(res.body[0].pages, '1764–1772', 'Wrong pages
item; expected e1002947, got ' + res.body[0].pages);
assert.deepEqual(res.body[0].itemType, 'journalArticle',
'Wrong itemType; expected journalArticle, got' + res.body[0].itemType);
});
});
@@ -187,12 +187,12 @@
});
});
- 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) {
+ it('fixes en dash in zotero results', function() {
+ return
server.query('http://onlinelibrary.wiley.com/doi/10.1111/j.2044-835X.1998.tb00748.x/abstract').then(function(res)
{
assert.status(res, 200);
- assert.checkZotCitation(res, 'Ueber einige Derivate des
Naphtylamins');
+ assert.checkZotCitation(res, 'Emotional instability as an
indicator of strictly timed infantile developmental transitions');
assert.deepEqual(!!res.body[0].DOI, true, 'Missing DOI');
- assert.deepEqual(!!res.body[0].pages, true, 'Missing pages');
+ assert.deepEqual(res.body[0].pages, '15–44');
assert.deepEqual(res.body[0].itemType, 'journalArticle',
'Wrong itemType; expected journalArticle, got' + res.body[0].itemType);
});
diff --git a/test/features/scraping/noZotero.js
b/test/features/scraping/noZotero.js
index 089ee6a..0882271 100644
--- a/test/features/scraping/noZotero.js
+++ b/test/features/scraping/noZotero.js
@@ -65,4 +65,15 @@
});
});
+ 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, '90–93', 'Missing pages'); //
Uses en dash
+ assert.deepEqual(res.body[0].itemType, 'journalArticle', 'Wrong
itemType; expected journalArticle, got' + res.body[0].itemType);
+
+ });
+ });
+
});
\ No newline at end of file
diff --git a/test/features/unit/exporter.js b/test/features/unit/exporter.js
index d000e30..33810a7 100644
--- a/test/features/unit/exporter.js
+++ b/test/features/unit/exporter.js
@@ -68,5 +68,12 @@
});
});
+ describe('fixPages function', function() {
+ it('converts hyphen minus to en dash', function() {
+ expected = {pages: '15–44'};
+ result = exporter.fixPages({pages:'15-44'});
+ assert.deepEqual(result, expected);
+ });
+ });
});
diff --git a/test/features/unit/translators/coins.js
b/test/features/unit/translators/coins.js
index f090e71..09a2a11 100644
--- a/test/features/unit/translators/coins.js
+++ b/test/features/unit/translators/coins.js
@@ -19,12 +19,20 @@
};
expected = {
itemType : 'bookSection',
- pages: '97-102'
+ pages: '97–102'
};
result = coins.other.spage({itemType: 'bookSection'}, metadata);
assert.deepEqual(result, expected);
});
+ it('Correctly fixes en dash in pages fields', function() {
+ expected = {
+ pages: '15–44'
+ };
+ result = coins.bookSection.pages.translate({}, '15-44');
+ assert.deepEqual(result, expected);
+ });
+
it('Correctly adds date', function() {
expected = {
date: '2010-01-01'
--
To view, visit https://gerrit.wikimedia.org/r/259983
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I4c162a3786f34e0612a71b9a43f8c064d0cc3db4
Gerrit-PatchSet: 6
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <[email protected]>
Gerrit-Reviewer: Mobrovac <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits