代做CSC108H Assignment 3: Poetry Form Checker代做留学生Python程序

Assignment 3

· Due Nov 26 by 4p.m.

· Points 8

CSC108H Assignment 3: Poetry Form. Checker

Due Date: Tuesday, November 26, 2024 before 4:00pm

Read this handout thoroughly, especially the tips on how to tackle the assignment.

Goals of this Assignment

· Writing code that uses dictionaries and reads from files.

· Using top down design to break a problem down into subtasks and implementing helper functions to complete those tasks.

· Writing unit tests (using pytest ) to check whether a function implementation is correct.

· Practice reading problem descriptions written in English, together with provided docstring examples, and implementing function bodies to solve the problems.

· Continue to use Python 3, Wing 101, provided starter code, a checker module, and other tools.

Poetry Form. Checker

Limericks, sonnets, haiku, and other forms of poetry each follow prescribed forms that specify the number of lines, the number of syllables on each line, and a rhyme scheme.

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 form. Here is your chance to resolve the question! In this assignment, you will work on a program that reads a poem from a file, determines how to pronounce the poem, counts the number of syllables in each line, and determines whether lines rhyme.

Definitions

In this section we provide definitions for terms that are used in the handout. All links go to https://dictionary.comLinks to an external site..

poemLinks to an external site.

a composition in verse, especially one that is characterized by a highly developed artistic form. and by the use of heightened language and rhythm to express an intensely imaginative interpretation of the subject

rhymeLinks to an external site.

a word agreeing with another in terminal sound: Find is a rhyme for mind and womankind

consonantLinks to an external site.

(in English articulation) a speech sound produced by occluding with or without releasing (p, b; t, d; k, g), diverting (m, n, ng), or obstructing (f, v; s, z, etc.) the flow of air from the lungs (opposed to vowel)

vowelLinks to an external site.

(in English articulation) a speech sound produced without occluding, diverting, or obstructing the flow of air from the lungs (opposed to consonant)

syllableLinks to an external site.

an uninterrupted segment of speech consisting of a vowel sound, a diphthong, or a syllabic consonant, with or without preceding or following consonant sounds

There are many vowel sounds. For example, the words freightfraughtfruit, and fright all contain different vowel sounds — there are far more vowel sounds than there are letters that we use to describe them: a, e, i, o, u, and sometimes y.

Poetry Form. Example: Limerick

Here is a stupendous work of limerick art. The lines have been numbered and we have highlighted the last word of each line, because those words must rhyme according to the rhyme scheme for limericks.

1. I wish I had thought of a rhyme

2. Before I ran all out of time!

3. I'll sit here instead,

4. A cloud on my head

5. That rains 'til I'm covered with slime.

Here is a decription of the form. of a limerick. Limericks are five lines long. Lines 1, 2, and 5 each contain eight syllables and the last words on these lines rhyme with each other. Lines 3 and 4 each contain five syllables and the last words 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; we will be counting syllables, but not paying attention to whether they are stressed or unstressed.)

The CMU Pronouncing Dictionary

To determine whether or not two words rhyme, we will use data that describe how to pronounce words.

The Carnegie Mellon University Pronouncing DictionaryLinks to an external site. describes how to pronounce words. Here is the entry for DAVID: D EY1 V IH0 D. There are five phonemes in David, namely 'D', 'EY1', 'V', 'IH0', and 'D'. Each phoneme describes a sound. The sounds are either vowel sounds or consonant sounds. We will refer to phonemes that describe vowel sounds as vowel phonemes, and similarly for consonants.

The phonemes were defined in a project called ArpabetLinks to an external site. that was created by the Advanced Research Projects Agency (ARPA)Links to an external site. back in the 1970's.

One can download a text file containing the CMU Pronouncing Dictionary: all the words together with their pronunciations. All vowel phonemes end in a 0, 1, or 2, with the digit indicating a level of syllabic stress. Consonant phonemes do not end in a digit. The number of syllables in a word is the same as the number of vowel sounds in the word, so you can determine the number of syllables in a word by counting the number of phonemes that end in a digit.

As an example, in the word secondary (S EH1 K AH0 N D EH2 R IY0), there are 4 vowel phonemes, and therefore 4 syllables. The vowel phonemes are EH1, AH0, EH2, and IY0.

In case you're curious, 0 means unstressed, 1 means primary stress, and 2 means secondary stress — try saying "secondary" out loud to hear for yourself which syllables have stress and which do not. In this assignment, your program will not need to distinguish between the levels of syllabic stress.

The assignment zipfile includes the file pronunciation_dictionary.txt, which contains our version of the Pronouncing Dictionary. Your program will read this file. You must use it, and not any other versions of the CMU Pronouncing Dictionary, because our version differs slightly from the CMU version. We have removed alternate pronunciations for words, and we have removed words that do not start and end with alphanumeric characters (like #HASH-MARK, #POUND-SIGN and #SHARP-SIGN). Open the pronunciation_dictionary.txt file to see the format; notice that any line beginning with ;;; is a comment.

The words in pronunciation_dictionary.txt are all uppercase and do not contain surrounding punctuation. When your program looks up a word, use the uppercase form, with no leading or trailing punctuation. Function transform_string() in the starter code file poetry_functions.py will be helpful here.

We have also provided a small, three word CMU Pronouncing Dictionary named pronunciation_dictionary_small.txt, for use in docstring examples.

Describing Poetry Forms

For each type of poetry form (limerick, haiku, etc.), we will write its rules as a poetry form. description. Here's our poetry form. description for the limerick poetry form.

    Limerick

    8 A

    8 A

    5 B

    5 B

    8 A

On each line, the first piece of information is a number that indicates the number of syllables required on that line of the poem. The second piece of information on each line is a rhyme label, a letter that indicates the pattern of end rhymes. Here, lines 1, 2, and 5 of a Limerick poem must rhyme with each other because they're all labeled with the same letter (A), and lines 3 and 4 must rhyme with each other because they're both labeled with the same letter (B). (Note that the choice to use the letters A and B was arbitrary. Other letters could have been used to describe this rhyme scheme.)

Two lines of a poem rhyme with each other when the last syllable of the last word on each of the two lines rhyme. Two syllables rhyme when their vowels are the same and they end in the same sequence of consonant phonemes. For instance, the words gosh and wash are entered in pronunciation_dictionary.txt as GOSH G AA1 SH and WASH W AA1 SH respectively. Both end in the same vowel phoneme AA1 and the same consonant phoneme SH, so they rhyme. Another example of rhyming words is okay (OKAY OW2 K EY1) and overstay (OVERSTAY OW2 V ER0 S T EY1).

Some poetry forms don't require lines that rhyme. For example, the haiku form. has 5 syllables in the first line, 7 in the second line, and 5 in the third line, but there are no rhyme requirements. Here is an example:

    Dan's hands are quiet.

    Soft peace surrounds him gently:

    No thought moves the air.

We'll indicate the lack of a rhyme requirement by using the rhyme label *. Here is our poetry form. description for the haiku poetry form.

    Haiku

    5 *

    7 *

    5 *

Some poetry forms have rhyme requirements but don't have a specified number of syllables per line. Quintain (English) is one such example; these are 5-line poems with an ABABB rhyme scheme, but with no syllable requirements. Here is our poetry form. description for the Quintain (English) poetry form. (notice that 0 is used to indicate that there is no requirement on the number of syllables in the line):

    Quintain (English)

    0 A

    0 B

    0 A

    0 B

    0 B

Here's an example of a Quintain (English) from Percy Bysshe Shelly's Ode To A Skylark:

    Teach us, Sprite or Bird,

    What sweet thoughts are thine:

    I have never heard

    Praise of love or wine

    That panted forth a flood of rapture so divine.

Your program will read a poetry form. description file containing poetry form. names together with their description. For each poetry form. in the file:

· the first line gives the name of the poetry form.

· subsequent lines contain the number of syllables and rhyme scheme for each line of poetry

· each poetry form. is separated from the next by a blank line

You may assume that the poetry form. names given in a poetry form. description file will all be different.

We have provided two poetry form. description files, poetry_forms.txt and poetry_forms_small.txt, as example poetry form. description files. The first is used by the Poetry Form. Checker program poetry_program.py while the second is used in doctest examples. We will test your code with these and other poetry form. description files.

Note: Many poetry forms don't have a fixed number of lines. Instead, they specify what a stanza looks like, and then the poetry is made up of as many stanzas as the poet likes. We will not consider stanza-based poems in this assignment.

Data Representation

We use the following Python definitions to create new types relevant to the problem domain. Read the comments in starter code file poetry_constants.py for detailed descriptions with examples.

Type variables defined in poetry_constants.py

 

POEM_LINE

str

POEM

list[POEM_LINE]

PHONEMES

tuple[str]

PRONUNCIATION_DICT

dict[str, PHONEMES]

POETRY_FORM_DESCRIPTION

tuple[tuple[int], tuple[str]]

POETRY_FORM_DICT

dict[str, POETRY_FORM_DESCRIPTION]

Valid Input

For all poetry samples used in this assignment, you should assume that all words in the poems will appear as keys in the pronunciation dictionary. We will test with other pronunciation dictionaries, but we will always follow this rule.

Task 1: Required Functions for Poetry Processing

In starter code file poetry_functions.py, complete the following function definitions. In addition, you may add some helper functions to aid with the implementation of these required functions.

Function name:
(Parameter types) -> Return type

Full Description (paraphrase to get a proper docstring description)

get_syllable_count:
(POEM_LINE, PRONUNCIATION_DICT) -> int

The first parameter represents a non-empty line from a poem that has had leading and trailing whitespace removed. The second parameter represents a pronunciation dictionary. This function is to return the number of syllables in the line from the poem. The number of syllables in a poem line is the same as the number of vowel phonemes in the line.
Assume that the pronunciation for every word in the line may be found in the pronunciation dictionary.
HINT: Method str.split() and helper functions transform_string() and is_vowel_phoneme() may be helpful.

check_syllable_counts:
(POEM, POETRY_FORM_DESCRIPTION, PRONUNCIATION_DICT) ->
list[POEM_LINE]

The first parameter represents a poem that has no blank lines where each line has had leading and trailing whitespace removed. The second parameter represents a poetry form. description. And the third parameter represents a pronunciation dictionary. This function is to return a list of the lines from the poem that do not have the right number of syllables for the poetry form. description. The lines should appear in the returned list in the same order as they appear in the poem. If all lines have the right number of syllables, return the empty list. The number of syllables in a line is the same as the number of vowel phonemes in the line.
Recall that every line whose required syllable count value is 0 has no syllable count requirement to meet.

get_last_syllable:
(PHONEMES) -> PHONEMES

The parameter represents a tuple of phonemes. The function is to return a tuple that contains the last vowel phoneme and any consonant phoneme(s) that follow it in the given tuple of phonemes. The ordering of phonemes in the tuple returned must be the same as in the given tuple. Return an empty tuple if the tuple of phonemes does not contain a vowel phoneme.
HINT: Helper function is_vowel_phoneme() may be helpful.

words_rhyme:
(str, str, PRONUNCIATION_DICT) -> bool

The first and second parameters each represent a word. The third parameter represents a pronunciation dictionary. The function is to return whether or not the two words rhyme, according to the pronunciation dictionary.
Assume that the pronunciation for both words may be found in the pronunciation dictionary.
Recall that two words rhyme if and only if they have the same last syllable.

all_lines_rhyme:
(POEM, list[int], PRONUNCIATION_DICT) -> bool

The first parameter represents a poem that has no blank lines and has had leading and trailing whitespace removed. The second parameter represents a list of poem line indexes. The third parameter represents a pronunciation dictionary. The function is to return whether or not each of the lines in the poem, whose index is in the list given by the second parameter, rhyme according to the pronunciation dictionary.
Recall that two lines in a poem rhyme if and only if the last word on each line rhyme.
Assume that the pronunciation for the words in the poem lines may be found in the pronunciation dictionary, and that the list of line indexes is not empty and only contains valid line indexes for the given poem.

get_rhyme_label_to_lines:
(tuple[str]) -> dict[str, list[int]]

The first parameter represents a rhyme scheme, in the format of the second item in a POETRY_FORM_DESCRIPTION type. The function is to return a Python dict where each key is a rhyme label given in the rhyme scheme. The value associated with each key is a list of the indexes in the rhyme scheme where the rhyme label appears.
Return an empty dictionary if the rhyme scheme is empty.

check_rhyme_scheme:
(POEM, POEM_FORM_DESCRIPTION, PRONUNCIATION_DICT) ->
list[list[POEM_LINE]]

The first parameter represents a poem that has no blank lines and has had leading and trailing whitespace removed. The second parameter represents a poetry form. description. And the third parameter represents a pronunciation dictionary. Return a list of lists of lines from the poem that do not rhyme according to the poetry form. description. If all lines rhyme as they should according to the poetry form, return an empty list.
Recall that every line whose rhyme label is * has no rhyme requirement to meet.
Notes:

· The lines should appear in each inner list in the same order as they appear in the poem.

· If n lines are supposed to rhyme with each other and at least one line does not, all n lines should appear in the inner list. For example:

if the rhyme scheme is ('A', 'A', 'B', 'B', 'A'),

and the poem lines are ['On the', 'plains, a', 'triceratops climbs.', 'The day adjourns.', 'Absurd!'],

this function should return either [['On the', 'plains, a', 'Absurd!'], ['triceratops climbs.', 'The day adjourns.']] or [['triceratops climbs.', 'The day adjourns.'], ['On the', 'plains, a', 'Absurd!']].


热门主题

课程名

mktg2509 csci 2600 38170 lng302 csse3010 phas3226 77938 arch1162 engn4536/engn6536 acx5903 comp151101 phl245 cse12 comp9312 stat3016/6016 phas0038 comp2140 6qqmb312 xjco3011 rest0005 ematm0051 5qqmn219 lubs5062m eee8155 cege0100 eap033 artd1109 mat246 etc3430 ecmm462 mis102 inft6800 ddes9903 comp6521 comp9517 comp3331/9331 comp4337 comp6008 comp9414 bu.231.790.81 man00150m csb352h math1041 eengm4100 isys1002 08 6057cem mktg3504 mthm036 mtrx1701 mth3241 eeee3086 cmp-7038b cmp-7000a ints4010 econ2151 infs5710 fins5516 fin3309 fins5510 gsoe9340 math2007 math2036 soee5010 mark3088 infs3605 elec9714 comp2271 ma214 comp2211 infs3604 600426 sit254 acct3091 bbt405 msin0116 com107/com113 mark5826 sit120 comp9021 eco2101 eeen40700 cs253 ece3114 ecmm447 chns3000 math377 itd102 comp9444 comp(2041|9044) econ0060 econ7230 mgt001371 ecs-323 cs6250 mgdi60012 mdia2012 comm221001 comm5000 ma1008 engl642 econ241 com333 math367 mis201 nbs-7041x meek16104 econ2003 comm1190 mbas902 comp-1027 dpst1091 comp7315 eppd1033 m06 ee3025 msci231 bb113/bbs1063 fc709 comp3425 comp9417 econ42915 cb9101 math1102e chme0017 fc307 mkt60104 5522usst litr1-uc6201.200 ee1102 cosc2803 math39512 omp9727 int2067/int5051 bsb151 mgt253 fc021 babs2202 mis2002s phya21 18-213 cege0012 mdia1002 math38032 mech5125 07 cisc102 mgx3110 cs240 11175 fin3020s eco3420 ictten622 comp9727 cpt111 de114102d mgm320h5s bafi1019 math21112 efim20036 mn-3503 fins5568 110.807 bcpm000028 info6030 bma0092 bcpm0054 math20212 ce335 cs365 cenv6141 ftec5580 math2010 ec3450 comm1170 ecmt1010 csci-ua.0480-003 econ12-200 ib3960 ectb60h3f cs247—assignment tk3163 ics3u ib3j80 comp20008 comp9334 eppd1063 acct2343 cct109 isys1055/3412 math350-real math2014 eec180 stat141b econ2101 msinm014/msing014/msing014b fit2004 comp643 bu1002 cm2030
联系我们
EMail: 99515681@qq.com
QQ: 99515681
留学生作业帮-留学生的知心伴侣!
工作时间:08:00-21:00
python代写
微信客服:codinghelp
站长地图