Question: I will appreciate some help with this python code.Attached below is the tester results. import analysis print(Analysis for testfile1.txt) analysis.load(testfile1.txt) print(Getting total word count -

 I will appreciate some help with this python code.Attached below is

I will appreciate some help with this python code.Attached below is the tester results.

import analysis print("Analysis for testfile1.txt") analysis.load("testfile1.txt") print("Getting total word count - should be 51") print(analysis.countall()) print("Getting unique word count - should be 5") print(analysis.countunique()) print("Getting common word out of ['apple','peach','pear'] - should be apple") print(analysis.commonword(["apple","peach","pear"])) print("Getting common word out of ['coconut','peach','banana'] - should be peach") print(analysis.commonword(["coconut","peach","banana"])) print("Getting common word out of ['pear','banana'] - should be pear") print(analysis.commonword(["pear","banana"])) print("Getting common word out of ['apple','peach','pear','coconut','banana'] - should be apple") print(analysis.commonword(['apple','peach','pear','coconut','banana'])) print("Getting common word out of ['plum','orange'] - should be None") print(analysis.commonword(['plum','orange'])) print("Getting common letter out of ['a','e','i','o','u'] - should be a") print(analysis.commonletter(['a','e','i','o','u'])) print("Getting common letter out of ['c', 't', 'p'] - should be p") print(analysis.commonletter(['c', 't', 'p'])) print("Getting common letter out of ['z','x','y'] - should be None") print(analysis.commonletter(['z','x','y'])) print("Getting common pair for 'apple' - should be coconut or peach") print(analysis.commonpair("apple")) print("Getting common pair for 'pear' - should be apple") print(analysis.commonpair("pear")) print("Getting common pair for 'banana' - should be peach") print(analysis.commonpair("banana")) print("Getting common pair for 'orange' - should be None") print(analysis.commonpair("orange")) print() print() print("Analysis for testfile2.txt") analysis.load("testfile2.txt") print("Getting total word count - should be 84") print(analysis.countall()) print("Getting unique word count - should be 5") print(analysis.countunique()) print("Getting common word out of ['apple','peach','pear'] - should be apple") print(analysis.commonword(["apple","peach","pear"])) print("Getting common word out of ['coconut','peach','banana'] - should be coconut") print(analysis.commonword(["coconut","peach","banana"])) print("Getting common word out of ['pear','banana'] - should be pear") print(analysis.commonword(["pear","banana"])) print("Getting common word out of ['apple','peach','pear','coconut','banana'] - should be coconut") print(analysis.commonword(['apple','peach','pear','coconut','banana'])) print("Getting common word out of ['plum','orange'] - should be None") print(analysis.commonword(['plum','orange'])) print("Getting common letter out of ['a','e','i','o','u'] - should be a") print(analysis.commonletter(['a','e','i','o','u'])) print("Getting common letter out of ['c', 't', 'p'] - should be p") print(analysis.commonletter(['c', 't', 'p'])) print("Getting common letter out of ['z','x','y'] - should be None") print(analysis.commonletter(['z','x','y'])) print("Getting common pair for 'apple' - should be coconut or peach") print(analysis.commonpair("apple")) print("Getting common pair for 'pear' - should be apple") print(analysis.commonpair("pear")) print("Getting common pair for 'banana' - should be apple") print(analysis.commonpair("banana")) print("Getting common pair for 'orange' - should be None") print(analysis.commonpair("orange")) print() print() print("Analysis for testfile3.txt") analysis.load("testfile3.txt") print("Getting total word count - should be 86") print(analysis.countall()) print("Getting unique word count - should be 5") print(analysis.countunique()) print("Getting common word out of ['apple','peach','pear'] - should be peach") print(analysis.commonword(["apple","peach","pear"])) print("Getting common word out of ['coconut','peach','banana'] - should be peach") print(analysis.commonword(["coconut","peach","banana"])) print("Getting common word out of ['pear','banana'] - should be pear") print(analysis.commonword(["pear","banana"])) print("Getting common word out of ['apple','peach','pear','coconut','banana'] - should be peach") print(analysis.commonword(['apple','peach','pear','coconut','banana'])) print("Getting common word out of ['plum','orange'] - should be None") print(analysis.commonword(['plum','orange'])) print("Getting common letter out of ['a','e','i','o','u'] - should be a") print(analysis.commonletter(['a','e','i','o','u'])) print("Getting common letter out of ['c', 't', 'p'] - should be c") print(analysis.commonletter(['c', 't', 'p'])) print("Getting common letter out of ['z','x','y'] - should be None") print(analysis.commonletter(['z','x','y'])) print("Getting common pair for 'apple' - should be peach") print(analysis.commonpair("apple")) print("Getting common pair for 'pear' - should be coconut or pear") print(analysis.commonpair("pear")) print("Getting common pair for 'banana' - should be coconut or peach") print(analysis.commonpair("banana")) print("Getting common pair for 'orange' - should be None") print(analysis.commonpair("orange")) print() print() print("Analysis for testfile4.txt") analysis.load("testfile4.txt") print("Getting total word count - should be 71") print(analysis.countall()) print("Getting unique word count - should be 5") print(analysis.countunique()) print("Getting common word out of ['apple','peach','pear'] - should be peach") print(analysis.commonword(["apple","peach","pear"])) print("Getting common word out of ['coconut','peach','banana'] - should be peach") print(analysis.commonword(["coconut","peach","banana"])) print("Getting common word out of ['pear','banana'] - should be pear") print(analysis.commonword(["pear","banana"])) print("Getting common word out of ['apple','peach','pear','coconut','banana'] - should be peach") print(analysis.commonword(['apple','peach','pear','coconut','banana'])) print("Getting common word out of ['plum','orange'] - should be None") print(analysis.commonword(['plum','orange'])) print("Getting common letter out of ['a','e','i','o','u'] - should be a") print(analysis.commonletter(['a','e','i','o','u'])) print("Getting common letter out of ['c', 't', 'p'] - should be p") print(analysis.commonletter(['c', 't', 'p'])) print("Getting common letter out of ['z','x','y'] - should be None") print(analysis.commonletter(['z','x','y'])) print("Getting common pair for 'apple' - should be peach") print(analysis.commonpair("apple")) print("Getting common pair for 'pear' - should be peach") print(analysis.commonpair("pear")) print("Getting common pair for 'banana' - should be pear") print(analysis.commonpair("banana")) print("Getting common pair for 'orange' - should be None") print(analysis.commonpair("orange")) print() print() print("Analysis for testfile5.txt") analysis.load("testfile5.txt") print("Getting total word count - should be 99") print(analysis.countall()) print("Getting unique word count - should be 5") print(analysis.countunique()) print("Getting common word out of ['apple','peach','pear'] - should be apple") print(analysis.commonword(["apple","peach","pear"])) print("Getting common word out of ['coconut','peach','banana'] - should be banana") print(analysis.commonword(["coconut","peach","banana"])) print("Getting common word out of ['pear','banana'] - should be banana") print(analysis.commonword(["pear","banana"])) print("Getting common word out of ['apple','peach','pear','coconut','banana'] - should be apple") print(analysis.commonword(['apple','peach','pear','coconut','banana'])) print("Getting common word out of ['plum','orange'] - should be None") print(analysis.commonword(['plum','orange'])) print("Getting common letter out of ['a','e','i','o','u'] - should be a") print(analysis.commonletter(['a','e','i','o','u'])) print("Getting common letter out of ['c', 't', 'p'] - should be p") print(analysis.commonletter(['c', 't', 'p'])) print("Getting common letter out of ['z','x','y'] - should be None") print(analysis.commonletter(['z','x','y'])) print("Getting common pair for 'apple' - should be banana") print(analysis.commonpair("apple")) print("Getting common pair for 'pear' - should be coconut, peach, or apple") print(analysis.commonpair("pear")) print("Getting common pair for 'banana' - should be apple") print(analysis.commonpair("banana")) print("Getting common pair for 'orange' - should be None") print(analysis.commonpair("orange")) 

Create a Python file called analysis.py that will perform text analysis on files. For this question, assume that each space jn the document separates one word from the next-so any use of the term "word' means a string that occurs between two spaces (or in two special cases between the start of the file and a space, or between a space and the end of the file). You can also assume there is no punctuation or other symbols present in the only words separated by spaces. If you want to see examples of the type of text, look in the testfile-txt files included on cuLearn You must implement and test the following functions inside of your analysis.py file 1) load (str) Takes a single string argument, representing a filename. The program must open the file and parse the text inside. This function will need to initialize the variables (e.g., lists, dictionaries, other variables) you need to solve the remainder of the problem. This function should also remove any information stored from a previous file (i.e., you start from nothing every time load is called) 2) commonword(list)-Takes a single list-type argument which contains string values The function should operate as follows: a. If the list is empty or none of the words specified in the list occur in the text that has been loaded, the function should return None b. Otherwise, the function should return the word contained in the list that occurs most often in the loaded text or any one of the most common, in the case of a tie 3) commonletter(list) Takes a single list-type argument which contains single character strings (i.e., letters/characters). The function should operate as follows: a. If the list is empty or none of the letters specified in the list occur in the text that has been loaded, the function should return None b. Otherwise, the function should return the letter contained in the list that occurs most often in the loaded text or any one of the most common, in the case of a tie 4) commonpair(str)-Takes a single string argument, representing the first word. This function should return the word that most frequently followed the given argument word (or one of, in case of ties). If the argument word does not appear in the text at COMP 1005/1405 W17 A4 Due Tuesday, March 21 at 11:55 PM all, or is never followed by another word (i.e., is the last word in the file), this function should return None 5) countai Returns the total number of words found in the text that has been loaded That is the word count of the document. 6) countunique0 Returns the number of unique words in the text that has been loaded. This is different than the previous function, as it should not count the same word more than once You can use the analysistester.py file from cuLearn, along with the posted text files, to test your functions. You can also create additional text files of your own to further test the correctness of

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!