pid-parser-service/parsers/Crossref.js

61 lines
1.5 KiB
JavaScript

const Entity = require("../model/Entity");
class Crossref {
parse(pid, item) {
let entity = new Entity(pid);
entity.result.source = "crossref";
entity.DOI = pid;
entity.title = item.title;
entity.result.url = item.URL;
entity.type = 'publication';
if (item['indexed']) {
entity.result.date = item['created']['date-parts'][0][0];
}
entity.result.accessRights = "OPEN";
entity.result.publisher = item.publisher;
entity.result.journal = null;
entity.result.description = item.abstract;
if (item.author) {
entity.result.authors = [];
for (let j = 0; j < item.author.length; j++) {
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++) {
let editor = this.parseName(item.editor[j]);
if (editor) {
entity.result.authors.push(editor);
}
}
}
return entity;
}
parseName(authorObj) {
let author = "";
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;
}
}
module.exports = Crossref;