Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

25 Vba Macros For Data Analysis In Microsoft Excel

Authors: Klemens Nguyen

1st Edition

B0CNSXYMTC, 979-8868455629

More Books

Students also viewed these Databases questions

Question

Natural disasters

Answered: 1 week ago

Question

fscanf retums a special value EOF that stands for...

Answered: 1 week ago