def classify_word_types(self, to_include): """ Classify and highlight specific word types. """ self.raw = self.text.get('1.0', tk.END) # Get current text input. wc = wd.WordSet(self.raw, self.md_core) # Label word types. flatten = [x for y in to_include for x in y] # Get rid of tupples. td = log.CodeBlockTimer( 'tfirst') # This loop ~0.01-0.05s per word! Need to speed up: td.start() for w, t in list(set(wc.pos)): if t in flatten: try: colour = wc.word_colours[t] self.highlight_words(w, wc, name=t, color=colour) except KeyError: pass else: pass td.finish()
def similarity_of_highlighted_texts(self): """ Get the similarities of two sections of highlighted text. """ wc = wd.WordSet(self.raw, self.md_core) self.text.config(cursor='@icons//highlighter_tip.cur') # Change cursor for highlights. if self.text.tag_ranges(tk.SEL): h1 = self.tag_highlighted_text(colour='blue', tag_name='h1') else: self.wait_variable(self.text_selected) h1 = self.tag_highlighted_text(colour='blue', tag_name='h1') self.wait_variable(self.text_selected) # Wait for next highlight. h2 = self.tag_highlighted_text(colour='red', tag_name='h2') self.text.config(cursor='arrow') # Return cursor to arrow. sim, color = wc.spacy_sim(h1, h2) self.text_selected = tk.StringVar() # Reset the text selection variable. return sim
def test_wordcolour(self): """Test highlighting words in a given colour.""" log.log_setup() # Start logging. text = 'I was about to go shopping, but it was raining. So I decided to stay at home instead.' app = gu.MainWindow(None, text) app.title('Prose analysis') app.grid_config() ws = wc.WordSet(text) app.highlight_words('was', ws) app.mainloop()
def sentiment_analysis(self): """ Highlight positive and negative sentiment for all words or all highlighted words. """ if self.highlighted_text_list: # Highlight only selected words. wc = wd.WordSet(self.raw, self.md_core) for s, v in zip(self.highlighted_text_list.keys(), self.highlighted_text_list.values()): pos, neg, obj, color = wc.sentiment(s) if color != '#000000': self.colourise_text(s, 'snow', color, s, v[0]) # Don't highlight. else: # Highlight all words. wc = wd.WordSet(self.raw, self.md_core) sentiment_all_vals = wc.sentiment_all()
def similarity_to_all_highlighted(self): """ Get similarity of the highlighted word to all other highlighted words. """ wc = wd.WordSet(self.raw, self.md_core) for k, v in zip(self.highlighted_text_list.keys(), self.highlighted_text_list.values()): # Check to see which sentence is being highlighted. s = ''.join(['' if i.isdigit() else i for i in k]) # Remove numeric elements for words appearing twice. sim, color = wc.spacy_sim(self.text_selected.get(), s) self.colourise_text(s, 'snow', color, s, v[0])