@ SuppressWarnings ( "unchecked" ) private static void updateEmotionTone ( Map < String , Object > user , List < ToneScore > emotionTone , boolean maintainHistory ) { Double maxScore = 0.0 ; String primaryEmotion = null ; Double primaryEmotionScore = null ; for ( ToneScore tone : emotionTone ) { if ( tone . getScore ( ) > maxScore ) { maxScore = tone . getScore ( ) ; primaryEmotion = tone . getToneName ( ) . toLowerCase ( ) ; primaryEmotionScore = tone . getScore ( ) ; } } if ( maxScore <= PRIMARY_EMOTION_SCORE_THRESHOLD ) { primaryEmotion = "neutral" ; primaryEmotionScore = null ; } // update user emotion tone Map < String , Object > emotion = ( Map < String , Object > ) ( ( Map < String , Object > ) ( user . get ( "tone" ) ) ) . get ( "emotion" ) ; emotion . put ( "current" , primaryEmotion ) ; if ( maintainHistory ) { List < Map < String , Object > > history = new ArrayList < Map < String , Object > > ( ) ; if ( emotion . get ( "history" ) != null ) { history = ( List < Map < String , Object > > ) emotion . get ( "history" ) ; } Map < String , Object > emotionHistoryObject = new HashMap < String , Object > ( ) ; emotionHistoryObject . put ( "tone_name" , primaryEmotion ) ; emotionHistoryObject . put ( "score" , primaryEmotionScore ) ; history . add ( emotionHistoryObject ) ; emotion . put ( "history" , history ) ; } }
updateEmotionTone updates the user emotion tone with the primary emotion - the emotion tone that has a score greater than or equal to the EMOTION_SCORE_THRESHOLD ; otherwise primary emotion will be neutral .