[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.

This commit is contained in:
Konstantina Galouni 2021-11-11 12:13:25 +02:00
parent cf08054ab5
commit d635949909
2 changed files with 30 additions and 3 deletions

View File

@ -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;
}
}

View File

@ -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);