1- import { computeJaccardDistanceMatrix } from './computeJaccardDistanceMatrix'
1+ import computeDistanceMatrix from './computeDistanceMatrix'
2+ import getAllLemmasFromReflections from './getAllLemmasFromReflections'
23import getGroupMatrix from './getGroupMatrix'
4+ import getTitleFromComputedGroup from './getTitleFromComputedGroup'
5+
6+ /*
7+ * Read each reflection, parse the content for entities (i.e. nouns), group the reflections based on common themes
8+ */
39
410type Entity = {
511 lemma : string
@@ -21,70 +27,79 @@ export type GroupingOptions = {
2127 maxReductionPercent ?: number
2228}
2329
24- function groupReflections <
25- T extends { id : string ; reflectionGroupId : string ; plaintextContent : string }
26- > ( reflections : T [ ] , groupingOptions : GroupingOptions ) {
27- const reflectionTexts = reflections . map ( ( r ) => r . plaintextContent || '' )
28-
29- const distanceMatrix = computeJaccardDistanceMatrix ( reflectionTexts )
30+ const groupReflections = <
31+ T extends { entities : any [ ] ; reflectionGroupId : string ; id : string ; plaintextContent : string }
32+ > (
33+ reflections : T [ ] ,
34+ groupingOptions : GroupingOptions
35+ ) => {
36+ const allReflectionEntities = reflections . map ( ( { entities} ) => entities )
37+ const oldReflectionGroupIds = reflections . map ( ( { reflectionGroupId} ) => reflectionGroupId )
3038
39+ // create a unique array of all entity names mentioned in the meeting's reflect phase
40+ const uniqueLemmaArr = getAllLemmasFromReflections ( allReflectionEntities )
41+ // create a distance vector for each reflection
42+ const distanceMatrix = computeDistanceMatrix ( allReflectionEntities , uniqueLemmaArr )
3143 const {
3244 groups : groupedArrays ,
3345 thresh,
3446 nextThresh
3547 } = getGroupMatrix ( distanceMatrix , groupingOptions )
36-
37- const updatedReflections : Array < {
38- reflectionId : string
39- oldReflectionGroupId : string
40- sortOrder : number
41- reflectionGroupId : string
42- } > = [ ]
43-
44- const reflectionGroupMapping : Record < string , string > = { }
45- const oldReflectionGroupIds = reflections . map ( ( r ) => r . reflectionGroupId )
46-
48+ // replace the arrays with reflections
49+ const updatedReflections = [ ] as GroupedReflectionRes [ ]
50+ const reflectionGroupMapping = { } as Record < string , string >
4751 const updatedGroups = groupedArrays . map ( ( group ) => {
52+ // look up the reflection by its vector, put them all in the same group
4853 let reflectionGroupId = ''
49-
5054 const groupedReflectionsRes = group . map ( ( reflectionDistanceArr , sortOrder ) => {
5155 const idx = distanceMatrix . indexOf ( reflectionDistanceArr )
5256 const reflection = reflections [ idx ] !
5357 reflectionGroupId = reflectionGroupId || reflection . reflectionGroupId
5458 return {
5559 reflectionId : reflection . id ,
60+ entities : reflection . entities ,
5661 oldReflectionGroupId : reflection . reflectionGroupId ,
5762 sortOrder,
5863 reflectionGroupId
59- }
64+ } as GroupedReflectionRes
6065 } )
6166
67+ const groupedReflectionEntities = groupedReflectionsRes
68+ . map ( ( { entities} ) => entities )
69+ . filter ( Boolean )
70+ const smartTitle = getTitleFromComputedGroup (
71+ uniqueLemmaArr ,
72+ group ,
73+ groupedReflectionEntities ,
74+ reflections
75+ )
76+
6277 updatedReflections . push ( ...groupedReflectionsRes )
63- groupedReflectionsRes . forEach ( ( { oldReflectionGroupId} ) => {
64- reflectionGroupMapping [ oldReflectionGroupId ] = reflectionGroupId
78+
79+ groupedReflectionsRes . forEach ( ( groupedReflection ) => {
80+ reflectionGroupMapping [ groupedReflection . oldReflectionGroupId ] = reflectionGroupId
6581 } )
6682
6783 return {
6884 id : reflectionGroupId ,
69- smartTitle : '' ,
70- title : ''
85+ smartTitle,
86+ title : smartTitle
7187 }
7288 } )
7389
7490 const newReflectionGroupIds = new Set (
7591 updatedReflections . map ( ( { reflectionGroupId} ) => reflectionGroupId )
7692 )
7793 const removedReflectionGroupIds = oldReflectionGroupIds . filter (
78- ( oldId ) => ! newReflectionGroupIds . has ( oldId )
94+ ( groupId ) => ! newReflectionGroupIds . has ( groupId )
7995 )
80-
8196 return {
8297 autoGroupThreshold : thresh ,
8398 groups : updatedGroups ,
8499 groupedReflectionsRes : updatedReflections ,
85100 reflectionGroupMapping,
86101 removedReflectionGroupIds,
87- nextThresh
102+ nextThresh : nextThresh as number
88103 }
89104}
90105
0 commit comments