Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Q2: Calculating Bigrams - 20 pts For this problem, we define a bigram as a tuple made of two consecutive words in a sentence.

Python image text in transcribed

Q2: Calculating Bigrams - 20 pts For this problem, we define a bigram as a tuple made of two consecutive words in a sentence. The file associated with this question is CalculatingBigrams.py. Part A (14 points): Complete the function calc_bigram(inp_str, punc) in the given file This part asks you to calculate the number of occurrences of "bigrams" given in a text (inp_str). You need to calculate the bigrams with only lowercase words, remove given punctuations (punc) and treat paragraphs (delimited by newlines) separately. You should return a dictionary (bigram_dict) with bigrams as keys and their counts as values. For example for the following sentence: "Can you can a can as a canner can can a can?" The bigrams (keys, note that they are tuples) and their counts are: ('can', 'you'): 1 ('you', 'can'): 1 ('can', 'a'): 2 ('a', 'can'): 2 ('can', 'as'): 1 (as', 'a'): 1 ('a', 'canner'): 1 ('canner', 'can'): 1 ('can', 'can'): 1 For the following sentences (there is a newline after the first point), the bigram ('picked', 'if') should not exist ***Peter Piper picked a peck of pickled peppers; A peck of pickled peppers Peter Piper picked. If Peter Piper picked a peck of pickled peppers, where's the peck of pickled peppers Peter Piper picked?" Part B (6 points): Complete the function remove_singles(bigram_dict) in the given file This part asks you to remove the bigrams that occur only once in the given bigram dictionary and return another dictionary containing the rest. For example for bigram dictionary created from the following sentence: "Can you can a can as a canner can can a can?" The remaining bigrams (that occur more than once) and their counts are: (can', 'a'): 2 ('a', 'can'): 2 Note for Both Parts: You do not need to do any error checking. The code file has further examples in its main function

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Question Can a self-employed person adopt a profit sharing plan?

Answered: 1 week ago