The program will be based on developing a concordance for a file, where a concor
ID: 3797978 • Letter: T
Question
The program will be based on developing a concordance for a file, where a concordance is "an alphabetical list of the words (especially the important ones present in the file, usually with citations of the passages concerned You will create a graphical user interface for the user to specify the file to be processed and then compute the concordance of the file, removing stop words. The gui will have buttons to display the entire concordance or the concordance for a specified word. For each word, the display includes the total number of occurrences and for each occurrence, the line number in the file and the local context defined as the original line with the specified word in all upper case. Your program must be designed using functions, and you are to document the functions similar to javadoc, using Include in a comment at the beginning of your program, your name and a description of the main data structure used in your solution. Notes and Hints 75 Concordance: jingleBells tot For an open file object file obj.readlines0 will return a list, where each element is a Browse to File Display All Display word string, one of the lines of the file Remember that case should not matter ago: 1 here. The string "Dream" and "dream 19: A day or two AGO, should both count as the same word. bank: 1 Punctuation should be stripped so that 25 We got into a drifted BANK, bay: "dream." and "dream" both count as the 50 Just get a bob tailed BAY same word. bells 17 The context line printed should contain 5: BELLS on bob tail ring, its original capitalization (except for the 10 Oh, jingle BELLS, jingle BELLS specified word that is all upper case) and 14 Jingle BELLS, jingle BELLS original punctuation.Explanation / Answer
# -*- coding: utf-8 -*-
"""
FileName: concordance.py
Author:
Date:
"""
def get_concordance(file_name, stopwords):
"""
:param file_name:
:param stopwords:
:return:
"""
concordance = {}
with open(file_name, "r") as f:
for line in f:
words = line.split(" ")
for word in words:
if word not in concordance:
if word not in stopwords:
concordance[word] = [1, [line]]
else:
if word not in stopwords:
concordance[word][0] += 1
concordance[word][1].append(line)
return concordance
stopwords = ["a", "about", "above", "above", "across", "after", "afterwards", "again", "against", "all", "almost",
"alone", "along", "already", "also", "although", "always", "am", "among", "amongst", "amoungst", "amount",
"an", "and", "another", "any", "anyhow", "anyone", "anything", "anyway", "anywhere", "are", "around", "as",
"at", "back", "be", "became", "because", "become", "becomes", "becoming", "been", "before", "beforehand",
"behind", "being", "below", "beside", "besides", "between", "beyond", "bill", "both", "bottom", "but",
"by", "call", "can", "cannot", "cant", "co", "con", "could", "couldnt", "cry", "de", "describe", "detail",
"do", "done", "down", "due", "during", "each", "eg", "eight", "either", "eleven", "else", "elsewhere",
"empty", "enough", "etc", "even", "ever", "every", "everyone", "everything", "everywhere", "except", "few",
"fifteen", "fify", "fill", "find", "fire", "first", "five", "for", "former", "formerly", "forty", "found",
"four", "from", "front", "full", "further", "get", "give", "go", "had", "has", "hasnt", "have", "he",
"hence", "her", "here", "hereafter", "hereby", "herein", "hereupon", "hers", "herself", "him", "himself",
"his", "how", "however", "hundred", "ie", "if", "in", "inc", "indeed", "interest", "into", "is", "it",
"its", "itself", "keep", "last", "latter", "latterly", "least", "less", "ltd", "made", "many", "may", "me",
"meanwhile", "might", "mill", "mine", "more", "moreover", "most", "mostly", "move", "much", "must", "my",
"myself", "name", "namely", "neither", "never", "nevertheless", "next", "nine", "no", "nobody", "none",
"noone", "nor", "not", "nothing", "now", "nowhere", "of", "off", "often", "on", "once", "one", "only",
"onto", "or", "other", "others", "otherwise", "our", "ours", "ourselves", "out", "over", "own", "part",
"per", "perhaps", "please", "put", "rather", "re", "same", "see", "seem", "seemed", "seeming", "seems",
"serious", "several", "she", "should", "show", "side", "since", "sincere", "six", "sixty", "so", "some",
"somehow", "someone", "something", "sometime", "sometimes", "somewhere", "still", "such", "system", "take",
"ten", "than", "that", "the", "their", "them", "themselves", "then", "thence", "there", "thereafter",
"thereby", "therefore", "therein", "thereupon", "these", "they", "thickv", "thin", "third", "this",
"those", "though", "three", "through", "throughout", "thru", "thus", "to", "together", "too", "top",
"toward", "towards", "twelve", "twenty", "two", "un", "under", "until", "up", "upon", "us", "very", "via",
"was", "we", "well", "were", "what", "whatever", "when", "whence", "whenever", "where", "whereafter",
"whereas", "whereby", "wherein", "whereupon", "wherever", "whether", "which", "while", "whither", "who",
"whoever", "whole", "whom", "whose", "why", "will", "with", "within", "without", "would", "yet", "you",
"your", "yours", "yourself", "yourselves", "the"]
if __name__ == "__main__":
file = "input.txt"
data = get_concordance(file, stopwords)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.