Exemplo n.º 1
0
def _add_emotions_from_words(
        words: Set[Optional[str]], words_emotions: Dict[str, List[Emotion]],
        seasons_episodes_subtitles_emotions: Dict[int, Dict[int, List[TimeEmotion]]],
        index: Tuple[int, int, int]) -> None:
    season, episode, seconds = index
    for word in [x for x in words if x]:
        for emotion in words_emotions[word]:
            seasons_episodes_subtitles_emotions[season][episode].append(
                TimeEmotion(seconds=seconds, emotion=emotion))
Exemplo n.º 2
0
def _add_emotions_from_sentence(
        limbic_model: LexiconLimbicModel,
        seasons_episodes_subtitles_emotions: Dict[int, Dict[int, List[TimeEmotion]]],
        season_episode_time_sentence: Dict[int, Dict[int, Dict[int, List[str]]]],
        index: Tuple[int, int, int]) -> None:
    season, episode, seconds = index
    for sentence in season_episode_time_sentence[season][episode][seconds]:
        for emotion in limbic_model.get_sentence_emotions(sentence):
            seasons_episodes_subtitles_emotions[season][episode].append(
                TimeEmotion(seconds=seconds, emotion=emotion))
Exemplo n.º 3
0
def get_subtitles_emotions(subtitles: List[Subtitle],
                           limbic_model: LexiconLimbicModel) -> Iterable[TimeEmotion]:
    """
    Get emotions per second using TimeEmotion named tuple.
    Each term per subtitle line is processed, and all emotions within a term
    is listed independently.

    Note that a given emotion will be mapped to the start of the subtitle time.
    """
    for sub in subtitles:
        for emotion in limbic_model.get_sentence_emotions(sub.content):
            yield TimeEmotion(seconds=sub.start.seconds, emotion=emotion)
Exemplo n.º 4
0
def _season_episode_emotions_from_dict(
        season_episode_emotions_dict: Dict[str, Any]) -> Dict[int, Dict[int, List[TimeEmotion]]]:
    """
    Utility method used to generate TimeEmotion from a dictionary with TimeEmotion data for a
    series with season and episodes.
    """
    output: Dict[int, Dict[int, List[TimeEmotion]]] = defaultdict(lambda: defaultdict(list))
    for season, season_data in season_episode_emotions_dict.items():
        for episode, episode_data in season_data.items():
            for emotion in episode_data:
                output[int(season)][int(episode)].append(
                    TimeEmotion(
                        seconds=emotion.get('seconds'),
                        emotion=Emotion(
                            category=emotion.get('category'),
                            value=emotion.get('value'),
                            term=emotion.get('term'))))
    return output