Fill This Form To Receive Instant Help
Homework answers / question archive / 2
2.1 Definition of a Rhyme It turns out that there are many different kinds of rhymes (see Wikiepedia for
a discussion). For the purposes of this assignment, we will focus on perfect
rhymes. Wikipedia defines this kind of rhyme as satisfying the following two
conditions:
e The stressed vowel sound (i.e., the primary stress) in both words must
be identical, as well as any subsequent sounds. For example, “sky” and
“high,” or “skylight” and “highlight.”
e The phoneme that preceds the stressed vowel must not be the same. For
example, “bean” and “green” is a perfect rhyme, but “leave” and “believe”
is not.!
e If a word does not have a primary strees, or if the primary stress is on the
first phoneme, then (for the purposes of this program), we will say that
it has no rhymes. (I’m not sure what linguists would say about this, but
it’s good enough for our project.)
In the rest of this document, “rhyme” refers to perfect rhymes unless otherwise
specified.
2.2 How Phonemes Work
The pronunciation dictionaries used in this assignment are based on the system
used in the Carnegie Mellon Pronunciation Dictionary. Basically, they have
built a list of all of the sounds used in English, and have built a very long list
of words, along with the pronunciation(s) for each word. (Some words have
multiple pronunciations. )
The pronunciation is broken into “phonemes,” which are basic units of sound;
each possible phoneme is represented by a string of letters. For instance, the
“uh” sound in “hut” is represented by AH. In the pronunciation dictionary, the
entry for “hut” looks like this:
HUT HH AH T
which means that the word is made up of three phonemes.
(Note that phonemes are not the same as syllables: a syllable can contain
many phonemes. )
' Linguist Note: This definition is not strictly correct, because syllables have stress, not
phonemes. And rhymes are defined by the start of the syllable being different, not the single
phoneme. However, our dataset only tells us about phonemes, not syllables, and so we are
limited: our programs can only make decisions based on the phonemes.
As such, our rhyming program will sometimes reject rhymes which it should find. But it's
the best we have for now.
In most (not all) words, some of the phonemes have “stress” - meaning that they
are emphasized more than the rest. There are three possible types of stress; each
is represented by a number attached to the phoneme:
e (2): no stress
e 1: primary stress
e 2: secondary stress
For instance, consider the words “weekly” and “computerize.” In “weekly,”
the primary stress is on the second phoneme, and “no stress” is on the last. In
“computerize,” the primary stress is on the sixth phoneme, secondary stress is
on the ninth, and “no stress” is on the second and eighth phonemes.
WEEKLY W IYi K L IYO
COMPUTERIZE K AHO M P Y UW1 T ERO AY2 Z
3 Program Requirements
Write a program, named rhymes.py . Prompt the user for a filename; (don't
print out any prompt text). Don't worry about having a loop here; we won't
test this program with invalid input for the first line. Open the requested file,
and read the contents; it will be a Pronunciation Dictionary, made up of many
lines like the entries we've seen above. (We will give you a few examples on the
class website.)
Store the information from the Pronunciation Dictioanry into a variable (1
would recommend a Python dictionary).
Once you have read the contents of the pronunciation dictionary (and stored
it into some internal data structure), read each additional line of input. all the
way to EOF (end-of-file). Do not print any prompts. For each line of input.
sanity-check that the line is reasonable:
e If the line is blank (that is, only has whitespace). print
No word given.
followed by a blank line, and then immediately read the next line of input.
e If the line has more than 1 word on it, report the error
Multiple words entered, please enter only one word at a time.
followed by a blank line, and then immediately read the next word of
input.
e Otherwise, do the rhyme search described below. After printing the output
described below, print a blank line and then read the next line of input.
Each time that you read a valid line of input, you will search the pronunciation
dictionary (or rather, your copy of it in memory). looking for rhymes of that
word. You will print out all of the rhymes you find. Print out the rhymes with
one rhyme per line, sorted alphabetically, like this:
The user types “silly” as the first line. You print:
Rhymes for: SILLY
CHILE
CHILI
LILLY
The user types “Sour” as the first line. You print:
Rhymes for: SOUR
DOUR
OVERPOWER
SHOWER
THREE-HOUR
TOWER
The user types “FOUR” as the first line. You print:
Rhymes for: FOUR
BOER
DOOR
STORE
If. during any search, you find the sane word twice, only print it once.
If a word doesn't have any rhymes. then print the line -- none found --
in place of any words.
The user types “difficult” as the first line. You print:
Rhymes for: DIFFICULT
-- none found --
3.2 Case Sensitivity
Throughout this program. all data (read from the pronunciation dictionary, or
words-to-search provided by the user) should be treated as case insensitive.
However. in order to make it possible to auto-grade this assignment. you
inust print out your results in ALL CAPS (except as shown in the examples
above).