To utilise all functions we created in previous tasks, we are going to make a function that would interact with users. W
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
To utilise all functions we created in previous tasks, we are going to make a function that would interact with users. W
To utilise all functions we created in previous tasks, we are going to make a function that would interact with users. Write a function tweet_analysis(), which does the following: 1. Ask for user input of the input filename with message: 'Enter the name of the file to read:' 2. Ask for user input of the output filename with message: 'Enter the name of the file to write: 3. Ask for user input of the stopwords with message: 'Enter your stopwords: 4. Ask for user input of the punctuations with message: 'Enter your punctuations to remove:' 5. Load the file from the input file from step 1. 6. For each line from the given file, process 1. Capitalisation 2. Remove stopwords as given in step 3. 3. Remove punctuations as given in step 4. 4. Remove duplicate words 5. Remove noises 6. Stem words 7. Write the resulting sentences to the output file from step 2. 8. Save the resulting sentences to a list 9. Return the saved resulting sentences Note: using previously implemented functions, this task should be straightforward! Note2: You can assume all previous functions are correctly implemented for you using sample answers, so you only have to submit the tweet_analysis function here. Note3: based on the above 2 notes, you should understand that you are not supposed to cram all previously implemented code into this function, but just call them. Note4: if you come across errors like /x9d, then you should specify the filing writing with encoding="utf-8". For example: Test Input Result output = tweet_analysis print(sorted (output[9].split() tweets.txt outputi.txt is this and or are has Enter the name of the file to read: tweets.txt Enter the name of the file to write: output1.txt Enter your stopwords: is this and or are has Enter your punctuations to remove: .,!?*^* ['back', 'blame', 'chris', 'corona', 'going', 'let', 'not', 'on', 'president', 'push', 'serious', 'that', 'th ..!?A* output = tweet_analysis tweets.txt print(sorted (output[10].split()) output2.txt is no of ..!?943 Enter the name of the file to read: tweets.txt Enter the name of the file to write: output2.txt Enter your stopwords: is no of Enter your punctuations to remove: .,!?*^* ['a', 'and', 'any', 'as', 'be', 'broke', 'cancell', 'conference', 'covid-19', 'due', 'flexibility', 'for', 's
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!