diff --git a/server/src/routes/scanr/scanr-to-data.js b/server/src/routes/scanr/scanr-to-data.js index 3d352c7b..8837813a 100644 --- a/server/src/routes/scanr/scanr-to-data.js +++ b/server/src/routes/scanr/scanr-to-data.js @@ -3,9 +3,8 @@ import { dataToGraphology } from '../../graphology/graph'; function getNodesFromPublicationList(publicationList) { return publicationList.flatMap(({ authors, id: publicationId }) => { if (!authors) return []; - return authors.reduce((acc, { person }) => { - if (!person?.id) return acc; - const { id: authorId, fullName: name } = person; + return authors.filter((author) => author?.person).reduce((acc, author) => { + const { person: authorId, fullName: name } = author; return [...acc, { id: authorId, attributes: { id: authorId, name, publicationId } }]; }, []); }); @@ -14,7 +13,7 @@ function getNodesFromPublicationList(publicationList) { function getEdgesFromPublicationList(publicationList) { return publicationList.flatMap(({ authors }) => { if (!authors) return []; - const knownAuthors = authors.filter(({ person }) => person?.id).map(({ person }) => person.id); + const knownAuthors = authors.filter((author) => author?.person).map((author) => author.person); const coAuthorships = knownAuthors.flatMap( // Graphology undirected edges must be sorted, to avoid duplicated edges. (v, i) => knownAuthors.slice(i + 1).map((w) => (w < v ? { source: w, target: v } : { source: v, target: w })), @@ -34,7 +33,6 @@ export function scanrToPublications(publicationList) { const publications = {}; publicationList.forEach((publication) => { - // console.log('publication', publication); if ('id' in publication) { const topics = publication?.domains?.filter((domain) => domain.type === 'wikidata') .reduce( @@ -44,7 +42,8 @@ export function scanrToPublications(publicationList) { ]), [], ); - const affiliationIds = publication?.affiliations?.reduce((acc, { id: affiliationId }) => ([...acc, affiliationId]), []); + const affiliationIds = publication?.affiliations?.filter((affiliation) => affiliation.id && affiliation.label) + .map((affiliation) => affiliation.id); publications[publication.id] = { id: publication.id, @@ -67,7 +66,7 @@ export function scanrToStructures(publicationList) { publicationList.forEach(({ affiliations = [] }) => { if (affiliations) { affiliations.forEach(({ id, label, address = [] }) => { - if (!(id in structures)) { + if (id && !(id in structures) && label) { structures[id] = { name: label.default.toLowerCase(), country: address[0]?.country ?? 'undefined',