# Path: server/src/voicebox/ngram.py
# class Ngram(object):
# 
#     def __init__(self, token):
#         self.token = token
#         self.count = 1
#         self.after = []
# 
#     def __str__(self):
#         return str({
#             'after': self.after,
#             'count': self.count
#         })
# 
#     def __repr__(self):
#         return str({
#             'after': self.after,
#             'count': self.count
#         })
# 
#     def __len__(self):
#         return len(self.token)
# 
#     def __eq__(self, other):
#         if type(self) is type(other):
#             return self.__dict__ == other.__dict__
#         return False
# 
#     def add_after(self, token, reach):
#         if len(self.after) < reach:
#             self.after.append({})
#         target_dict = self.after[reach - 1]
#         if token in target_dict:
#             target_dict[token] += 1
#         else:
#             target_dict[token] = 1


import string
import re
from .ngram import Ngram
        self.hindsight = hindsight
        self.sentence_start_token = sentence_start_token

        self.max_reach = 2

        self.wordcount = 0
        self.tree = {}
        self.build()

    def build(self):
        sentences = self.get_sentences()

        for sentence in sentences:
            sentence = [self.sentence_start_token] + sentence

            for ngram_size in range(1, self.max_ngram_size + 1):
                for start in range(1, len(sentence)):
                    end = start + ngram_size

                    if start >= 0 and end < len(sentence) + 1:
                        before, current, after = sentence[:start], sentence[start:end], sentence[end:]

                        if len(current) == 1:
                            self.wordcount += 1

                        ngram = " ".join(current)

                        if ngram in self.tree:
                            self.tree[ngram].count += 1
                        else:

# Path: server/src/voicebox/ngram.py
# class Ngram(object):
# 
#     def __init__(self, token):
#         self.token = token
#         self.count = 1
#         self.after = []
# 
#     def __str__(self):
#         return str({
#             'after': self.after,
#             'count': self.count
#         })
# 
#     def __repr__(self):
#         return str({
#             'after': self.after,
#             'count': self.count
#         })
# 
#     def __len__(self):
#         return len(self.token)
# 
#     def __eq__(self, other):
#         if type(self) is type(other):
#             return self.__dict__ == other.__dict__
#         return False
# 
#     def add_after(self, token, reach):
#         if len(self.after) < reach:
#             self.after.append({})
#         target_dict = self.after[reach - 1]
#         if token in target_dict:
#             target_dict[token] += 1
#         else:
#             target_dict[token] = 1


# Path: server/src/voicebox/corpus.py
import string
import re
from .ngram import Ngram

        self.hindsight = hindsight
        self.sentence_start_token = sentence_start_token

        self.max_reach = 2

        self.wordcount = 0
        self.tree = {}
        self.build()

    def build(self):
        sentences = self.get_sentences()

        for sentence in sentences:
            sentence = [self.sentence_start_token] + sentence

            for ngram_size in range(1, self.max_ngram_size + 1):
                for start in range(1, len(sentence)):
                    end = start + ngram_size

                    if start >= 0 and end < len(sentence) + 1:
                        before, current, after = sentence[:start], sentence[start:end], sentence[end:]

                        if len(current) == 1:
                            self.wordcount += 1

                        ngram = " ".join(current)

                        if ngram in self.tree:
                            self.tree[ngram].count += 1
                        else:

                            self.tree[ngram] = Ngram(ngram)