def file_read(self): self.results.delete('1.0', END) self.article_textarea.delete('1.0', END) popular_words = int(self.ignore_entry.get()) filename = askopenfilename() if self.collocation_words.get() == '2': collocations, most_common_words, file_text = collocations_file.find_collocations(filename, dict(), popular_words) collocations = sort_collocations(collocations) text = print_collocations_for_test_area(collocations, 15) elif self.collocation_words.get() == '3': collocations, most_common_words, file_text = collocations_file_tri.find_collocations_tri(filename, dict(), popular_words) collocations = sort_collocations_tri(collocations) text = print_collocations_for_test_area_tri(collocations, 15) elif self.collocation_words.get() == '4': collocations, most_common_words, file_text = collocations_file_tetra.find_collocations_tetra(filename, dict(), popular_words) collocations = sort_collocations_tetra(collocations) text = print_collocations_for_test_area_tetra(collocations, 15) elif self.collocation_words.get() == '5': collocations, most_common_words, file_text = collocations_file_penta.find_collocations_penta(filename, dict(), popular_words) collocations = sort_collocations_penta(collocations) text = print_collocations_for_test_area_penta(collocations, 15) self.results.insert(END, text) self.article_textarea.insert(END, file_text) self.set_words_colors(most_common_words, collocations)
def wikipedia_article(self): self.results.delete('1.0', END) self.article_textarea.delete('1.0', END) popular_words = int(self.ignore_entry.get()) flag, article = collocations_wikipedia.get_article_from_wikipedia(self.entry1.get()) if not flag: self.results.insert(END, 'Could not get the atricle, because:\n') self.results.insert(END, article) return article_text = article.content links = article.links while len(article_text) < int(self.min_entry.get()): n = randint(0, len(links)-1) link = links[n] del links[n] flag, new_article = collocations_wikipedia.get_article_from_wikipedia(link) if flag: links += new_article.links article_text += ' ' + new_article.content if not len(links): break self.results.delete('1.0', END) if self.collocation_words.get() == '2': collocations, most_common_words = collocations_wikipedia.find_collocations(article_text, dict(), popular_words) collocations = sort_collocations(collocations) text = print_collocations_for_test_area(collocations, 15) elif self.collocation_words.get() == '3': collocations, most_common_words = collocations_wikipedia_tri.find_collocations_tri(article_text, dict(), popular_words) collocations = sort_collocations_tri(collocations) text = print_collocations_for_test_area_tri(collocations, 15) elif self.collocation_words.get() == '4': collocations, most_common_words = collocations_wikipedia_tetra.find_collocations_tetra(article_text, dict(), popular_words) collocations = sort_collocations_tetra(collocations) text = print_collocations_for_test_area_tetra(collocations, 15) elif self.collocation_words.get() == '5': collocations, most_common_words = collocations_wikipedia_penta.find_collocations_penta(article_text, dict(), popular_words) collocations = sort_collocations_penta(collocations) text = print_collocations_for_test_area_penta(collocations, 15) self.results.insert(END, text) self.article_textarea.insert(END, article_text) self.set_words_colors(most_common_words, collocations)