Commit cb24e106 authored by Maxime Chaillet's avatar Maxime Chaillet

in a single string authors name, detect first name and family name when there are only 2 words.

parent 77ba535b
This diff is collapsed.
......@@ -186,12 +186,14 @@ function extractFieldsFromDoi(data) {
// on how to cite this work.
//@data: the data object, it is a reference
function createCitation(data) {
// Authors sent in json can be in several format. The following call find first name and last name when possible.
// It writes a message in the console in case it fails identifyng them in which case the string containing first anme and last name will
// be displayed as it came from json.
var authorList = _.transform(data.creator, function(result, obj) {
if (obj.givenName) {
result.push(obj.familyName + ' ' + obj.givenName);
} else {
// cells of data.creator.name contains First Name FAMILY NAME most of the time.
// Here first name and last name are in a single string creator.name
// 1 - detect the words in UPPERCASE as FAMILY name
// 2 - detect the words in lowercase except first letter which can optionally be uppercase.
// 3 - flip them
......@@ -201,9 +203,21 @@ function createCitation(data) {
var familyName = familyRegExp.exec(obj.name);
var firstName = firstNameRegExp.exec(obj.name);
// Sometime all words are uppercase or lowercase or uppercase for the first letter only. In this case we can not distinguish between family name and firstname. => string unchanged
if (!familyName || !firstName ){
result.push(obj.name);
// Sometime all words are uppercase or lowercase or uppercase for the first letter only. In this case
// we can not distinguish between family name and firstname if there are more than 2 words.
// => string unchanged
var findWordsRegExp = new RegExp(/(\S+)/g);
var wordTable = obj.name.match(findWordsRegExp);
if (wordTable.length === 2){
result.push(wordTable[1] + " " + wordTable[0]);
} else {
// there are not 2 words so it is not possible to distingues first name and family name
result.push(obj.name);
}
} else {
result.push(familyName[1] + " " + firstName[0].trim());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment