1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Misha Larkins [42]
2 years ago
8

Define a function called 'findWordFreq, which takes two parameters. The first parameter, 'text" is an nltk.text.Text object and

the second parameter, 'word' is a string. The function definition code stub is given in the editor. Perform the given operation for the 'text' object and print the results: 11 Determine the frequency distribution of all words having only alphabets in "text", store into a variable 'textfreq 15 • Find the frequency for the given 'word, and store it into the variable 'wordfreq'. • Find the word which has a maximum frequency from the textfreq , and store into the variable 'maxfreq! 16 17 19 Return 'wordfreq' and 'maxfreq. variables from the function. Input Format for Custom Testing Input from stdin will be processed as follows and passed to the function. Python 3 • Autocomplete Ready O 8 import zipfile from nltk.corpus import gutenberg 10 from nltk. text import Text import nltk 12 13 14 # Complete the 'findWordFreq' function below. def findWordFreq(text, word): # Write your code here textfreq = nltk. FreqDist(text) 18 wordfreq = nltk.FreqDist(word) maxfreq = nltk.FreqDist(text) 20 return wordfreq, maxfreq 21 22 vif -_name__ == '__main__': 23 text = input() 24 word = input() 25 if not os.path.exists(os.getcwd() + "/nltk_data"): 26 with zipfile.ZipFile("nltk_data.zip", 'r') as zip_ref: 27 zip_ref.extractall(os.getcwd()) 28 os.environ['NLTK_DATA'] = os.getcwd() + "/nltk_data" 30 text = Text(gutenberg.words (text)) 31 32 word_freq, max_freq = findWordFreq(text, word) 33 34 print(word_freq) 35 print(max_freq) The first line contains a string 'text', which should be one of the text collection file names from gutenberg corpora. The second line contains a string 'word. Find the frequency for the word, Sample Case Sample Input 29 Function Parameters STDIN ----- ------- austen-sense.txt John → text = nltk.Text(nltk.gutenberg.words ('austen-sense.txt → word = 'John! Line: 19 Col Sample Output Test Results Custom Inpus Run Submit Cod 163 to No test case passed. Input (stdin) 1 austen-sense.txt 2. John Your Output (stdout) 1 2. Expected Output 1 163 2 to
Computers and Technology
1 answer:
MakcuM [25]2 years ago
4 0

Answer:

import os

import nltk

import zipfile

from nltk. corpus import gutenberg

from nltk. text import Text

def findWordFreq(text, word):

   textfreq = nltk. FreqDist(text)

   wordfreq = nltk.FreqDist(word)

   maxfreq = max(textfreq)

   return wordfreq, maxfreq

if -_name__ == '__main__':

   text = input()

   word = input()

   if not os.path.exists(os.getcwd() + "/nltk_data"):

       with zipfile.ZipFile("nltk_data.zip", 'r') as zip_ref:

           zip_ref.extractall(os.getcwd())

   os.environ['NLTK_DATA'] = os.getcwd() + "/nltk_data"

   text = Text(gutenberg.words (text))

   word_freq, max_freq = findWordFreq(text, word)

   print(word_freq)

   print(max_freq)

Explanation:

The natural language package in python is used to get and analyse word from voice input. The python code above get words from a zipfile extract, and the 'findWordFreq' function gets the word count and the maximum number of alphabet used in the word distribution.

You might be interested in
What command is used to generate an RSA key pair?
Leokris [45]

Answer:

D) crypto key generate rsa

Explanation:

In cryptography, the RSA refers to Rivest–Shamir–Adleman. This is an algorithm used for encrypting and decrypting messages in computers thereby ensuring secured transmission of data. In order to generate an RSA key pair, you will use the command crypto key generate rsa while in the global configuration mode. This command has the following syntax:

crypto key generate rsa [general-keys| usage-keys| signature| encryption] [<em>labelkey-label</em>] [exportable] [modulus <em>modulus-size</em>] [storage <em>name of device</em>:][redundancy][on <em>name of device</em>:],

with each parameter having its description

5 0
3 years ago
What can be designed to create annoying glitches or destroy data
Katen [24]

I guess the best answer is Virus.

Virus is a malicious computer program that is designed to create annoying glitches or destroy data.

3 0
2 years ago
Read 2 more answers
Creating a newsletter
pav-90 [236]
This isn’t helpful considering no one knows what type of news letter you want
6 0
2 years ago
Canada’s energy plan, named __________, makes three governmental agencies accountable for safeguarding Canada’s environment.
stepan [7]

Answer:

Canada launched the national Generation Energy Council of leading Canadians, who proposed principles to the Government of Canada on how to build our energy future. Today, these principles guide government decisions to support Canadian families, businesses, and communities. Together, we are: saving energy powering clean communities.

Explanation:

8 0
2 years ago
The Syntax NPV formula includes the Rate, The Cash Flows, the number of payments, and the Future
Tems11 [23]

Answer:

False

Explanation:

NPV stands for Net Present Value, it is an important term in finance as it used to determine the value of money or investment based on a series of cashflows and specified discount rate. Excel provides a functions which aids easy calculation of the Net Present value of money or investment using the NPV formula. The syntax forbthe NPV formula is :

=NPV(rate,value 1, [value 2],...)

This formular requires only tow key parameters ; the discount rate, which comes first and the cashflows, which is designated in the syntax as values ; the cashflows is usually placed in a range of cells in excel and the cell range is inputed in the formular. Hence, the number of payments and future value aren't part of the NPV syntax.

5 0
2 years ago
Other questions:
  • The spreadsheet below shows the names years in office, and number of terms for five US presidents
    7·2 answers
  • The strFirstName and strLastName variables contain the strings "Jane" and "Jones," respectively. Which of the following statemen
    14·1 answer
  • 1. of the following individuals, who was the most recent to develop information searching tools online? (points : 1) otlet wells
    5·1 answer
  • The item that is clicked in a JList can be retrieved using the _____ method of JList.
    8·1 answer
  • Is full dive vr possible and can we accomplish it with today’s technology? Explain why
    13·2 answers
  • Can someone help me i need to write something for cyber bullying
    11·2 answers
  • Colin Mackay Inc., a software company with its head office in Amsterdam, has employees across three continents. Certain project
    11·1 answer
  • Most airlines use very modern hardware and software.<br><br><br> True<br><br> False
    9·1 answer
  • Primary functions of lighting are sufficient light to...
    13·1 answer
  • Reading (BCK FORM 2C IT 2020-2021)
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!