USE PYTHON 3 ONLY A concordance is a compendium of the words in a particular tex
ID: 3716652 • Letter: U
Question
USE PYTHON 3 ONLY
A concordance is a compendium of the words in a particular text, along with their local context. By local context, I mean the surrounding words that occurred in the sentence with the word. A concordance has a number of uses, including searching for idioms and phrases, identification of authors, and translations of partial texts.
Because concordances are rather expensive (time wise) to develop, common words such as: and, a, the, those, him, her, etc. were ignored. These were called "stop words", and stop words are ignored in creating the concordance.
In your program you will need to ask the user which file they wish to analyze. Also you need to load a file of stop words named EnglishStopWords.txt. Then your program needs to compute a concordance which stores the following information for each word not in the stop words file.
• The word
• The total number of occurrences in the text file.
Note: You do not need to save the local context of each occurrence.
Then your program needs to print the word which appears the most often along with how many times it occurs. If there is a tie for the most, print all the words which are tied. The word or words need to be printed in a table format including titles for each column.
Requirements
• You need to use at least three functions. One of them will be main(). It is up to you what the other two functions do but you must have two more functions.
• Case should not matter here. The string ‘Spider’ and ‘spider’ should both count as the same word.
• Punctuation should be stripped so that ‘spider.’ And ‘spider’ both count as the same word.
Explanation / Answer
Let me know if you have any doubt. # -*- coding: utf-8 -*- """ Created on Thu Apr 26 07:48:04 2018 @author: """ import string import operator stpwords = {} txtdata = {} def processing(file1,file2): for line in file2: #creating dictionary of stopwords for word in line.split(): if word not in stpwords: stpwords[word] = 1 for line in file1: #counting word occurances for word in line.split(): word = word.translate(None, string.punctuation) word = word.lower() if word in stpwords: continue elif word not in txtdata: txtdata[word] = 1 else: txtdata[word] = txtdata[word] + 1 def result(): count = max(txtdata.items(), key=operator.itemgetter(1))[1] #finding max count result = [] #preparing result list for key in txtdata: if txtdata[key] == count: result.append(key) print("{:Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.