Пример #1
0
class SentenceTestCase(unittest.TestCase):
    def setUp(self):
        self.sut = Sentence()
        self.sut.add_end(Word('you', 'PRP'))
        self.sut.add_end(Word('are', 'VBP'))
        self.sut.add_end(Word('conflicted', 'VBN'))

    def test_sentence_grows(self):
        self.sut.add_start(Word('word', 'NN'))
        self.assertEqual(4, len(self.sut.words))

    def test_render_case_and_fullstop(self):
        self.assertEqual("You are conflicted.", self.sut.render())

    def test_expand_contractions(self):
        actual = expand_contractions("can't ain't i'm you're")
        self.assertEqual("cannot am not I am you are", actual)

    def test_move_tag_seq(self):
        self.sut.words = move_tag_seq(self.sut.words, ['PRP', 'VBP'], 'end')
        self.assertEqual(['VBN', 'PRP', 'VBP'], get_tag_seq(self.sut.words))

    def test_mutate_tag_seq(self):
        self.sut.words = mutate_tag_seq(self.sut.words, ['PRP', 'VBP', 'VBN'],
                                        ['VBP', 'VBN'])
        self.assertEqual(['VBP', 'VBN'], get_tag_seq(self.sut.words))

    def test_plurals(self):
        self.sut.add_end(Word('weapons', 'NNS'))
        self.sut.words = move_tag_seq(self.sut.words, ['VBN', 'NN'], 'start')
        self.assertEqual(['VBN', 'NNS', 'PRP', 'VBP'],
                         get_tag_seq(self.sut.words))
Пример #2
0
 def test_size_matters_not(self):
     sut = Sentence(
         self.tagger.tag("Size does not matter.")
     )
     apply_yodish_grammar(sut)
     self.assertEqual(
         "Size matters not.",
         sut.render()
     )
Пример #3
0
 def test_so_certain_are_you(self):
     sut = Sentence(
         self.tagger.tag("Are you so certain?")
     )
     apply_yodish_grammar(sut)
     self.assertEqual(
         "So certain are you?",
         sut.render()
     )
Пример #4
0
 def test_uppercase_i(self):
     sut = Sentence(
         self.tagger.tag("ii i i")
     )
     apply_yodish_grammar(sut)
     self.assertEqual(
         "Ii I I.",
         sut.render()
     )
Пример #5
0
 def test_conflicted_you_are(self):
     sut = Sentence(
         self.tagger.tag("You are conflicted.")
     )
     apply_yodish_grammar(sut)
     self.assertEqual(
         "Conflicted, you are.",
         sut.render()
     )
Пример #6
0
 def test_much_anger(self):
     sut = Sentence(
         self.tagger.tag("I sense much anger in him.")
     )
     apply_yodish_grammar(sut)
     self.assertEqual(
         "Much anger in him, I sense.",
         sut.render() 
     )
Пример #7
0
 def test_away_put_weapons(self):
     sut = Sentence(
         self.tagger.tag("Put your weapons away.")
     )
     apply_yodish_grammar(sut)
     self.assertEqual(
         "Away put your weapons.",
         sut.render()
     )
Пример #8
0
 def test_my_home_this_is(self):
     sut = Sentence(
         self.tagger.tag("This is my home.")
     )
     apply_yodish_grammar(sut)
     self.assertEqual(
         "My home this is.",
         sut.render()
     )
Пример #9
0
 def test_long_input(self):
     source = "One two three. Four five six seven eight nine. Ten eleven twelve thirteen. Fourteen fifteen sixteen seventeen eighteen nineteen twenty"
     sentences = self.tagger.tag(source).replace('\n', '').split(')(')
     actual = ""
     expected = "One two three. Four five six seven eight nine. Ten eleven twelve thirteen. Fourteen fifteen sixteen seventeen eighteen nineteen twenty."
     for pos_tagged in sentences:
         s = Sentence(pos_tagged)
         apply_yodish_grammar(s)
         actual += s.render() + ' '
     actual = actual.strip()
     self.assertEqual(expected, actual)
Пример #10
0
 def test_multiple_sentences(self):
     source = "You are conflicted. Put your weapons away."
     sentences = self.tagger.tag(source).split('\n')
     actual = ""
     expected = "Conflicted, you are. Away put your weapons."
     for pos_tagged in sentences:
         s = Sentence(pos_tagged)
         apply_yodish_grammar(s)
         actual += s.render() + ' '
     actual = actual.strip()
     self.assertEqual(expected, actual)
Пример #11
0
def translate(source):
    t = PartOfSpeechTagger('http://text-processing.com/api/tag/', 'text')
    source = expand_contractions(source)
    source = t.tag(source)
    source = source.replace('\n','')
    logging.warning("Foo: " + source)
    sentences = source.split(')(')

    translated = ""
    for pos_tagged in sentences:
        s = Sentence(pos_tagged)
        apply_yodish_grammar(s)
        translated += s.render() + ' '
    return translated.strip()
Пример #12
0
def translate(source):
    t = PartOfSpeechTagger('http://text-processing.com/api/tag/', 'text')
    source = expand_contractions(source)
    source = t.tag(source)
    source = source.replace('\n', '')
    logging.warning("Foo: " + source)
    sentences = source.split(')(')

    translated = ""
    for pos_tagged in sentences:
        s = Sentence(pos_tagged)
        apply_yodish_grammar(s)
        translated += s.render() + ' '
    return translated.strip()
Пример #13
0
 def test_long_input(self):
     source = "One two three. Four five six seven eight nine. Ten eleven twelve thirteen. Fourteen fifteen sixteen seventeen eighteen nineteen twenty"
     sentences = self.tagger.tag(source).replace('\n','').split(')(')
     actual = ""
     expected = "One two three. Four five six seven eight nine. Ten eleven twelve thirteen. Fourteen fifteen sixteen seventeen eighteen nineteen twenty."
     for pos_tagged in sentences:
         s = Sentence(pos_tagged)
         apply_yodish_grammar(s)
         actual += s.render() + ' '
     actual = actual.strip()
     self.assertEqual(
         expected,
         actual
     )
Пример #14
0
 def test_multiple_sentences(self):
     source = "You are conflicted. Put your weapons away."
     sentences = self.tagger.tag(source).split('\n')
     actual = ""
     expected = "Conflicted, you are. Away put your weapons."
     for pos_tagged in sentences:
         s = Sentence(pos_tagged)
         apply_yodish_grammar(s)
         actual += s.render() + ' '
     actual = actual.strip()
     self.assertEqual(
         expected,
         actual
     )
Пример #15
0
class SentenceTestCase(unittest.TestCase):

    def setUp(self):
        self.sut = Sentence()
        self.sut.add_end(Word('you', 'PRP'))
        self.sut.add_end(Word('are', 'VBP'))
        self.sut.add_end(Word('conflicted', 'VBN'))

    def test_sentence_grows(self):
        self.sut.add_start(Word('word', 'NN'))
        self.assertEqual(4, len(self.sut.words))

    def test_render_case_and_fullstop(self):
        self.assertEqual("You are conflicted.", self.sut.render())

    def test_expand_contractions(self):
        actual = expand_contractions("can't ain't i'm you're")
        self.assertEqual("cannot am not I am you are", actual)

    def test_move_tag_seq(self):
        self.sut.words = move_tag_seq(
            self.sut.words,
            ['PRP','VBP'],
            'end'
        )
        self.assertEqual(['VBN','PRP','VBP'], get_tag_seq(self.sut.words))

    def test_mutate_tag_seq(self):
        self.sut.words = mutate_tag_seq(
            self.sut.words,
            ['PRP','VBP','VBN'],
            ['VBP','VBN']
        )
        self.assertEqual(['VBP','VBN'], get_tag_seq(self.sut.words))

    def test_plurals(self):
        self.sut.add_end(Word('weapons', 'NNS'))
        self.sut.words = move_tag_seq(
            self.sut.words,
            ['VBN','NN'],
            'start'
        )
        self.assertEqual(
            ['VBN','NNS','PRP','VBP'], 
            get_tag_seq(self.sut.words)
        )
Пример #16
0
 def test_conflicted_you_are(self):
     sut = Sentence(self.tagger.tag("You are conflicted."))
     apply_yodish_grammar(sut)
     self.assertEqual("Conflicted, you are.", sut.render())
Пример #17
0
 def test_much_anger(self):
     sut = Sentence(self.tagger.tag("I sense much anger in him."))
     apply_yodish_grammar(sut)
     self.assertEqual("Much anger in him, I sense.", sut.render())
Пример #18
0
 def test_away_put_weapons(self):
     sut = Sentence(self.tagger.tag("Put your weapons away."))
     apply_yodish_grammar(sut)
     self.assertEqual("Away put your weapons.", sut.render())
Пример #19
0
 def test_my_home_this_is(self):
     sut = Sentence(self.tagger.tag("This is my home."))
     apply_yodish_grammar(sut)
     self.assertEqual("My home this is.", sut.render())
Пример #20
0
 def test_size_matters_not(self):
     sut = Sentence(self.tagger.tag("Size does not matter."))
     apply_yodish_grammar(sut)
     self.assertEqual("Size matters not.", sut.render())
Пример #21
0
 def test_so_certain_are_you(self):
     sut = Sentence(self.tagger.tag("Are you so certain?"))
     apply_yodish_grammar(sut)
     self.assertEqual("So certain are you?", sut.render())
Пример #22
0
 def test_uppercase_i(self):
     sut = Sentence(self.tagger.tag("ii i i"))
     apply_yodish_grammar(sut)
     self.assertEqual("Ii I I.", sut.render())