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]
3 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]3 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
Janet needs to flag a message for follow-up in Outlook. Which option is not a default?
kari74 [83]
Answer:

Explanation:

Today
5 0
3 years ago
Read 2 more answers
Why are formulas used in spreadsheets?
cluponka [151]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The correct answer to this question is B.

The formulas in the spreadsheet are used to do the automatic calculation when data is changed in the spreadsheet.

For example, if you add numbers in a column and then get average. you can use sum() and average() formula to calculate the sum and average of numbers in a column. If you will change any number in the column, the calculation for sum and average automatically done. So, the answer to this question is B. i.e.

so that calculations are automatically redone when data is changed.

While the other options are not correct because:

  • To ensure data is entered correctly is done by validation not by using formula.
  • To ensure data is properly formated is done in the formatting section.
  • The error can be easily identified using validation features in excel.

7 0
3 years ago
Rewrite this method so that it avoids the use of a return statement:
olganol [36]
Sorry we chose 0 for the denominator
8 0
3 years ago
Technology __________ guides how frequently technical systems are updated, and how technical updates are approved and funded.
Nookie1986 [14]

Answer:

governance

Explanation:

5 0
2 years ago
Write a c++ program that prints the intial letter of any name​
Shalnov [3]

Answer:

#include<iostream>

using namespace std;

int main(){

char str[20];

int i=0;

std::cout<<"Enter a name:" ;

cin>>str;

cout<<*str;

while(str[i]!='\0'){

if(str[i]==' '){

i++;

cin>>*(str+i);

}

i++;

}

return 0;

}

6 0
3 years ago
Other questions:
  • A computer scientist creates a necklace to celebrate the birth of her daughter. The necklace encodes her daughter's
    6·1 answer
  • Add a function named circle to the polygons module. This function expects the same arguments as the square and hexagon functions
    9·1 answer
  • How do you take a picture on this app
    10·1 answer
  • Your ad can show on the Google Search Network when someone searches for terms that are similar to your:
    6·1 answer
  • Write a for loop that prints the values 1 2 4 8 16 32 64 by increasing the value of a counting variable by a factor of two in ea
    15·1 answer
  • Assignment 4: Evens and Odds<br><br><br> How do I fix this?
    13·1 answer
  • In binary, if there is a 1 in the 1s place the number is always
    9·1 answer
  • Question 1(Multiple Choice Worth 5 points)
    9·2 answers
  • A network administrator wants to authenticate server machines using Transport Layer Security (TLS). What can the administrator i
    15·1 answer
  • the function must find the substrings of s that start with a vowel and end with a consonant, then print the alphabetically first
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!