Exemplo n.º 1
0
class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        self.assertTrue(self.ld.rhymes("dog", "bog"))
        self.assertFalse(self.ld.rhymes("dog", "cat"))

    def test_syllables(self):
        self.assertEqual(self.ld.num_syllables("dog"), 1)
        self.assertEqual(self.ld.num_syllables("asdf"), 1)
        self.assertEqual(self.ld.num_syllables("letter"), 2)
        self.assertEqual(self.ld.num_syllables("washington"), 3)

    def test_examples(self):

        a = """
a bather whose clothing was strewed
by winds that left her quite nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""


        self.assertTrue(self.ld.is_limerick(a))
        self.assertFalse(self.ld.is_limerick(b))
        self.assertFalse(self.ld.is_limerick(c))
Exemplo n.º 2
0
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        self.assertTrue(self.ld.rhymes("dog", "bog"))
        self.assertFalse(self.ld.rhymes("dog", "cat"))

    def test_syllables(self):
        self.assertEqual(self.ld.num_syllables("dog"), 1)
        self.assertEqual(self.ld.num_syllables("asdf"), 1)
        self.assertEqual(self.ld.num_syllables("letter"), 2)
        self.assertEqual(self.ld.num_syllables("washington"), 3)

    def test_examples(self):

        a = """
a bather whose clothing was strewed
by winds that left her quite nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        self.assertTrue(self.ld.is_limerick(a))
        self.assertFalse(self.ld.is_limerick(b))
        self.assertFalse(self.ld.is_limerick(c))
Exemplo n.º 3
0
 def setUp(self):
     self.ld = LimerickDetector()
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        s = []
        try:
            self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.rhymes("read", "need"), True)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        except:
            s.append(11)
        try:
            self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        except:
            s.append(12)
        try:
            self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        except:
            s.append(13)
        try:
            self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        except:
            s.append(14)
        try:
            self.assertEqual(self.ld.rhymes("cup", "duck"), False)
        except:
            s.append(15)
        try:
            self.assertEqual(self.ld.rhymes("infinity", "affinity"), False)
        except:
            s.append(16)
        try:
            self.assertEqual(self.ld.rhymes("ark", "ink"), False)
        except:
            s.append(17)
        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s) != 0:
            print 'Failed rhyme tests:', ','.join([str(x) for x in s])

    def test_syllables(self):
        s = []
        try:
            self.assertEqual(self.ld.num_syllables("dog"), 1)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.num_syllables("letter"), 2)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.num_syllables("washington"), 3)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.num_syllables("dock"), 1)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.num_syllables("fly"), 1)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.num_syllables("placate"), 2)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.num_syllables("renege"), 2)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except:
            s.append(11)
        # try: self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        # except: s.append(11)
        # try: self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        # except: s.append(11)
        # try: self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        # except: s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s) != 0:
            print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
a woman whose friends called a PRUDE
on a lark WHen bathing all nUde
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"
        ab = """A wonderful bird is the pelican,

        His bill can hold more than his beli-can.

        He can take in his beak

        Food enough for a week

        But I'm damned if I see how the heli-can."""

        ac = """The limerick packs laughs anatomical
                Into space that is quite economical.
                But the good ones I've seen
                So seldom are clean
                And the clean ones so seldom are comical"""

        ad = """There once was a son of a duke
        Whose upbringing was really a fluke:
        He was raised by some gibbons
        With apes for his siblin's
        So all he can say now is "ook." """

        ae = """May you purge all the lust from my soul,

        Give me continence and self-control,

        Give me patience and love

        From the heavens above

        To obey your commands in their whole."""

        af = """Our novels get longa and long

        Their language gets stronga and strong

        There is much to be said

        For the life that is led

        In illiterate places like Bong"""

        ag = """With the ladies I'm not a chart-topper

        I seem dainty and meek and a flopper

        I'll be more of a chief

        If I smell like cooked beef

        With the scent of a Burger King Whopper"""

        p = """There was a Young Person of can't,
Whose toilette was far from pant;
She dressed in a sack,
Spickle-speckled with black,
That ombliferous person of chant."""

        t = """Can't believe it's true, must be a can't.
It seems kids these days actually pant.
It's a very strange fad,
to dress up just like Dad.
Bell-bottom pants and big clunky shoes."""
        u = """There was an old man from Peru
Who dreamt he was eating his shoe.
He awoke in a fright
In the middle of the night
And found it was perfectly true"""

        s = []

        try:
            self.assertEqual(self.ld.is_limerick(a), True)
        except:
            s.append('a')
        try:
            self.assertEqual(self.ld.is_limerick(b), False)
        except:
            s.append('b')
        try:
            self.assertEqual(self.ld.is_limerick(c), False)
        except:
            s.append('c')
        try:
            self.assertEqual(self.ld.is_limerick(d), False)
        except:
            s.append('d')
        try:
            self.assertEqual(self.ld.is_limerick(e), True)
        except:
            s.append('e')
        try:
            self.assertEqual(self.ld.is_limerick(f), False)
        except:
            s.append('f')
        try:
            self.assertEqual(self.ld.is_limerick(g), True)
        except:
            s.append('g')
        try:
            self.assertEqual(self.ld.is_limerick(h), False)
        except:
            s.append('h')
        try:
            self.assertEqual(self.ld.is_limerick(p), False)
        except:
            s.append('p')
        try:
            self.assertEqual(self.ld.is_limerick(t), False)
        except:
            s.append('t')
        try:
            self.assertEqual(self.ld.is_limerick(u), True)
        except:
            s.append('u')
        try:
            self.assertEqual(self.ld.is_limerick(ab), False)
        except:
            s.append('ab')
        try:
            self.assertEqual(self.ld.is_limerick(ac), False)
        except:
            s.append('ac')
        try:
            self.assertEqual(self.ld.is_limerick(ad), False)
        except:
            s.append('ad')
        try:
            self.assertEqual(self.ld.is_limerick(ae), False)
        except:
            s.append('ae')
        try:
            self.assertEqual(self.ld.is_limerick(af), False)
        except:
            s.append('af')
        try:
            self.assertEqual(self.ld.is_limerick(ag), False)
        except:
            s.append('ag')
        print 'Number of failed limerick tests:', str(len(s))
        if len(s) != 0: print 'Failed limerick tests:', ','.join(s)
Exemplo n.º 5
0
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_guess_syllables(self):
        s = []

        try:
            self.assertEqual(self.ld.guess_syllables("kogo"), 2)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.guess_syllables("213"), 1)
        except:
            s.append(2)

        print '\nNumber of failed guess_syllables tests:', str(len(s))
        if len(s) != 0:
            print 'Failed guess_syllables tests:', ','.join(
                [str(x) for x in s])

    def test_apostrophe(self):
        s = []

        self.assertEqual(
            self.ld.apstrophe_tokenize("I can't wouldn't isn't won't won;t"),
            ['I', "can't", "wouldn't", "isn't", "won't", 'won', ';', 't'])

        try:
            self.assertEqual(
                self.ld.apstrophe_tokenize(
                    "I can't wouldn't isn't won't won;t"),
                ['I', "can't", "wouldn't", "isn't", "won't", 'won', ';', 't'])
        except:
            s.append(1)

        print '\nNumber of failed apostrophe tests:', str(len(s))
        if len(s) != 0:
            print 'Failed apostrophe tests:', ','.join([str(x) for x in s])

    def test_rhyme(self):
        s = []

        ##        self.assertEqual(self.ld.rhymes("awoke", "broke"), False)

        try:
            self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.rhymes("read", "need"), True)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        except:
            s.append(11)
        try:
            self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        except:
            s.append(12)
        try:
            self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        except:
            s.append(13)
        try:
            self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        except:
            s.append(14)
        try:
            self.assertEqual(self.ld.rhymes("cup", "duck"), False)
        except:
            s.append(15)
        try:
            self.assertEqual(self.ld.rhymes("og", "bog"), True)
        except:
            s.append(16)
        try:
            self.assertEqual(self.ld.rhymes("awoke", "broke"), True)
        except:
            s.append(17)

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s) != 0:
            print 'Failed rhyme tests:', ','.join([str(x) for x in s])

    def test_syllables(self):
        s = []
        try:
            self.assertEqual(self.ld.num_syllables("dog"), 1)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.num_syllables("letter"), 2)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.num_syllables("washington"), 3)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.num_syllables("dock"), 1)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.num_syllables("fly"), 1)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.num_syllables("placate"), 2)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.num_syllables("renege"), 2)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except:
            s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s) != 0:
            print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"

        i = """Technic back in time was so broke
Everyone think computer is just a joke
but machine learning grow
make everybody know
the new time of era has awoke"""

        s = []

        ##        self.assertEqual(self.ld.is_limerick(a), True)

        try:
            self.assertEqual(self.ld.is_limerick(a), True)
        except:
            s.append('a')
        try:
            self.assertEqual(self.ld.is_limerick(b), False)
        except:
            s.append('b')
        try:
            self.assertEqual(self.ld.is_limerick(c), False)
        except:
            s.append('c')
        try:
            self.assertEqual(self.ld.is_limerick(d), False)
        except:
            s.append('d')
        try:
            self.assertEqual(self.ld.is_limerick(e), True)
        except:
            s.append('e')
        try:
            self.assertEqual(self.ld.is_limerick(f), False)
        except:
            s.append('f')
        try:
            self.assertEqual(self.ld.is_limerick(g), True)
        except:
            s.append('g')
        try:
            self.assertEqual(self.ld.is_limerick(h), False)
        except:
            s.append('h')
        try:
            self.assertEqual(self.ld.is_limerick(i), True)
        except:
            s.append('i')

        print 'Number of failed limerick tests:', str(len(s))
        if len(s) != 0: print 'Failed limerick tests:', ','.join(s)
Exemplo n.º 6
0
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        self.assertEqual(self.ld.rhymes("read", "need"), True)

        self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        self.assertEqual(self.ld.rhymes("cup", "duck"), False)

    def test_syllables(self):
        self.assertEqual(self.ld.num_syllables("dog"), 1)
        self.assertEqual(self.ld.num_syllables("asdf"), 1)
        self.assertEqual(self.ld.num_syllables("letter"), 2)
        self.assertEqual(self.ld.num_syllables("washington"), 3)
        self.assertEqual(self.ld.num_syllables("dock"), 1)
        self.assertEqual(self.ld.num_syllables("dangle"), 2)
        self.assertEqual(self.ld.num_syllables("thrive"), 1)
        self.assertEqual(self.ld.num_syllables("fly"), 1)
        self.assertEqual(self.ld.num_syllables("placate"), 2)
        self.assertEqual(self.ld.num_syllables("renege"), 2)
        self.assertEqual(self.ld.num_syllables("reluctant"), 3)

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"

        self.assertEqual(self.ld.is_limerick(a), True)
        self.assertEqual(self.ld.is_limerick(b), False)
        self.assertEqual(self.ld.is_limerick(c), False)
        self.assertEqual(self.ld.is_limerick(d), False)
        self.assertEqual(self.ld.is_limerick(f), False)
        # self.assertEqual(self.ld.is_limerick(e), True)
        self.assertEqual(self.ld.is_limerick(g), True)
Exemplo n.º 7
0
class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        s = []
        try: self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        except: s.append(1)
        try: self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        except: s.append(2)
        try: self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        except: s.append(3)
        try: self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        except: s.append(4)
        try: self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        except: s.append(5)
        try: self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        except: s.append(6)
        try: self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        except: s.append(7)
        try: self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        except: s.append(8)
        try: self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        except: s.append(9)
        try: self.assertEqual(self.ld.rhymes("read", "need"), True)
        except: s.append(10)
        try: self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        except: s.append(11)
        try: self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        except: s.append(12)
        try: self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        except: s.append(13)
        try: self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        except: s.append(14)
        try: self.assertEqual(self.ld.rhymes("cup", "duck"), False)
        except: s.append(15)

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s)!=0: print 'Failed rhyme tests:', ','.join([str(x) for x in s])

    def test_syllables(self):
        s = []
        try: self.assertEqual(self.ld.num_syllables("dog"), 1)
        except: s.append(1)
        try: self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except: s.append(2)
        try: self.assertEqual(self.ld.num_syllables("letter"), 2)
        except: s.append(3)
        try: self.assertEqual(self.ld.num_syllables("washington"), 3)
        except: s.append(4)
        try: self.assertEqual(self.ld.num_syllables("dock"), 1)
        except: s.append(5)
        try: self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except: s.append(6)
        try: self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except: s.append(7)
        try: self.assertEqual(self.ld.num_syllables("fly"), 1)
        except: s.append(8)
        try: self.assertEqual(self.ld.num_syllables("placate"), 2)
        except: s.append(9)
        try: self.assertEqual(self.ld.num_syllables("renege"), 2)
        except: s.append(10)
        try: self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except: s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s)!=0: print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
They pondered if a machine could think ahead
You will see it when I win Jeopardy, IBM Watson said
With "Hey Siri", one got their own Jeeves at hand
Alexa turned all devices, a puppet on command
Now they ask, will it lead to Great Filter or Singularity instead!
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"

        s = []

        try: self.assertEqual(self.ld.is_limerick(a), True)
        except: s.append('a')
        try: self.assertEqual(self.ld.is_limerick(b), False)
        except: s.append('b')
        try: self.assertEqual(self.ld.is_limerick(c), False)
        except: s.append('c')
        try: self.assertEqual(self.ld.is_limerick(d), False)
        except: s.append('d')
        try: self.assertEqual(self.ld.is_limerick(f), False)
        except: s.append('f')
        try: self.assertEqual(self.ld.is_limerick(e), True)
        except: s.append('e')
        try: self.assertEqual(self.ld.is_limerick(g), True)
        except: s.append('g')

        print 'Number of failed limerick tests:', str(len(s))
        if len(s)!=0: print 'Failed limerick tests:', ','.join(s)
Exemplo n.º 8
0
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_apos(self):
        s = []

        try:
            self.assertEqual(self.ld.apostrophe_tokenize("He can't do this"),
                             True)
        except:
            s.append(1)
        try:
            self.assertEqual(
                self.ld.apostrophe_tokenize(
                    "She doesn't care this ain't her work"), True)
        except:
            s.append(2)

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s) != 0:
            print 'Failed rhyme tests:', ','.join([str(x) for x in s])

    def test_rhyme(self):
        s = []

        try:
            self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.rhymes("read", "need"), True)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        except:
            s.append(11)
        try:
            self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        except:
            s.append(12)
        try:
            self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        except:
            s.append(13)
        try:
            self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        except:
            s.append(14)
        try:
            self.assertEqual(self.ld.rhymes("cup", "duck"), False)
        except:
            s.append(15)
        try:
            self.assertEqual(self.ld.rhymes("confession", "regression"), True)
        except:
            s.append(16)

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s) != 0:
            print 'Failed rhyme tests:', ','.join([str(x) for x in s])
        """
        try: self.assertEqual(self.ld.rhymes("a", "ah"), False)
        except: s.append(1)
        try: self.assertEqual(self.ld.rhymes("eh", "meh"), False)
        except: s.append(2)
        try: self.assertEqual(self.ld.rhymes("play", "slay"), True)
        except: s.append(3)
        try: self.assertEqual(self.ld.rhymes("along", "prolong"), True)
        except: s.append(4)
        try: self.assertEqual(self.ld.rhymes("infinity", "affinity"), False)
        except: s.append(5)
        try: self.assertEqual(self.ld.rhymes("clarify", "verify"), True)
        except: s.append(6)
        try: self.assertEqual(self.ld.rhymes("anatomical", "Economical"), False)
        except: s.append(7)
        try: self.assertEqual(self.ld.rhymes("impair", "footwear"), False)
        except: s.append(8)
        try: self.assertEqual(self.ld.rhymes("along", "wrong"), True)
        except: s.append(9)

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s)!=0: print 'Failed rhyme tests:', ','.join([str(x) for x in s])
        """

    def test_syllables(self):
        s = []
        try:
            self.assertEqual(self.ld.num_syllables("dog"), 1)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.num_syllables("letter"), 2)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.num_syllables("washington"), 3)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.num_syllables("dock"), 1)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.num_syllables("fly"), 1)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.num_syllables("placate"), 2)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.num_syllables("renege"), 2)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except:
            s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s) != 0:
            print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"

        i = """potato potato potato swine
potato potato mine
potato swig
potato rig
potato potato potato wine."""

        j = """potato potato swine swine
potato potato mine
potato swig
potato rig
potato potato wine wine."""

        k = """potato potato mice
potato potato ice
potato
potato
potato potato rice"""

        l = """potato potato mice
potato potato ice
potato
potato"""

        m = """potato potato mouse nick
potato potato tick
potato trick
potato pick
potato potato wick wick
        """

        n = """potato potato potato hand
potato potato demand
potato pride
potato snide

potato potato potato grand        """

        o = """rat rat rat rat pound
rat lives in the ground
rat is a big ass man
rat lives in a frying pan
rat pat mat bat cat     sat mound
        """

        s = []

        try:
            self.assertEqual(self.ld.is_limerick(a), True)
        except:
            s.append('a')
        try:
            self.assertEqual(self.ld.is_limerick(b), False)
        except:
            s.append('b')
        try:
            self.assertEqual(self.ld.is_limerick(c), False)
        except:
            s.append('c')
        try:
            self.assertEqual(self.ld.is_limerick(d), False)
        except:
            s.append('d')
        try:
            self.assertEqual(self.ld.is_limerick(f), False)
        except:
            s.append('f')
        try:
            self.assertEqual(self.ld.is_limerick(e), True)
        except:
            s.append('e')
        try:
            self.assertEqual(self.ld.is_limerick(g), True)
        except:
            s.append('g')
        try:
            self.assertEqual(self.ld.is_limerick(h), False)
        except:
            s.append('h')
        try:
            self.assertEqual(self.ld.is_limerick(i), False)
        except:
            s.append('i')
        try:
            self.assertEqual(self.ld.is_limerick(j), True)
        except:
            s.append('j')
        try:
            self.assertEqual(self.ld.is_limerick(k), False)
        except:
            s.append('k')
        try:
            self.assertEqual(self.ld.is_limerick(l), False)
        except:
            s.append('l')
        try:
            self.assertEqual(self.ld.is_limerick(m), False)
        except:
            s.append('m')
        try:
            self.assertEqual(self.ld.is_limerick(n), True)
        except:
            s.append('n')
        try:
            self.assertEqual(self.ld.is_limerick(o), False)
        except:
            s.append('o')

        print 'Number of failed limerick tests:', str(len(s))
        if len(s) != 0: print 'Failed limerick tests:', ','.join(s)
Exemplo n.º 9
0
from limerick import LimerickDetector

ld = LimerickDetector()
print ld.num_syllables("dog")
print ld.rhymes("dog", "bog")
print ld.guess_syllables("splorkatuk")
class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        s = []
        try: self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        except: s.append(1)
        try: self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        except: s.append(2)
        try: self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        except: s.append(3)
        try: self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        except: s.append(4)
        try: self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        except: s.append(5)
        try: self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        except: s.append(6)
        try: self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        except: s.append(7)
        try: self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        except: s.append(8)
        try: self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        except: s.append(9)
        try: self.assertEqual(self.ld.rhymes("read", "need"), True)
        except: s.append(10)
        try: self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        except: s.append(11)
        try: self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        except: s.append(12)
        try: self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        except: s.append(13)
        try: self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        except: s.append(14)
        try: self.assertEqual(self.ld.rhymes("cup", "duck"), False)
        except: s.append(15)
        
        try: self.assertEqual(self.ld.rhymes("infinity", "affinity"), False)  # <<<<<<<<<<<
        except: s.append(16)
        try: self.assertEqual(self.ld.rhymes("dog", "bog"), True)  # <<<<<<<<<<<
        except: s.append(16)
        

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s)!=0: print 'Failed rhyme tests:', ','.join([str(x) for x in s])

    def test_syllables(self):
        s = []
        try: self.assertEqual(self.ld.num_syllables("dog"), 1)
        except: s.append(1)
        try: self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except: s.append(2)
        try: self.assertEqual(self.ld.num_syllables("letter"), 2)
        except: s.append(3)
        try: self.assertEqual(self.ld.num_syllables("washington"), 3)
        except: s.append(4)
        try: self.assertEqual(self.ld.num_syllables("dock"), 1)
        except: s.append(5)
        try: self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except: s.append(6)
        try: self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except: s.append(7)
        try: self.assertEqual(self.ld.num_syllables("fly"), 1)
        except: s.append(8)
        try: self.assertEqual(self.ld.num_syllables("placate"), 2)
        except: s.append(9)
        try: self.assertEqual(self.ld.num_syllables("renege"), 2)
        except: s.append(10)
        try: self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except: s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s)!=0: print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        #h = "dog\ndog\ndog\ndog\ndog"
        
        h=  """Can't believe it's true, must be a ruse.
It seems kids these days actually choose.
It's a very strange fad,
to dress up just like Dad.
Bell-bottom pants and big clunky shoes."""

        m="""asdf asdf asdf asdf asdf asdf asdf bright
asdf asdf asdf asdf asdf asdf light
asdf asdf asdf asdf day
asdf asdf asdf way
asdf asdf asdf's asdf asdf night"""

        n = 'machines got smarter leaving us in wonder\n they helped us in every way and got us under\n as algorithms came along\n  computer vision became strong\n digital era evolved leaving us not sunder'

        o = ""
        s = []

        try: self.assertEqual(self.ld.is_limerick(a), True)
        except: s.append('a')
        try: self.assertEqual(self.ld.is_limerick(b), False)
        except: s.append('b')
        try: self.assertEqual(self.ld.is_limerick(c), False)
        except: s.append('c')
        try: self.assertEqual(self.ld.is_limerick(d), False)
        except: s.append('d')
        try: self.assertEqual(self.ld.is_limerick(f), False)
        except: s.append('f')
        try: self.assertEqual(self.ld.is_limerick(e), True)
        except: s.append('e')
        try: self.assertEqual(self.ld.is_limerick(g), True)
        except: s.append('g')
        try: self.assertEqual(self.ld.is_limerick(h), False)
        except: s.append('h')
        try: self.assertEqual(self.ld.is_limerick(m), True)
        except: s.append('m')
        try: self.assertEqual(self.ld.is_limerick(n), True)
        except: s.append('N')
        
        #print self.ld.is_limerick(o)
        
        print 'Number of failed limerick tests:', str(len(s))
        if len(s)!=0: print 'Failed limerick tests:', ','.join(s)
Exemplo n.º 11
0
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        s = []
        try:
            self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.rhymes("read", "need"), True)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        except:
            s.append(11)
        try:
            self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        except:
            s.append(12)
        try:
            self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        except:
            s.append(13)
        try:
            self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        except:
            s.append(14)
        try:
            self.assertEqual(self.ld.rhymes("cup", "duck"), False)
        except:
            s.append(15)
        try:
            self.assertEqual(self.ld.rhymes("infinity", "affinity"), False)
        except:
            s.append(16)
        try:
            self.assertEqual(self.ld.rhymes("you", "ewe"), True)
        except:
            s.append(17)
        try:
            self.assertEqual(self.ld.rhymes("anita", "juanita"), True)
        except:
            s.append(18)
        try:
            self.assertEqual(self.ld.rhymes("fire", "conspire"), True)
        except:
            s.append(19)
        try:
            self.assertEqual(self.ld.rhymes("guessing", "messing"), True)
        except:
            s.append(20)
        try:
            self.assertEqual(self.ld.rhymes("cant", "pant"), True)
        except:
            s.append(21)

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s) != 0:
            print 'Failed rhyme tests:', ','.join([str(x) for x in s])

    def test_syllables(self):
        s = []
        try:
            self.assertEqual(self.ld.num_syllables("dog"), 1)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.num_syllables("letter"), 2)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.num_syllables("washington"), 3)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.num_syllables("dock"), 1)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.num_syllables("fly"), 1)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.num_syllables("placate"), 2)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.num_syllables("renege"), 2)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except:
            s.append(11)
        try:
            self.assertEqual(self.ld.num_syllables("eyes"), 1)
        except:
            s.append(12)
        try:
            self.assertEqual(self.ld.num_syllables("you"), 1)
        except:
            s.append(13)
        try:
            self.assertEqual(self.ld.guess_syllables("Placate"), 2)
        except:
            s.append(14)
        try:
            self.assertEqual(self.ld.guess_syllables("eyes"), 1)
        except:
            s.append(15)
        try:
            self.assertEqual(self.ld.guess_syllables("boys"), 1)
        except:
            s.append(16)
        try:
            self.assertEqual(self.ld.num_syllables("boys"), 1)
        except:
            s.append(17)
        try:
            self.assertEqual(self.ld.guess_syllables("buyer"), 2)
        except:
            s.append(18)
        try:
            self.assertEqual(self.ld.num_syllables("buyer"), 2)
        except:
            s.append(19)
        try:
            self.assertEqual(self.ld.guess_syllables("year"), 1)
        except:
            s.append(20)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s) != 0:
            print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"

        j = """Can't believe it's true, must be a ruse.
It seems kids these days actually choose.
It's a very strange fad,
to dress up just like Dad.
Bell-bottom pants and big clunky shoes."""

        i = """There once was a young lady named bright

Whose speed was much faster than light
She set out one day
In a relative way
And returned on the previous night."""
        k = """There was a young lady from space
who grew at a frightening pace
and her mother said "Nelly
There's more in your belly
Than ever went in through your face"""
        l = """A pocket full of random guessing
I never ever had a model messing
Love without my intervention
Such a way of comprehension
Is that or not a hidden blessing"""
        m = """asdf asdf asdf asdf asdf asdf asdf bright
        asdf asdf asdf asdf asdf asdf light
        asdf asdf asdf asdf can't
        asdf asdf asdf pant
        asdf asdf asdf's asdf asdf night"""

        s = []

        try:
            self.assertEqual(self.ld.is_limerick(a), True)
        except:
            s.append('a')
        try:
            self.assertEqual(self.ld.is_limerick(b), False)
        except:
            s.append('b')
        try:
            self.assertEqual(self.ld.is_limerick(c), False)
        except:
            s.append('c')
        try:
            self.assertEqual(self.ld.is_limerick(d), False)
        except:
            s.append('d')
        try:
            self.assertEqual(self.ld.is_limerick(e), True)
        except:
            s.append('e')
        try:
            self.assertEqual(self.ld.is_limerick(f), False)
        except:
            s.append('f')
        try:
            self.assertEqual(self.ld.is_limerick(g), True)
        except:
            s.append('g')
        try:
            self.assertEqual(self.ld.is_limerick(h), False)
        except:
            s.append('h')
        try:
            self.assertEqual(self.ld.is_limerick(i), True)
        except:
            s.append('i')
        try:
            self.assertEqual(self.ld.is_limerick(j), True)
        except:
            s.append('j')
        try:
            self.assertEqual(self.ld.is_limerick(k), True)
        except:
            s.append('k')
        try:
            self.assertEqual(self.ld.is_limerick(m), True)
        except:
            s.append('m')

        print 'Number of failed limerick tests:', str(len(s))
        if len(s) != 0: print 'Failed limerick tests:', ','.join(s)
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        s = []
        try:
            self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.rhymes("read", "need"), True)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        except:
            s.append(11)
        try:
            self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        except:
            s.append(12)
        try:
            self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        except:
            s.append(13)
        try:
            self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        except:
            s.append(14)
        try:
            self.assertEqual(self.ld.rhymes("cup", "duck"), False)
        except:
            s.append(15)
        try:
            self.assertEqual(self.ld.rhymes("dog", "dog"), True)
        except:
            s.append(16)
        try:
            self.assertEqual(self.ld.rhymes("train", "plane"), True)
        except:
            s.append(17)
        try:
            self.assertEqual(self.ld.rhymes("thicket", "it"), True)
        except:
            s.append(18)
        try:
            self.assertEqual(self.ld.rhymes("thicket", "cricket"), True)
        except:
            s.append(19)
        try:
            self.assertEqual(self.ld.rhymes("conspire", "fire"), True)
        except:
            s.append(20)
        try:
            self.assertEqual(self.ld.rhymes("along", "wrong"), True)
        except:
            s.append(21)
        try:
            self.assertEqual(self.ld.rhymes("eyes", "oversize"), True)
        except:
            s.append(22)
        try:
            self.assertEqual(self.ld.rhymes("affinity", "infinity"), False)
        except:
            s.append(23)
        try:
            self.assertEqual(self.ld.rhymes("fly", "butterfly"), False)
        except:
            s.append(24)
        try:
            self.assertEqual(self.ld.rhymes("imperia", "asia"), False)
        except:
            s.append(25)
        try:
            self.assertEqual(self.ld.rhymes("footwear", "impair"), False)
        except:
            s.append(26)
        try:
            self.assertEqual(self.ld.rhymes("anatomical", "economical"), False)
        except:
            s.append(27)
        try:
            self.assertEqual(self.ld.rhymes("reader", "higher"), False)
        except:
            s.append(28)

        print '\nNumber of failed rhyme tests:', str(len(s))
        if len(s) != 0:
            print 'Failed rhyme tests:', ','.join([str(x) for x in s])

    def test_syllables(self):
        s = []
        try:
            self.assertEqual(self.ld.num_syllables("dog"), 1)
        except:
            s.append(1)
        try:
            self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except:
            s.append(2)
        try:
            self.assertEqual(self.ld.num_syllables("letter"), 2)
        except:
            s.append(3)
        try:
            self.assertEqual(self.ld.num_syllables("washington"), 3)
        except:
            s.append(4)
        try:
            self.assertEqual(self.ld.num_syllables("dock"), 1)
        except:
            s.append(5)
        try:
            self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except:
            s.append(6)
        try:
            self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except:
            s.append(7)
        try:
            self.assertEqual(self.ld.num_syllables("fly"), 1)
        except:
            s.append(8)
        try:
            self.assertEqual(self.ld.num_syllables("placate"), 2)
        except:
            s.append(9)
        try:
            self.assertEqual(self.ld.num_syllables("renege"), 2)
        except:
            s.append(10)
        try:
            self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except:
            s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s) != 0:
            print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "The topic of my yearning,\nWelcome to machine learning,\nTrain your model,\nSit back and dawdle,\nAnd watch the magic unfolding"

        s = []

        try:
            self.assertEqual(self.ld.is_limerick(a), True)
        except:
            s.append('a')
        try:
            self.assertEqual(self.ld.is_limerick(b), False)
        except:
            s.append('b')
        try:
            self.assertEqual(self.ld.is_limerick(c), False)
        except:
            s.append('c')
        try:
            self.assertEqual(self.ld.is_limerick(d), False)
        except:
            s.append('d')
        try:
            self.assertEqual(self.ld.is_limerick(f), False)
        except:
            s.append('f')
        try:
            self.assertEqual(self.ld.is_limerick(e), True)
        except:
            s.append('e')
        try:
            self.assertEqual(self.ld.is_limerick(g), True)
        except:
            s.append('g')
        try:
            self.assertEqual(self.ld.is_limerick(g), True)
        except:
            s.append('h')

        print 'Number of failed limerick tests:', str(len(s))
        if len(s) != 0: print 'Failed limerick tests:', ','.join(s)
class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        print 'RHYMETEST_BELOW'
        print self.ld.rhymes("defiance", "compliance")

    def test_syllables(self):
        s = []
        #try: self.assertEqual(self.ld.guess_syllables("dog"), 1)
        #except: s.append(1)
        try: self.assertEqual(self.ld.guess_syllables("asdf"), 1)
        except: s.append(2)
        try: self.assertEqual(self.ld.guess_syllables("letter"), 2)
        except: s.append(3)
        try: self.assertEqual(self.ld.guess_syllables("washington"), 3)
        except: s.append(4)
        try: self.assertEqual(self.ld.guess_syllables("dock"), 1)
        except: s.append(5)
        try: self.assertEqual(self.ld.guess_syllables("dangle"), 2)
        except: s.append(6)
        try: self.assertEqual(self.ld.guess_syllables("thrive"), 1)
        except: s.append(7)
        try: self.assertEqual(self.ld.guess_syllables("fly"), 1)
        except: s.append(8)
        try: self.assertEqual(self.ld.guess_syllables("placate"), 2)
        except: s.append(9)
        try: self.assertEqual(self.ld.guess_syllables("renege"), 2)
        except: s.append(10)
        
        try: self.assertEqual(self.ld.guess_syllables("advertisement"), 5)
        except: s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s)!=0: print 'Failed syllables tests:', ','.join([str(x) for x in s])

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c =  """
THIS THING IS SUPPOSED TO RHYME
BUT I SIMPLY DON'T GOT THE TIME
WHO CARES IF I MISS,
NOBODY WILL READ THIS
I'LL END THIS HERE POEM POTATO
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"
        
        i = """When we shook our hands with science
the digital era came in compliance
as algorithms came along
vision of computer became strong
it's enthralling to see that machine and humans have such a beautiful alliance"""


        
        s = []

        try: self.assertEqual(self.ld.is_limerick(a), True)
        except: s.append('a')
        try: self.assertEqual(self.ld.is_limerick(b), False)
        except: s.append('b')
        try: self.assertEqual(self.ld.is_limerick(c), False)
        except: s.append('c')
        try: self.assertEqual(self.ld.is_limerick(d), False)
        except: s.append('d')
        try: self.assertEqual(self.ld.is_limerick(f), False)
        except: s.append('e')
        try: self.assertEqual(self.ld.is_limerick(e), True)
        except: s.append('f')
        try: self.assertEqual(self.ld.is_limerick(g), True)
        except: s.append('g')
        try: self.assertEqual(self.ld.is_limerick(h), True)
        except: s.append('h')
        
        print self.ld.is_limerick(i)

        print 'Number of failed limerick tests:', str(len(s))
        if len(s)!=0: print 'Failed limerick tests:', ','.join(s)
Exemplo n.º 14
0
class TestSequenceFunctions(unittest.TestCase):
    def setUp(self):
        self.ld = LimerickDetector()

    def test_rhyme(self):
        self.assertEqual(self.ld.rhymes("dog", "bog"), True)
        self.assertEqual(self.ld.rhymes("eleven", "seven"), True)
        self.assertEqual(self.ld.rhymes("nine", "wine"), True)
        self.assertEqual(self.ld.rhymes("dine", "fine"), True)
        self.assertEqual(self.ld.rhymes("wine", "mine"), True)
        self.assertEqual(self.ld.rhymes("dock", "sock"), True)
        self.assertEqual(self.ld.rhymes("weigh", "fey"), True)
        self.assertEqual(self.ld.rhymes("tree", "debris"), True)
        self.assertEqual(self.ld.rhymes("niece", "peace"), True)
        self.assertEqual(self.ld.rhymes("read", "need"), True)

        self.assertEqual(self.ld.rhymes("dog", "cat"), False)
        self.assertEqual(self.ld.rhymes("bagel", "sail"), False)
        self.assertEqual(self.ld.rhymes("wine", "rind"), False)
        self.assertEqual(self.ld.rhymes("failure", "savior"), False)
        self.assertEqual(self.ld.rhymes("cup", "duck"), False)

    def test_syllables(self):
        self.assertEqual(self.ld.num_syllables("dog"), 1)
        self.assertEqual(self.ld.num_syllables("asdf"), 1)
        self.assertEqual(self.ld.num_syllables("letter"), 2)
        self.assertEqual(self.ld.num_syllables("washington"), 3)
        self.assertEqual(self.ld.num_syllables("dock"), 1)
        self.assertEqual(self.ld.num_syllables("dangle"), 2)
        self.assertEqual(self.ld.num_syllables("thrive"), 1)
        self.assertEqual(self.ld.num_syllables("fly"), 1)
        self.assertEqual(self.ld.num_syllables("placate"), 2)
        self.assertEqual(self.ld.num_syllables("renege"), 2)
        self.assertEqual(self.ld.num_syllables("reluctant"), 3)

    def test_examples(self):

        a = """
a woman whose friends called a prude
on a lark when bathing all nude
saw a man come along
and unless we are wrong
you expected this line to be lewd
        """

        b = """while it's true all i've done is delay
in defense of myself i must say
today's payoff is great
while the workers all wait
"""

        c = """
this thing is supposed to rhyme
but I simply don't got the time
who cares if i miss,
nobody will read this
i'll end this here poem potato
"""

        d = """There was a young man named Wyatt
whose voice was exceedingly quiet
And then one day
it faded away"""

        e = """An exceedingly fat friend of mine,
When asked at what hour he'd dine,
Replied, "At eleven,     
At three, five, and seven,
And eight and a quarter past nine"""

        f = """A limerick fan from Australia
regarded his work as a failure:
his verses were fine
until the fourth line"""

        g = """There was a young lady one fall
Who wore a newspaper dress to a ball.
The dress caught fire
And burned her entire
Front page, sporting section and all."""

        h = "dog\ndog\ndog\ndog\ndog"

        self.assertEqual(self.ld.is_limerick(a), True)
        self.assertEqual(self.ld.is_limerick(b), False)
        self.assertEqual(self.ld.is_limerick(c), False)
        self.assertEqual(self.ld.is_limerick(d), False)
        self.assertEqual(self.ld.is_limerick(f), False)
        # self.assertEqual(self.ld.is_limerick(e), True)
        self.assertEqual(self.ld.is_limerick(g), True)
Exemplo n.º 15
0
from limerick import LimerickDetector

ld = LimerickDetector()
print ld.num_syllables("dog")
print ld.rhymes("dog", "bog")
print ld.guess_syllables("splorkatuk")
Exemplo n.º 16
0
 def setUp(self):
     self.ld = LimerickDetector()
Exemplo n.º 17
0
class TestSequenceFunctions(unittest.TestCase):

    def setUp(self):
        self.ld = LimerickDetector()

    def test_syllables(self):
        s = []
        try: self.assertEqual(self.ld.num_syllables("dog"), 1)
        except: s.append(1)
        try: self.assertEqual(self.ld.num_syllables("asdf"), 1)
        except: s.append(2)
        try: self.assertEqual(self.ld.num_syllables("letter"), 2)
        except: s.append(3)
        try: self.assertEqual(self.ld.num_syllables("washington"), 3)
        except: s.append(4)
        try: self.assertEqual(self.ld.num_syllables("dock"), 1)
        except: s.append(5)
        try: self.assertEqual(self.ld.num_syllables("dangle"), 2)
        except: s.append(6)
        try: self.assertEqual(self.ld.num_syllables("thrive"), 1)
        except: s.append(7)
        try: self.assertEqual(self.ld.num_syllables("fly"), 1)
        except: s.append(8)
        try: self.assertEqual(self.ld.num_syllables("placate"), 2)
        except: s.append(9)
        try: self.assertEqual(self.ld.num_syllables("renege"), 2)
        except: s.append(10)
        try: self.assertEqual(self.ld.num_syllables("reluctant"), 3)
        except: s.append(11)

        print '\nNumber of failed syllables tests:', str(len(s))
        if len(s)!=0: print 'Failed syllables tests:', ','.join([str(x) for x in s])