-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
297 additions
and
175 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,82 @@ | ||
export function communityGetTopicsCount(community, publications, limit = 0) { | ||
const communityGetUniquePublications = (community) => ( | ||
community.reduce((acc, node) => [...acc, ...node.attributes.publications.flatMap((id) => (!acc.includes(id) ? id : []))], []) | ||
); | ||
|
||
function communityGetTopicsCount(community, publications, limit = 0) { | ||
const topics = {}; | ||
|
||
// Count topics | ||
community.forEach((node) => { | ||
node.attributes.publications.forEach((publicationId) => { | ||
publications[publicationId]?.topics.forEach(({ label }) => { topics[label] = topics[label] + 1 || 1; }); | ||
}); | ||
// Count topics from unique publication ids | ||
community.reduce((acc, node) => [...acc, ...node.attributes.publications.flatMap((id) => (!acc.includes(id) ? id : []))], []).forEach((id) => { | ||
publications[id]?.topics?.forEach(({ label }) => { topics[label] = topics[label] + 1 || 1; }); | ||
}); | ||
|
||
const numberOfTopics = Object.keys(topics).length; | ||
if (numberOfTopics === 0) return []; | ||
|
||
// Get max topics | ||
// @todo | ||
const endSlice = limit > 0 ? limit : numberOfTopics; | ||
const topTopics = Object.assign( | ||
...Object | ||
.entries(topics) | ||
.sort(({ 1: a }, { 1: b }) => b - a) | ||
.slice(0, endSlice) | ||
.map(([k, v]) => ({ [k]: v })), | ||
); | ||
|
||
return Object.entries(topTopics); | ||
} | ||
|
||
function communityGetTypesCount(community, publications, limit = 0) { | ||
const types = {}; | ||
|
||
// Count types from unique publication ids | ||
community.reduce((acc, node) => [...acc, ...node.attributes.publications.flatMap((id) => (!acc.includes(id) ? id : []))], []).forEach((id) => { | ||
types[publications[id].type] = types[publications[id].type] + 1 || 1; | ||
}); | ||
|
||
const numberOfTypes = Object.keys(types).length; | ||
// console.log('numberOfTopics', numberOfTopics); | ||
|
||
if (numberOfTypes === 0) return []; | ||
|
||
// Get max types | ||
const endSlice = limit > 0 ? limit : numberOfTypes; | ||
const topTypes = Object.assign( | ||
...Object | ||
.entries(types) | ||
.sort(({ 1: a }, { 1: b }) => b - a) | ||
.slice(0, endSlice) | ||
.map(([k, v]) => ({ [k]: v })), | ||
); | ||
|
||
return Object.entries(topTypes); | ||
} | ||
|
||
function communityGetBestAuthors(community, limit = 0) { | ||
const endSlice = limit > 0 ? limit : community.length; | ||
// Count and sort coauthors | ||
return community.sort((a, b) => b.attributes.publications.length - a.attributes.publications.length).slice(0, endSlice); | ||
} | ||
|
||
export function fillAndSortCommunities(communities, publications, { communitiesLimit = 0, topicsLimit = 0, typesLimit = 0, authorsLimit = 0 }) { | ||
const filledCommunities = {}; | ||
const numberOfCommunities = Object.keys(communities).length; | ||
const endSlice = communitiesLimit > 0 ? communitiesLimit : numberOfCommunities; | ||
|
||
// Sort communities | ||
const sortedCommunities = Object.entries(communities).sort((a, b) => b[1].length - a[1].length).slice(0, endSlice); | ||
|
||
// Fill communities | ||
sortedCommunities.forEach(([key, values]) => { | ||
filledCommunities[key] = { | ||
nodes: values, | ||
size: values.length, | ||
publications: communityGetUniquePublications(values), | ||
topics: communityGetTopicsCount(values, publications, topicsLimit), | ||
types: communityGetTypesCount(values, publications, typesLimit), | ||
authors: communityGetBestAuthors(values, authorsLimit), | ||
}; | ||
}); | ||
|
||
return Object.entries(topics); | ||
return filledCommunities; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,28 @@ | ||
export function publicationGetTopicsCount(publications, id, limit = 0) { | ||
export function publicationsGetTopicsCount(publications, publicationsIds, limit = 0) { | ||
const topics = {}; | ||
|
||
// Count topics | ||
publications[id]?.topics.forEach(({ label }) => { | ||
topics[label] = topics[label] + 1 || 1; | ||
}); | ||
publicationsIds.forEach((publicationId) => ( | ||
publications[publicationId]?.topics.forEach(({ label }) => { | ||
topics[label] = topics[label] + 1 || 1; | ||
}))); | ||
|
||
const numberOfTopics = Object.keys(topics).length; | ||
// console.log('numberOfTopics', numberOfTopics); | ||
|
||
if (numberOfTopics === 0) return []; | ||
|
||
console.log('topics: ', topics); | ||
|
||
// Get max topics | ||
// @todo | ||
const endSlice = limit > 0 ? limit : numberOfTopics; | ||
const topTopics = Object.assign( | ||
...Object | ||
.entries(topics) | ||
.sort(({ 1: a }, { 1: b }) => b - a) | ||
.slice(0, endSlice) | ||
.map(([k, v]) => ({ [k]: v })), | ||
); | ||
|
||
return Object.entries(topics); | ||
return Object.entries(topTopics); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.