Skip to content

Commit

Permalink
fix(scanr): adjustments with new scanr api
Browse files Browse the repository at this point in the history
  • Loading branch information
ahonestla committed Nov 30, 2023
1 parent 509fa84 commit f3e34fa
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions server/src/routes/scanr/scanr-to-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 } }];
}, []);
});
Expand All @@ -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 })),
Expand All @@ -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(
Expand All @@ -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,
Expand All @@ -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',
Expand Down

0 comments on commit f3e34fa

Please sign in to comment.