Spring 2012»CSCI 470 Homework 2

CSCI 470 Homework 2

Assigned Date: Tuesday, Feb. 7, 2012
Due Date: Tuesday, Feb. 21, 2012
Due Time: 10:50am

Last modified on February 16, 2012, at 10:45 AM (see updates)


This assignment's objectives are:

  • Understand knowledge representation schemes and related issues.
  • Gain experience in programming with a programming language used in AI applications.
  • Develop working knowledge, in terms of understanding the theory and being able to design/implement working applications, of at least one AI area.

This is a solo assignment (i.e., you must do it alone). You may discuss the assignment only with the instructor.


Write a Python poem generator using Markov models and text available on the Internet.


Your program should:

  1. Utilize one (or more) Markov model(s) to analyze text.
  2. Read a collection of text files (poems, books, etc.) from a subdirectory called data.
  3. Output a poem (in the "style" of the texts read in as input) to the standard output.

Your program should also:

  1. Have some way of evaluating its output (a crude way is fine). Let's call this its fitness function. The fitness function should accept a string as input, and return a numeric value as output (the larger, the better).
  2. Loop enough times generating poems and keeping only the best (as per your fitness function).


Follow the Golden Rule of Style: "A program should be as easy for a human being to read and understand as it is for a computer to execute." [1]

In general, you should comment any variable, obscure statement, block of code, etc. you create.

Also, you should comment why something is being done, e.g.,

numStudents += 1   # we have processed one more student

as opposed to how it is done, e.g.,

numStudents += 1   # increment numStudents by one

Finally, your code should always include opening comments as follows.

(NOTE: Angle brackets signify information that needs to be filled out. Remove the angle brackets!)

#   Author:     <Your Name(s)>
#   Email:      <Your email address(es)>
#   Class:      CSCI 470, Section 1
#   Assignment: HMWK1
#   Due Date:   <The assignment's due date>
#   Certification of Authenticity <remove one of the following>:     
#     I certify that this lab is entirely my own work.
#      I certify that this lab is my own work, but I received
#      some assistance from:  <Name(s)>
#   TASK:   <Provide a simple, yet complete description of the task being
#           performed by this program. It may be several sentences long.>
#   INPUT:  <Describe the input to this program.  Be thorough.>
#   OUTPUT: <Describe the output to this program.  Be thorough.>


Submit your assignment on OAKS by the due date. Your submission must include:

  1. Your Python AI program, called poemGenerator.py . Your program should run as follows:
    python poemGenerator.py
    (the data subdirectory should be placed in the same directory as your program)
  2. Three poems generated from your program, called poem1.txt, poem2.txt, and poem3.txt that best demonstrate your programs poetic prowess. Note that these poems must be generated from the same input data.
  3. A README.txt file, which describes the data and explains how it was acquired (i.e., URLs).
  4. Your input data stored in a zip file, called data.zip.


Your grade will be based on the elegance of your design, the quality of your documentation, and how well you followed the above instructions. In particular, there are many ways to achieve the above functionality. Aim for simplicity and elegance. Design, design, design... before you implement.


  1. Cooper, D. and Clancy, M. (1985) "Oh! Pascal", 2nd ed., W.W. Norton & Company, New York, p. 42.

Relevant Quote

"Any amount of work can be done in any amount of time... only the quality varies." ~Joao Meidanis