Question: import random def getwords(fileName): file = open(fileName, 'r') text = file.read() stopletters = [., ,, ;, :, 's, '', !, ?, (, ), '', '']text

import random

def getwords(fileName):

file = open(fileName, 'r')

text = file.read()

stopletters = [".", ",", ";", ":", "'s", '"', "!", "?", "(", ")", '', '']text = text.lower()

for letter in stopletters:

text = text.replace(letter, "")

words = text.split()

return words

def compute_bigrams(fileName):

input_list = getwords(fileName)

bigram_list = {}

for i in range(len(input_list)-1):

if input_list[i] in bigram_list: bigram_list[input_list[i]] = bigram_list[input_list[i]]+[input_list[i+1]]

else:

bigram_list[input_list[i]] = [input_list[i+1]]

return bigram_list

Copy and paste the code above into your editor

Use a large input text file (copy the content of a news article for example).

The file must be stored on the same folder where you have your program

Write the main program where you will call the get words and compute_bigrams functions. Give the name of your file as an argument to the functions.

Print the results returned by each function so that you observe what they do.

Implement the 2 algorithms provided earlier. Submit a program for each:

Generating Random Words (slide 4) 2-grams Algorithm (slide 8)

Generate 4 paragraphs with 100 words each.

Use a large input file. At least the size of a news article.

THE LINK TO THE ARTICLE IS BELOW

(https://www.nytimes.com/2018/11/12/obituaries/stan-lee-dead.html)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!