# Path: epitator/annotator.py
# class Annotator(object):
#     def annotate(self, doc):
# 
# Path: epitator/ngram_annotator.py
# class NgramAnnotator(Annotator):
# 
#     def __init__(self, n_min=1, n_max=5):
#         self.n_min = n_min
#         self.n_max = n_max
# 
#     def annotate(self, doc):
# 
#         if 'tokens' not in doc.tiers:
#             doc.add_tiers(TokenAnnotator())
# 
#         ngram_spans = []
# 
#         token_spans = doc.tiers['tokens'].spans
# 
#         for n in range(self.n_min, self.n_max + 1):
#             for i in range(len(token_spans)):
#                 if i + n > len(token_spans):
#                     break
#                 span = AnnoSpan(token_spans[i].start,
#                                 token_spans[i + n - 1].end,
#                                 doc)
#                 ngram_spans.append(span)
# 
#         doc.tiers['ngrams'] = AnnoTier(ngram_spans)
# 
#         return doc


import unittest
from epitator.annotator import AnnoDoc
from epitator.ngram_annotator import NgramAnnotator


class NgramAnnotatorTest(unittest.TestCase):

    def setUp(self):

        self.annotator = NgramAnnotator()

    def test_one_word_sentence(self):

        doc = AnnoDoc("Hi")
        doc.add_tier(self.annotator)

        self.assertEqual(len(doc.tiers['ngrams'].spans), 1)

        self.assertEqual(doc.tiers['ngrams'].spans[0].text, 'Hi')

    def test_two_word_sentence(self):

        doc = AnnoDoc("Hi there")
        doc.add_tier(self.annotator)

        self.assertEqual(len(doc.tiers['ngrams'].spans), 3)

        self.assertEqual(doc.tiers['ngrams'].spans[0].text, 'Hi')
        self.assertEqual(doc.tiers['ngrams'].spans[1].text, 'Hi there')
        self.assertEqual(doc.tiers['ngrams'].spans[2].text, 'there')

    def test_three_word_sentence_with_period(self):


# Path: epitator/annotator.py
# class Annotator(object):
#     def annotate(self, doc):
# 
# Path: epitator/ngram_annotator.py
# class NgramAnnotator(Annotator):
# 
#     def __init__(self, n_min=1, n_max=5):
#         self.n_min = n_min
#         self.n_max = n_max
# 
#     def annotate(self, doc):
# 
#         if 'tokens' not in doc.tiers:
#             doc.add_tiers(TokenAnnotator())
# 
#         ngram_spans = []
# 
#         token_spans = doc.tiers['tokens'].spans
# 
#         for n in range(self.n_min, self.n_max + 1):
#             for i in range(len(token_spans)):
#                 if i + n > len(token_spans):
#                     break
#                 span = AnnoSpan(token_spans[i].start,
#                                 token_spans[i + n - 1].end,
#                                 doc)
#                 ngram_spans.append(span)
# 
#         doc.tiers['ngrams'] = AnnoTier(ngram_spans)
# 
#         return doc


# Path: tests/annotator/test_ngram_annotator.py
import unittest
from epitator.annotator import AnnoDoc
from epitator.ngram_annotator import NgramAnnotator



class NgramAnnotatorTest(unittest.TestCase):

    def setUp(self):

        self.annotator = NgramAnnotator()

    def test_one_word_sentence(self):

        doc = AnnoDoc("Hi")
        doc.add_tier(self.annotator)

        self.assertEqual(len(doc.tiers['ngrams'].spans), 1)

        self.assertEqual(doc.tiers['ngrams'].spans[0].text, 'Hi')

    def test_two_word_sentence(self):

        doc = AnnoDoc("Hi there")
        doc.add_tier(self.annotator)

        self.assertEqual(len(doc.tiers['ngrams'].spans), 3)

        self.assertEqual(doc.tiers['ngrams'].spans[0].text, 'Hi')
        self.assertEqual(doc.tiers['ngrams'].spans[1].text, 'Hi there')
        self.assertEqual(doc.tiers['ngrams'].spans[2].text, 'there')

    def test_three_word_sentence_with_period(self):


        doc = AnnoDoc("Bears eat tacos.")