Mvolz has uploaded a new change for review.
https://gerrit.wikimedia.org/r/313807
Change subject: Fixes to open graph translator
......................................................................
Fixes to open graph translator
* Use site_name parameter in more itemTypes
* Change article itemType to newspaperArticle from
blogPost
* Minor assert change
Bug: T147079
Change-Id: I2a9cede0925fd3834a00bfd7709dc2c1f93edc7c
---
M lib/translators/openGraph.js
M test/features/scraping/index.js
M test/utils/assert.js
3 files changed, 64 insertions(+), 18 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/services/citoid
refs/changes/07/313807/1
diff --git a/lib/translators/openGraph.js b/lib/translators/openGraph.js
index c2f866b..742dfc1 100644
--- a/lib/translators/openGraph.js
+++ b/lib/translators/openGraph.js
@@ -5,6 +5,7 @@
var fixDate = ex.fixDate;
var fixLang = ex.fixLang;
+var vISBN = ex.validateISBN;
/**
* Open graph type field values : Zotero type field values
@@ -12,7 +13,7 @@
*/
exports.types = {
website: 'webpage',
- article: 'blogPost', // May change to journalArticle, newspaperArticle,
magazineArticle
+ article: 'newspaperArticle', // Previously blogPost, could also be
newspaperArticle or magazineArticle
book: 'book',
profile: 'webpage', // May be possible to obtain more information from
this link a.k.a. names
'music.song': 'audioRecording',
@@ -55,13 +56,20 @@
};
exports.audioRecording = Object.assign({}, exports.general, {
release_date: makeTranslator('date',fixDate), // only present in
music.album
- isbn: makeTranslator('ISBN')
+ isbn: makeTranslator('ISBN', vISBN)
});
exports.bill = exports.generalWithDate;
-exports.blogPost = exports.generalWithDate;
+exports.blogPost = {
+ title: makeTranslator('title'), // general OG property, common to all
Zotero types
+ url: makeTranslator('url'), // general OG property, common to all Zotero
types
+ description: makeTranslator('abstractNote'), // general OG property,
abstractNote common to all Zotero types
+ locale: makeTranslator('language', fixLang), // general OG property,
common to all Zotero types
+ published_time: makeTranslator('date', fixDate),
+ site_name: makeTranslator('blogTitle')
+};
exports.book = Object.assign({}, exports.general, {
release_date: makeTranslator('date', fixDate),
- isbn: makeTranslator('ISBN')
+ isbn: makeTranslator('ISBN', vISBN)
});
exports.bookSection = exports.book;
exports['case'] = {
@@ -77,11 +85,17 @@
isbn: makeTranslator('ISBN')
};
exports.conferencePaper = Object.assign({}, exports.general, {
- isbn: makeTranslator('ISBN')
+ isbn: makeTranslator('ISBN', vISBN)
});
-exports.dictionaryEntry = Object.assign({}, exports.general, {
- isbn: makeTranslator('ISBN')
-});
+exports.dictionaryEntry = {
+ title: makeTranslator('title'), // general OG property, common to all
Zotero types
+ url: makeTranslator('url'), // general OG property, common to all Zotero
types
+ description: makeTranslator('abstractNote'), // general OG property,
abstractNote common to all Zotero types
+ locale: makeTranslator('language', fixLang), // general OG property,
common to all Zotero types
+ published_time: makeTranslator('date', fixDate),
+ site_name: makeTranslator('dictionaryTitle'),
+ isbn: makeTranslator('ISBN', vISBN)
+};
exports.document = exports.generalWithDate;
exports.email = {
title: makeTranslator('subject'),
@@ -91,25 +105,46 @@
published_time: makeTranslator('date', fixDate),
release_date: makeTranslator('date', fixDate)
};
-exports.encyclopediaArticle = Object.assign({}, exports.general, {
- isbn: makeTranslator('ISBN')
-});
+exports.encyclopediaArticle = {
+ title: makeTranslator('title'), // general OG property, common to all
Zotero types
+ url: makeTranslator('url'), // general OG property, common to all Zotero
types
+ description: makeTranslator('abstractNote'), // general OG property,
abstractNote common to all Zotero types
+ locale: makeTranslator('language', fixLang), // general OG property,
common to all Zotero types
+ published_time: makeTranslator('date', fixDate),
+ site_name: makeTranslator('encyclopediaTitle'),
+ isbn: makeTranslator('ISBN', vISBN)
+};
exports.film = Object.assign({}, exports.general, {
duration: makeTranslator('runningTime'),
release_date: makeTranslator('date', fixDate)
});
-exports.forumPost = exports.generalWithDate;
+exports.forumPost = {
+ title: makeTranslator('title'), // general OG property, common to all
Zotero types
+ url: makeTranslator('url'), // general OG property, common to all Zotero
types
+ description: makeTranslator('abstractNote'), // general OG property,
abstractNote common to all Zotero types
+ locale: makeTranslator('language', fixLang), // general OG property,
common to all Zotero types
+ published_time: makeTranslator('date', fixDate),
+ site_name: makeTranslator('forumTitle'),
+ isbn: makeTranslator('ISBN', vISBN)
+};
exports.hearing = exports.generalWithDate;
exports.instantMessage = exports.generalWithDate;
exports.interview = exports.generalWithDate;
-exports.journalArticle = exports.generalWithDate;
+exports.journalArticle = {
+ title: makeTranslator('title'), // general OG property, common to all
Zotero types
+ url: makeTranslator('url'), // general OG property, common to all Zotero
types
+ description: makeTranslator('abstractNote'), // general OG property,
abstractNote common to all Zotero types
+ locale: makeTranslator('language', fixLang), // general OG property,
common to all Zotero types
+ published_time: makeTranslator('date', fixDate),
+ site_name: makeTranslator('publicationTitle')
+};
exports.letter = exports.generalWithDate;
-exports.magazineArticle = exports.generalWithDate;
+exports.magazineArticle = exports.journalArticle;
exports.manuscript = exports.generalWithDate;
exports.map = Object.assign({}, exports.general, {
- isbn: makeTranslator('ISBN')
+ isbn: makeTranslator('ISBN', vISBN)
});
-exports.newspaperArticle = exports.generalWithDate;
+exports.newspaperArticle = exports.journalArticle;
exports.note = {}; // Has no fields
exports.patent = exports.general;
exports.podcast = exports.general;
@@ -125,7 +160,7 @@
exports.thesis = exports.generalWithDate;
exports.tvBroadcast = exports.generalWithDate;
exports.videoRecording = Object.assign({}, exports.film, {
- isbn: makeTranslator('ISBN')
+ isbn: makeTranslator('ISBN', vISBN)
});
exports.webpage = Object.assign({}, exports.generalWithDate, {
site_name: makeTranslator('websiteTitle') // prefix og: general property,
but should only be assigned if type webpage is used
diff --git a/test/features/scraping/index.js b/test/features/scraping/index.js
index 668d05b..3853c36 100644
--- a/test/features/scraping/index.js
+++ b/test/features/scraping/index.js
@@ -306,6 +306,17 @@
});
});
+ // itemType from open graph
+ it('itemType from open graph', function() {
+ return
server.query('http://www.aftenposten.no/kultur/Pinlig-for-Skaber-555558b.html').then(function(res)
{
+ assert.status(res, 200);
+ assert.checkCitation(res, 'Pinlig for Skåber');
+ assert.isInArray(res.body[0].source, 'citoid');
+ assert.deepEqual(res.body[0].itemType, 'newspaperArticle');
+ assert.deepEqual(res.body[0].publicationTitle, 'Aftenposten')
+ });
+ });
+
});
});
diff --git a/test/utils/assert.js b/test/utils/assert.js
index f2e7049..15436be 100644
--- a/test/utils/assert.js
+++ b/test/utils/assert.js
@@ -108,7 +108,7 @@
// Assert that expected value is an element of an array.
function isInArray(arr, expected) {
if(!Array.isArray(arr)){
- throw new Error('Expected array, got ' + arr); // If arr is undefined
will throw undefined error instead
+ throw new Error('Expected array, got ' + typeof arr + ' ' + arr); //
If arr is undefined will throw undefined error instead
}
assert.notDeepEqual(arr.indexOf(expected), -1);
}
--
To view, visit https://gerrit.wikimedia.org/r/313807
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I2a9cede0925fd3834a00bfd7709dc2c1f93edc7c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/services/citoid
Gerrit-Branch: master
Gerrit-Owner: Mvolz <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits