Poetry Form Checker(诗歌形式检测小程序)
Poetry Form Checker
Limericks, sonnets, haiku, and other forms of poetry each follow prescribed patterns that give the number of lines, the number of syllables on each line, and a rhyme scheme. For example, limericks are five lines long; the first, second, and fifth lines each have eight syllables and rhyme with each other; and the third and fourth lines each have five syllables and rhyme with each other. (There are additional rules about the location and number of stressed vs. unstressed syllables, but we’ll ignore those rules for this assignment.)
Here is a stupendous work of limerick art:
I wish I had thought of a rhyme
Before I ran all out of time!
I'll sit here instead,
A cloud on my head
That rains 'til I'm covered with slime.
We’re sure that you’ve all kept yourselves awake wondering if there was a way to have a computer program check whether a poem is a limerick or if it follows some other poetry pattern. Here’s your chance to resolve the question!
The CMU Pronouncing Dictionary
The Carnegie Mellon University Pronouncing Dictionary describes how to pronounce words. Head there now and look up a couple of words; try searching for words like “Daniel”, “is”, and “goofy”, and see if you can interpret the results. Do contractions like “I’ll” (short for “I will”) and “we’ll” (short for “we will”) work? Try clicking the “Show Lexical Stress” checkbox too, and see how that changes the result.
Here is the output for “Daniel” (with “Show Lexical Stress” turned on): D AE1 N Y AH0 L. Each of the separate pieces describes a sound; these pieces are called phonemes. The phonemes are either vowel sounds or consonant sounds, and they are from a project called Arpabet that was created by the Advanced Research Projects Agency (ARPA) back in the 1970’s. The vowel phonemes all have a number after them; these indicate a level of stress. For example, in “Daniel”, the stress falls on the first vowel, AE1, and the second vowel is unstressed, AH0. The higher the level of stress, the larger the number after the vowel phoneme. In the CMU Pronouncing Dictionary, stress is always on a vowel sound.
Your program will read the file dictionary.txt, which is our version of the Pronouncing Dictionary. You must use this file, not any files from the CMU website. Take a look at our dictionary.txt file to see the format; notice that any line beginning with ;;; is a comment and not part of the dictionary.
Notice that the words in dictionary.txt are all uppercase and that they do not contain surrounding punctuation. When your program looks up a word, use the uppercase form, with no leading or trailing punctuation. Function clean_up in the starter code file poetry_functions.py will be be helpful here.