Question: Please answer following questions along with Python code and its result. Make sure to import NLTK 1. Save some text into a file corpus.txt. Define

Please answer following questions along with Python code and its result. Make sure to import NLTK

1. Save some text into a file corpus.txt. Define a function load(f) that reads from the file named in its sole argument, and returns a string containing the text of the file. Use nltk.regexp_tokenize() to create a tokenizer that tokenizes the following kinds of expressions: monetary amounts; dates.

2. Rewrite the following loop as a list comprehension:

>>> sent = ['The', 'dog', 'gave', 'John', 'the', 'newspaper']

>>> result = []

>>> for word in sent:

... word_len = (word, len(word))

... result.append(word_len)

>>> result

[('The', 3), ('dog', 3), ('gave', 4), ('John', 4), ('the', 3), ('newspaper', 9)]

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!