Skip to content

Commit

Permalink
fix(openalex): Use "affiliations" instead of "raw_affiliations_string…
Browse files Browse the repository at this point in the history
…s" in OpenAlex API /2
  • Loading branch information
annelhote committed Nov 13, 2024
1 parent 1554bd1 commit 2171b96
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions server/src/utils/works.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,9 @@ const getTypeFromOpenAlex = (type) => {
return newType;
};

const getOpenAlexAffiliation = (author) => {
const getOpenAlexAffiliations = (work) => {
const source = 'OpenAlex';
return author.affiliations.map((affiliation) => {
const affiliations = work.authorships.map((author) => author.affiliations.map((affiliation) => {
const rawAffiliation = affiliation.raw_affiliation_string;
let key = removeDiacritics(rawAffiliation).concat(' [ source: ').concat(source).concat(' ]');
const label = removeDiacritics(rawAffiliation).concat(' [ source: ').concat(source).concat(' ]');
Expand All @@ -337,7 +337,9 @@ const getOpenAlexAffiliation = (author) => {
}
return { key, label, rawAffiliation, rors, rorsToCorrect, source };
});
});
}));
// TODO: recursive flat
return affiliations.flat().flat().flat().filter((affiliation) => !!affiliation.rawAffiliation);
};

const getOpenAlexPublicationsByYear = (options, cursor = '*', previousResponse = [], remainingTries = 3) => {
Expand Down Expand Up @@ -379,10 +381,7 @@ const getOpenAlexPublicationsByYear = (options, cursor = '*', previousResponse =
const hits = response?.results ?? [];
const results = previousResponse.concat(hits.map((result) => {
const answer = {
affiliations: result?.authorships
?.map((author) => getOpenAlexAffiliation(author))
.flat()
.filter((affiliation) => !!affiliation.rawAffiliation),
affiliations: getOpenAlexAffiliations(result),
allIds: Object.keys(result.ids).map((key) => ({ id_type: key, id_value: cleanId(result.ids[key]) })),
authors: result?.authorships?.map((author) => author.author.display_name),
datasource: ['openalex'],
Expand Down

0 comments on commit 2171b96

Please sign in to comment.