[Library]: searchDatacite.service.ts & searchCrossref.service.ts: [Bug fix] Extra checks added in author parsing | In Crossref parse author.name if author.family and/or author.given is missing.

deprecated-master
Konstantina Galouni 2 years ago
parent cf08054ab5
commit d635949909

@ -78,12 +78,18 @@ export class SearchCrossrefService {
if (item.author) {
entity.result.authors = [];
for (let j = 0; j < item.author.length; j++) {
entity.result.authors.push(item.author[j].family + ", " + item.author[j].given);
let author = this.parseName(item.author[j]);
if(author) {
entity.result.authors.push(author);
}
}
}
if (item.editor) {
for (let j = 0; j < item.editor.length; j++) {
entity.result.editors.push(item.editor[j].family + ", " + item.editor[j].given);
let editor = this.parseName(item.editor[j]);
if(editor) {
entity.result.authors.push(editor);
}
}
}
results.push(entity);
@ -93,4 +99,23 @@ export class SearchCrossrefService {
}
private parseName(authorObj) : string {
let author: string = "";
if(authorObj.hasOwnProperty("family")) {
author += authorObj.family;
}
if(authorObj.hasOwnProperty("family") && authorObj.hasOwnProperty("given")) {
author += ", ";
}
if(authorObj.hasOwnProperty("given")) {
author += authorObj.given;
}
if(!author && authorObj.hasOwnProperty("name")) {
author += authorObj.name;
}
return author;
}
}

@ -68,7 +68,9 @@ export class SearchDataciteService {
entity.result.authors = [];
for (let j = 0; j < item.attributes.author.length; j++) {
const author = item.attributes.author[j];
entity.result.authors.push((author.family) ? author.family + ', ' + author.given : author.literal);
if(author.family || author.literal) {
entity.result.authors.push((author.family) ? author.family + (author.given ? ', ' + author.given : '') : author.literal);
}
}
}
results.push(entity);

Loading…
Cancel
Save