Esempio n. 1
0
def main(argv):
    """ This is the main entry point to the program. This program generates a 
    set of rap lyrics using a markov chain generated from the passed in data
    set. 
    
        usage: python rap.py <input_file> <num_words>
    
    Arguments:
      - input_file - this is the file to create the markov chain 
    """
    if len(argv) < 2:
        usage_and_quit()

    poet = Poet()
    poet.feed(argv[0])

    out = ''
    num_words = int(argv[1])
    for i in range(num_words):
        next = poet.get_next()
        out += next + ' '
        if REGEX_PUNC.match(next):
            print out
            out = ''
        print out
Esempio n. 2
0
def main():
    parser = argparse.ArgumentParser(
        description='compose some (bad, random) poetry')
    parser.add_argument('-t',
                        '--tweet',
                        dest='tweet',
                        help='tweet the poem',
                        action='store_true')
    parser.add_argument('-s',
                        '--source',
                        dest='source',
                        required=True,
                        help='path to corpus text')
    parser.add_argument('-f',
                        '--form',
                        dest='form',
                        help='poetic form to compose',
                        choices=('haiku', 'free_verse'))
    options = parser.parse_args()

    poet = Poet(corpus=options.source)
    poem = poet.compose(options.form)
    print poem
    print len(poem)

    # optionally, tweet the review.
    if options.tweet:
        print "Would tweet."
Esempio n. 3
0
    def test_should_be_able_to_echo_for_reveal_day_1(self):
        poet = Poet(Poem(POEM), EchoFormatter())

        actualTale = poet.revealForDay(1)
        expectedTale = "This is the house that Jack built.\n\tthe house that Jack built."

        self.assertEqual(actualTale, expectedTale)
def guruify():
    target = flask.request.form['data']
    print(target)
    p = Poet()
    target = "https://en.wikipedia.org/wiki/" + target.replace(' ','_')
    p.target(target)
    try:
        poem = p.getpoem()
    except:
        poem = "No wisdom about this"
    ps = poem.split()
    commonbaddies = [
    'and',
    'of',
    'the',
    'as',
    'for'
    'a',
    'to',
    'like',
    'in'
    ]
    for word in ps[::-1]:
        if word in commonbaddies:
            ps = ps[:-1]
        else:
            break
    q = len(ps) // 4
    poem = ' '.join(ps[:q]) + '|' + ' '.join(ps[q:q*2]) + '|' + ' '.join(ps[q*2:q*3]) + '|' + ' '.join(ps[q*3:])
    return poem
Esempio n. 5
0
    def test_recite_contains_day(
        self
    ):  # TODO - hard to understand, what is Tale Day? The initial problem has no such word.
        poet = Poet(Poem(POEM), NoEchoFormatter())
        tale = poet.recite()

        actualTaleDay = len(poet.poem.getPoem())  # TODO - don't invent words
        expectedTaleDay = tale.count("Day")
        self.assertEqual(actualTaleDay, expectedTaleDay)
Esempio n. 6
0
def guruify():
    target = flask.request.form['data']
    print(target)
    p = Poet()
    target = "https://en.wikipedia.org/wiki/" + target.replace(' ', '_')
    p.target(target)
    try:
        poem = p.getpoem()
    except:
        poem = "No wisdom about this"
    return poem
Esempio n. 7
0
    def test_reveal_for_day_5(
            self):  # TODO - try to see if you can  use multi-line strings
        poet = Poet(Poem(POEM), NoEchoFormatter())
        actualTale = poet.revealForDay(5)

        expectedTale = "This is the dog that worried\n\t" \
            + "the cat that killed\n\t" \
            + "the rat that ate\n\t" \
            + "the malth that lay in\n\t" \
            + "the house that Jack built." \

        self.assertEqual(actualTale, expectedTale)
Esempio n. 8
0
    def test_recite_reveal_everyday_tale(
        self
    ):  # TODO - the test can be more specific, like how many days should exist? What should be the length of the poem?
        poet = Poet(Poem(POEM), NoEchoFormatter())
        tale = poet.recite()

        actualTaleDay = len(poet.poem.getPoem())
        expectedTaleDay = tale.count("Day")

        for day in range(1, actualTaleDay + 1):
            dayString = "Day {0} -".format(day)
            self.assertNotEqual(
                tale.index(dayString), -1
            )  # TODO Complicated way of saying that something should exist. Is there is a simpler method to do that.
Esempio n. 9
0
    def run():
        parser = Parser()
        parser.checkArgs()
        args = parser.getArgs()

        poem = Poem(POEM, Main.getRandom(args))
        poet = Poet(poem, Main.getEcho(args))
        shouldRecite = args[constant.RECITE_DEST]

        if shouldRecite:
            tale = poet.recite()
            print(tale)
        else:
            forWhichDay = args[constant.REVEAL_FOR_DAY_DEST][0]
            tale = poet.revealForDay(forWhichDay)
            print(tale)
Esempio n. 10
0
    def test_reveal_for_day_1(self):
        poet = Poet(Poem(POEM), NoEchoFormatter())
        actualTale = poet.revealForDay(1)
        expectedTale = "This is the house that Jack built."

        self.assertEqual(actualTale, expectedTale)
Esempio n. 11
0
from functions import *
from poet import Poet

if __name__ == "__main__":

    h3 = 0.9
    h2 = 0.099
    h1 = 0.001
    e = 0.00002

    ferdowsi = Poet('train_set//ferdowsi_train.txt', 'ferdowsi')
    hafez = Poet('train_set//hafez_train.txt', 'hafez')
    molavi = Poet('train_set//molavi_train.txt', 'molavi')

    verify_test_set(h3, h2, h1, e, ferdowsi, hafez, molavi,
                    'test_set//test_file.txt')