Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Create a Python file called analysis.py that will perform text analysis on files. For this question, assume that each space ( ) in the document
Create a Python file called analysis.py that will perform text analysis on files. For this question, assume that each space (" ") in 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 files - only words separated by spaces. If you want to see examples of the type of text, look in the testfile_.txt files included on cu Learn. You must implement and test the following functions inside of your analysis.py file: 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). Common word (list) - Takes a single list-type argument which contains string values. the function should operate as follows: 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. 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. Common letter (list) - Takes a single list-type argument which contains single character strings (i.e., letters/characters). the function should operate as follows: 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. 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. Common pair (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 all, or is never followed by another word (i.e., is the last word in the file), this function should return None. Count all () - Returns the total number of words found in the text that has been loaded. That is, the word count of the document. Count unique () - 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
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started