def text_cooccurrences_by_chapter(self):
     cooccurring_by_chapters = []
     for book in self.text:
         print("chapter")
         characters_present_in_chapter = set()
         # region where only characters present in current chapter are chosen
         tokens = [
             token for para in book for sent in para for token in sent
         ]
         print(tokens[:5])
         for character in self.characters.keys():
             for character_inflected_form in self.characters[character]:
                 if character_inflected_form in tokens:
                     characters_present_in_chapter.add(character)
         # endregion
         print(list(characters_present_in_chapter)[:5])
         possible_pairs = list(
             itertools.combinations(characters_present_in_chapter, 2))
         cooccurring = dict.fromkeys(possible_pairs, 0)
         for para in book:
             for sent in utils.partition(para, 5):
                 sent = [word for s in sent for word in s]
                 for pair in possible_pairs:
                     # print(sent, pair)
                     if utils.one_of_them_in(self.characters[pair[0]], sent) \
                             and utils.one_of_them_in(
                             self.characters[pair[1]], sent):
                         cooccurring[pair] += 1
         cooccurring_by_chapters.append(cooccurring)
     return cooccurring_by_chapters
 def text_cooccurrences_by_chapter(self):
     cooccurring_by_chapters = []
     # print(len(self.text))
     # print(self.text)
     for chapter in self.text:
         # print("chapter")
         characters_present_in_chapter = set()
         # region where only characters present in current chapter are chosen
         tokens = [
             token for long_line in chapter for half_line in long_line
             for token in half_line.split(" ")
         ]
         for character_lemma in self.characters:
             for character in self.characters[character_lemma]:
                 if character in tokens:
                     characters_present_in_chapter.add(character_lemma)
         # endregion
         possible_pairs = list(
             itertools.combinations(characters_present_in_chapter, 2))
         co_occurring = dict.fromkeys(possible_pairs, 0)
         for para in utils.partition(
                 chapter,
                 4 * 3):  # this is the natural way to divide texts in
             para = " ".join([" ".join(long_line) for long_line in para])
             for pair in possible_pairs:
                 if utils.one_of_them_in(self.characters[pair[0]], para) \
                         and utils.one_of_them_in(
                         self.characters[pair[1]], para):
                     co_occurring[pair] += 1
         cooccurring_by_chapters.append(co_occurring)
     return cooccurring_by_chapters
 def text_co_occurrences(self):
     possible_pairs = list(
         itertools.combinations(list(self.characters.keys()), 2))
     # print(possible_pairs)
     co_occurring = dict.fromkeys(possible_pairs, 0)
     for chapter in self.text:
         for para in utils.partition(chapter, 3 * 4):
             para = " ".join([" ".join(long_line) for long_line in para])
             for pair in possible_pairs:
                 if utils.one_of_them_in(self.characters[pair[0]], para) and \
                         utils.one_of_them_in(self.characters[pair[1]], para):
                     co_occurring[pair] += 1
     return co_occurring
 def text_co_occurrences(self):
     possible_pairs = list(
         itertools.combinations(list(self.characters.keys()), 2))
     cooccurring = dict.fromkeys(possible_pairs, 0)
     for chapter in self.text:
         for para in chapter:
             for sent in utils.partition(para, 5):
                 sent = [word for s in sent for word in s]
                 for pair in possible_pairs:
                     if utils.one_of_them_in(self.characters[pair[0]],
                                             sent) and utils.one_of_them_in(
                                                 self.characters[pair[1]],
                                                 sent):
                         cooccurring[pair] += 1
     return cooccurring
    def text_occurrences(self):
        """

        """
        if not self.characters:
            raise ValueError("Load character names")
        if not self.text:
            raise ValueError("Load text")
        occurrences = super(NibelungenliedSocialNetwork, self).text_occurrences
        for character in self.characters:
            for chapter in self.text:
                for para in utils.partition(chapter, 3 * 4):
                    para = " ".join(
                        [" ".join(long_line) for long_line in para])
                    if utils.one_of_them_in(self.characters[character], para):
                        occurrences[character] += 1
        return occurrences
    def text_occurrences(self):
        """

        """
        if not self.characters:
            raise ValueError("Load character names")
        if not self.text:
            raise ValueError("Load text")
        occurrences = super(VolsungaSocialNetwork, self).text_occurrences
        for character in self.characters:
            for chapter in self.text:
                for para in chapter:
                    for sent in para:
                        if utils.one_of_them_in(self.characters[character],
                                                sent):
                            occurrences[character] += 1
        return occurrences
    def text_occurrences(self):
        """

        """
        if not self.characters:
            raise ValueError("Load character names")
        if not self.text:
            raise ValueError("Load text")
        occurrences = super(DLHSocialNetwork, self).text_occurrences
        for character in self.characters:
            for book in self.text:
                for para in book:
                    for sent in para:
                        sent = [word for s in sent for word in s]
                        if utils.one_of_them_in(self.characters[character],
                                                sent):
                            occurrences[character] += 1
        return occurrences