def OnLearn(self, event): input = inputWords(word=self.originaltext.GetValue()) result = session.query(inputWords).filter(inputWords.word == self.originaltext.GetValue()).first() if result is None: controller.addCommon(self, self.originaltext.GetValue()) print("Correct Word Identified as Misspelling:", self.originaltext.GetValue()) self.totalLearned+=1 session.add(input) session.commit() # No need to add sa common bc na-add na sya if not self.words: wx.MessageBox("No more words.") else: self.checkindexCurr = self.wrong.index(self.currentword) self.wrong.remove(self.originaltext.GetValue()) self.originaltext.SetValue(self.wrong[self.checkindexCurr]) self.currentword = self.wrong[self.checkindexCurr] controller.suggestionslist = [] self.suggestions = [] controller.displaySuggestions(self, self.currentword) for i in controller.suggestionslist: self.suggestions.append(i) self.wordsuggest.Set(self.suggestions) # MET AND LEV # sugg_start = timeit.default_timer() controller.sortedDictionary = dict() controller.displayLevSugg(self, self.currentword) self.levSuggest.Set(self.suggestionsLev) self.checktext.Set(self.suggestionsLev) # sugg_stop = timeit.default_timer() # totaltime = sugg_stop - sugg_start # print('Producing Suggestions Metaphone&Lev Runtime: ', totaltime) # overalltime+=totaltime else: print ("End of array.") wx.MessageBox("Word Added!") self.Refresh()
def OnIgnore(self, event): if wx.MessageBox("Remove word?", "Please confirm", wx.YES_NO) != wx.NO: self.checkindexCurr = self.wrong.index(self.currentword) self.wrong.remove(self.originaltext.GetValue()) self.originaltext.SetValue(self.wrong[self.checkindexCurr]) # ma change ang original word sa nxt wrong words self.currentword = self.wrong[self.checkindexCurr] controller.suggestionslist = [] self.suggestions = [] controller.sortedDictionary = dict() controller.displaySuggestions(self, self.currentword) controller.displayLevSugg(self, self.currentword) for i in controller.suggestionslist: self.suggestions.append(i) # for i in controller.sortedDictionary. self.wordsuggest.Set(self.suggestions) self.levSuggest.Set(self.suggestionsLev) self.checktext.Set(self.suggestions) self.checktext.SetLabel(self.suggestions[0]) self.Refresh()
def OnSpellCheck(self, e): # for unhighlighting texts # session.query(Common).delete() # session.commit() overall_start = timeit.default_timer() target1 = self.originaltext.GetValue() result1 = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", target1) start1 = self.inputtext.GetValue().find(result1) position1 = start1 + len(result1) self.inputtext.Bind(wx.EVT_SET_FOCUS, self.UnHighlight(start1, position1)) self.value = self.inputtext.GetValue() self.words = self.value.split() self.List = [] for i in self.words: converted = controller.ForceToUnicode(i) if converted.isdigit() == False: result = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", converted) self.List.append(result) else: pass print self.List print ("Number of words:", len(self.List)) if not self.words: wx.MessageBox("Please enter something for us to check your work!!") else: controller.spellingCheck(self, self.List) controller.suggestionslist = [] self.suggestions = [] # for not sorted suggestions controller.displaySuggestions(self, self.currentword) for i in controller.suggestionslist: self.suggestions.append(i) # appending misspelled words misspelled = [] for i in self.wrong: if i in misspelled: pass else: misspelled.append(controller.ForceToUnicode(i)) self.misspellings.SetValue(json.dumps(misspelled)) # for levenshtein-generated suggestions with Metaphone # Diri jud ang start sa timer kay controller.displayLevSugg does a thing sugg_start = timeit.default_timer() controller.sortedDictionary = {} self.suggestionsLev = [] controller.displayLevSugg(self, self.currentword) for k in controller.sortedDictionary.values(): for j in k: if j in self.suggestionsLev: pass else: self.suggestionsLev.append(j) # End sa time sugg_stop = timeit.default_timer() totaltime = sugg_stop - sugg_start self.seggestionsLev = self.suggestionsLev[:4] print('Producing Suggestions Metaphone&Lev Runtime: ', totaltime) # adding all runtime para sa metlev-suggestions self.overalltime+=totaltime self.wordsuggest.Set(self.suggestions) self.levSuggest.Set(self.suggestionsLev) self.checktext.Set(self.suggestionsLev[:5]) print("Current Word:", self.currentword) print ("Non-sorted suggestions:", self.suggestions) print ("Sorted suggestions:", self.suggestionsLev) self.Refresh() self.checktext.Enable() self.changebtn.Enable() self.changeallbtn.Enable() self.findnextbtn.Enable() self.previousbtn.Enable() self.ignorebtn.Enable() self.learnbtn.Enable() if (self.checkindexCurr == 0): self.previousbtn.Disable() # for highlighting texts target = self.originaltext.GetValue() result = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", target) for i in range(self.inputtext.GetNumberOfLines()): line = self.inputtext.GetLineText(i) if result in line: start = self.inputtext.GetValue().find(result) position = start + len(result) self.inputtext.Bind(wx.EVT_SET_FOCUS, self.OnHighlight(start, position)) start = 0 overall_stop = timeit.default_timer() print('Overall Runtime: ', overall_stop - overall_start)
def Previous(self, e): try: # for unhighlighting previous texts target1 = self.originaltext.GetValue() result1 = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", target1) start1 = self.inputtext.GetValue().find(result1) position1 = start1 + len(result1) self.inputtext.Bind(wx.EVT_SET_FOCUS, self.UnHighlight(start1, position1)) self.findnextbtn.Enable() self.checktext.Clear() self.checkindexCurr = self.checkindexCurr - 1 self.previousbtn.Enable() self.originaltext.SetValue(self.wrong[self.checkindexCurr]) self.currentword = self.wrong[self.checkindexCurr] # for not sorted suggestions controller.suggestionslist = [] self.suggestions = [] controller.displaySuggestions(self, self.currentword) for i in controller.suggestionslist: self.suggestions.append(i) self.wordsuggest.Set(self.suggestions) # for levenshtein-generated suggestions controller.sortedDictionary = dict() self.suggestionsLev = [] controller.displayLevSugg(self, self.currentword) for k in controller.sortedDictionary.values(): for j in k: if j in self.suggestionsLev: pass else: self.suggestionsLev.append(j) self.levSuggest.Set(self.suggestionsLev) self.checktext.Set(self.suggestionsLev[:5]) self.Refresh() if (self.checkindexCurr == 0): self.previousbtn.Disable() except IndexError: wx.MessageBox("There's no previous word") # for highlighting texts target = self.originaltext.GetValue() result = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", target) count = 0 for i in range(self.inputtext.GetNumberOfLines()): if count == 0: line = self.inputtext.GetLineText(i) if result in line: start = self.inputtext.GetValue().find(result) position = start + len(result) self.inputtext.Bind(wx.EVT_SET_FOCUS, self.OnHighlight(start, position)) start = 0 count = 1 self.Refresh() if (self.checkindexCurr == 0): self.previousbtn.Disable() except IndexError: wx.MessageBox("There's no previous word")
def Next(self, e): try: # remove highlight from previous words target1 = self.originaltext.GetValue() result1 = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", target1) start1 = self.inputtext.GetValue().find(result1) position1 = start1 + len(result1) self.inputtext.Bind(wx.EVT_SET_FOCUS, self.UnHighlight(start1, position1)) self.previousbtn.Enable() self.checktext.Clear() self.checkindexCurr = self.checkindexCurr + 1 self.originaltext.SetValue(self.wrong[self.checkindexCurr]) self.currentword = self.wrong[self.checkindexCurr] self.curwordindex = self.List.index(self.currentword) # for not sorted suggestions controller.suggestionslist = [] self.suggestions = [] controller.displaySuggestions(self, self.currentword) for i in controller.suggestionslist: self.suggestions.append(i) # for Levenshtein-generated Suggestions # Diri jud ang start sa timer bc ang method sugg_start = timeit.default_timer() controller.sortedDictionary ={} self.suggestionsLev = [] controller.displayLevSugg(self, self.currentword) for k in controller.sortedDictionary.values(): for j in k: if j in self.suggestionsLev: continue else: self.suggestionsLev.append(j) #End sa timer sugg_stop = timeit.default_timer() totaltime = sugg_stop - sugg_start print('Producing Suggestions Metaphone&Lev Runtime: ', totaltime) # adding all runtime para sa metlev-suggestions self.overalltime+=totaltime self.wordsuggest.Set(self.suggestions) self.levSuggest.Set(self.suggestionsLev) self.checktext.Set(self.suggestionsLev[:5]) print("Current Word:", self.currentword) print ("Non-sorted suggestions:", self.suggestions) print ("Sorted suggestions:", self.suggestionsLev) # for highlighting text target = self.originaltext.GetValue() result = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", target) count = 0 for i in range(self.inputtext.GetNumberOfLines()): if count == 0: line = self.inputtext.GetLineText(i) if target in line: start = self.inputtext.GetValue().find(result) position = start + len(result) self.inputtext.Bind(wx.EVT_SET_FOCUS, self.OnHighlight(start, position)) start = 0 count = 1 if (self.checkindexCurr == len(self.wrong)-1): self.findnextbtn.Disable() print ("Overall Lev-Suggestion Runtime:", self.overalltime) print("Total True Negatives:", self.totalLearned) except IndexError: #self.findnextbtn.Disable() wx.MessageBox("No more words.")
def ChangeAll(self, e): target1 = self.checktext.GetValue() result1 = re.sub(r"[:;!?@#$%^&*()~`\"_+=.,]", "", target1) start1 = self.inputtext.GetValue().find(target1) position1 = start1 + len(target1) self.inputtext.Bind(wx.EVT_SET_FOCUS, self.UnHighlight(start1, position1)) self.selected = self.checktext.GetValue() if self.selected == "": wx.MessageBox("Please Select a word") else: # target = self.originaltext.GetValue() # for i in range(self.inputtext.GetValue()): # line = self.inputtext.GetLineText(i) # if target in line: # self.inputtext.GetValue().replace(target, self.selected) try: self.List[self.curwordindex] = self.selected for item in self.List: if item == self.currentword: self.List[self.List.index(item)] = self.selected print self.List self.inputtext.SetValue(' '.join(self.List)) self.checktext.Clear() self.checkindexCurr = self.wrong.index(self.currentword) for item in self.wrong: if item == self.currentword: self.wrong.remove(self.currentword) print self.wrong self.originaltext.SetValue(self.wrong[self.checkindexCurr]) #ma change ang original word sa nxt wrong words self.currentword = self.wrong[self.checkindexCurr] self.curwordindex = self.List.index(self.currentword) print self.wrong controller.suggestionslist = [] self.suggestions = [] controller.displaySuggestions(self, self.currentword) for i in controller.suggestionslist: self.suggestions.append(i) self.wordsuggest.Set(self.suggestions) # MET AND LEV # sugg_start = timeit.default_timer() controller.displayLevSugg(self, self.currentword) self.levSuggest.Set(self.suggestionsLev) self.checktext.Set(self.suggestions) self.checktext.SetLabel(self.suggestions[0]) # sugg_stop = timeit.default_timer() # totaltime = sugg_stop - sugg_start # print('Producing Suggestions Metaphone&Lev Runtime: ', totaltime) # overalltime+=totaltime # misspelled = [] # for i in self.wrong: # if i in misspelled: # pass # else: # misspelled.append(controller.ForceToUnicode(i)) # self.misspellings.SetValue(json.dumps(misspelled)) self.Refresh() except IndexError: wx.MessageBox("No more wrong words")