当前位置: 首页>>代码示例>>Python>>正文


Python SpellChecker.ignore_always方法代码示例

本文整理汇总了Python中enchant.checker.SpellChecker.ignore_always方法的典型用法代码示例。如果您正苦于以下问题:Python SpellChecker.ignore_always方法的具体用法?Python SpellChecker.ignore_always怎么用?Python SpellChecker.ignore_always使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在enchant.checker.SpellChecker的用法示例。


在下文中一共展示了SpellChecker.ignore_always方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: spellChecker

# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import ignore_always [as 别名]
class spellChecker(object):
	def __init__(self, text, dictionary):
		super(spellChecker, self).__init__()
		log.debug("Creating the SpellChecker object. Dictionary: %s" % (dictionary,))
		self.active = True
		try:
			if config.app["app-settings"]["language"] == "system":
				log.debug("Using the system language")
				self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
			else:
				log.debug("Using language: %s" % (languageHandler.getLanguage(),))
				self.checker = SpellChecker(languageHandler.curLang, filters=[tokenize.EmailFilter, tokenize.URLFilter])
			self.checker.set_text(text)
		except DictNotFoundError:
			print "no dict"
			log.exception("Dictionary for language %s not found." % (dictionary,))
			wx_ui.dict_not_found_error()
			self.active = False
		if self.active == True:
			log.debug("Creating dialog...")
			self.dialog = wx_ui.spellCheckerDialog()
			widgetUtils.connect_event(self.dialog.ignore, widgetUtils.BUTTON_PRESSED, self.ignore)
			widgetUtils.connect_event(self.dialog.ignoreAll, widgetUtils.BUTTON_PRESSED, self.ignoreAll)
			widgetUtils.connect_event(self.dialog.replace, widgetUtils.BUTTON_PRESSED, self.replace)
			widgetUtils.connect_event(self.dialog.replaceAll, widgetUtils.BUTTON_PRESSED, self.replaceAll)
			self.check()
			self.dialog.get_response()
			self.fixed_text = self.checker.get_text()

	def check(self):
		try:
			self.checker.next()
			textToSay = _(u"Misspelled word: %s") % (self.checker.word,)
			context = u"... %s %s %s" % (self.checker.leading_context(10), self.checker.word, self.checker.trailing_context(10))
			self.dialog.set_title(textToSay)
			output.speak(textToSay)
			self.dialog.set_word_and_suggestions(word=self.checker.word, context=context, suggestions=self.checker.suggest())
		except StopIteration:
			log.debug("Process finished.")
			wx_ui.finished()
			self.dialog.Destroy()

	def ignore(self, ev):
		self.check()

	def ignoreAll(self, ev):
		self.checker.ignore_always(word=self.checker.word)
		self.check()

	def replace(self, ev):
		self.checker.replace(self.dialog.get_selected_suggestion())
		self.check()

	def replaceAll(self, ev):
		self.checker.replace_always(self.dialog.get_selected_suggestion())
		self.check()

	def clean(self):
		if hasattr(self, "dialog"):
			self.dialog.Destroy()
开发者ID:manuelcortez,项目名称:socializer,代码行数:62,代码来源:spellchecker.py

示例2: SpellCheckHighlighter

# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import ignore_always [as 别名]
class SpellCheckHighlighter(QtGui.QSyntaxHighlighter):
  def __init__(self, parent = None):
    super(SpellCheckHighlighter, self).__init__(parent)
    
    self.set_language("en_US")
    
    self.format = QTextCharFormat()
    self.format.setUnderlineColor(QColor(255, 0, 0))
    self.format.setUnderlineStyle(QTextCharFormat.SpellCheckUnderline)
    
    self.errors = []
  
  def set_language(self, lang):
    dict = enchant.DictWithPWL(lang, "data/dict/enchant.txt")
    self.checker = SpellChecker(dict, chunkers = (HTMLChunker,))
  
  def get_language(self):
    return self.checker.dict.tag
  
  def highlightBlock(self, text):
    
    # If there is no previous state, then it's -1, which makes the first line 0.
    # And every line after that increases as expected.
    line = self.previousBlockState() + 1
    self.setCurrentBlockState(line)
    
    # Make sure our error list is long enough to hold this line.
    for i in range(len(self.errors), line + 1):
      self.errors.append([])
    
    text = common.qt_to_unicode(text)
    text = RE_ANGLED_APOST.sub("'", text)
    
    self.errors[line] = []
    self.checker.set_text(text)
    
    for err in self.checker:
      self.setFormat(err.wordpos, len(err.word), self.format)
      self.errors[line].append((err.word, err.wordpos))
  
  def add(self, word):
    self.checker.add(word)
    self.rehighlight()
  
  def ignore(self, word):
    self.checker.ignore_always(word)
    self.rehighlight()

### EOF ###
开发者ID:ThunderGemios10,项目名称:The-Super-Duper-Script-Editor-2,代码行数:51,代码来源:spellcheck_highlighter.py

示例3: SpellChecker

# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import ignore_always [as 别名]
import sys
from enchant.checker import SpellChecker
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Setting some initial variables...
result =[0,0,0,0,0,0,0,0,0]				#list to store result of test	-1=no test yet 0=fail 1=pass
spellCorrect =True		# assuming initially no spelling mistakes
total_mis_spells=0		# variable to hold total number of mis-spells
chkr = SpellChecker("en_US")
# adding some ignore words in dictionary...
chkr.ignore_always('Lenz');chkr.ignore_always('lenz')
chkr.ignore_always('GUWAHATI');chkr.ignore_always('guwahati')
chkr.ignore_always('Shakshat');chkr.ignore_always('shakshat')
chkr.ignore_always('MCB')
chkr.ignore_always('IIT');chkr.ignore_always('iit')
chkr.ignore_always('Behaviour');chkr.ignore_always('behaviour')
chkr.ignore_always('CSE');chkr.ignore_always('cse');
driver=webdriver.Firefox()			
wait = WebDriverWait(driver, 120)		# seeting wait time for firefox to be 120 seconds

def find(xpath):						# a function to find web-elements 
	try:
		element = wait.until(EC.element_to_be_clickable((By.XPATH,xpath)))
		return element
	except:
		print 'element with xpath =',xpath,'not found or the your net connection is slow'
		sys.exit()
开发者ID:gaurav95367,项目名称:iitgProject,代码行数:32,代码来源:test7.py

示例4: SpellCheck

# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import ignore_always [as 别名]

#.........这里部分代码省略.........
                    self.begin_line += 1
                    self.last_line_pos = 0
                    self.last_col = 0
                    self.new = True
                else:
                    self._DisableButtons()
                    self.list.Clear()
                    self.text.SetValue("")
                    common.note(tr('No more error found'))
                    return
        self._EnableButtons()
        self.document.SetSelectionStart(self.begin_pos + self.last_line_pos)
        self.document.SetSelectionEnd(self.begin_pos + self.last_line_pos + len(self.chkr.word.encode('utf-8')))
        self.document.EnsureCaretVisible()

        suggs = self.chkr.suggest()
        self.list.Clear()
        for s in suggs:
            self.list.Append(s)
        if len(suggs) > 0:
            self.text.SetValue(suggs[0])
        else:
            self.text.SetValue("")

    def OnIgnore(self, evnt=None):
        """Callback for the "ignore" button.
        This simply advances to the next error.
        """
        self.last_col += len(self.chkr.word)
        self._Advance()

    def OnIgnoreAll(self, evnt=None):
        """Callback for the "ignore all" button."""
        self.chkr.ignore_always()
#        self.ignore_list.append(self.chkr.word)
#        self._Advance()
        self.OnIgnore()

    def OnReplace(self, evnt=None):
        """Callback for the "replace" button."""
        repl = self._GetRepl()
        self.document.ReplaceSelection(repl)
        self.document.EnsureCaretVisible()
        self.last_col += len(repl.encode('utf-8'))
        self._Advance()

    def OnReplaceAll(self, evnt=None):
        """Callback for the "replace all" button."""
        repl = self._GetRepl()
        status = self.document.save_state()
        content = self.document.getRawText()
        text = content[self.begin_pos + self.last_line_pos:]
        r = re.compile(r'\b%s\b' % self.chkr.word.encode('utf-8'))
        text = content[:self.begin_pos + self.last_line_pos] + r.sub(repl.encode('utf-8'), text)
        self.document.SetText(unicode(text, 'utf-8'))
        self.document.restore_state(status)
        self.last_col += len(repl)

#        self.chkr.replace_always(repl)
        self._Advance()

    def _OnReplSelect(self,evnt=None):
        """Callback when a new replacement option is selected."""
        sel = self.list.GetSelection()
        if sel == -1:
            return
开发者ID:LinYuanLab,项目名称:ulipad,代码行数:70,代码来源:SpellCheck.py

示例5: spellCheckerDialog

# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import ignore_always [as 别名]
class spellCheckerDialog(wx.Dialog):
 def __init__(self, text, dictionary):
  super(spellCheckerDialog, self).__init__(None, 1)
  try:
   if config.main["general"]["language"] == "system": self.checker = SpellChecker()
   else: self.checker = SpellChecker(languageHandler.getLanguage())
   self.checker.set_text(text)
  except DictNotFoundError:
   wx.MessageDialog(None, _(u"A bug has happened. There are no dictionaries available for the selected language in TW Blue"), _(u"Error"), wx.ICON_ERROR).ShowModal()
   self.Destroy()
  panel = wx.Panel(self)
  sizer = wx.BoxSizer(wx.VERTICAL)
  word = wx.StaticText(panel, -1, _(u"Mis-spelled word"))
  self.word = wx.TextCtrl(panel, -1)
  wordBox = wx.BoxSizer(wx.HORIZONTAL)
  wordBox.Add(word)
  wordBox.Add(self.word)
  context = wx.StaticText(panel, -1, _(u"Context"))
  self.context = wx.TextCtrl(panel, -1)
  contextBox = wx.BoxSizer(wx.HORIZONTAL)
  contextBox.Add(context)
  contextBox.Add(self.context)
  suggest = wx.StaticText(panel, -1, _(u"Suggestions"))
  self.suggestions = wx.ListBox(panel, -1, choices=[], style=wx.LB_SINGLE)
  suggestionsBox = wx.BoxSizer(wx.HORIZONTAL)
  suggestionsBox.Add(suggest)
  suggestionsBox.Add(self.suggestions)
  ignore = wx.Button(panel, -1, _(u"Ignore"))
  self.Bind(wx.EVT_BUTTON, self.onIgnore, ignore)
  ignoreAll = wx.Button(panel, -1, _(u"Ignore all"))
  self.Bind(wx.EVT_BUTTON, self.onIgnoreAll, ignoreAll)
  replace = wx.Button(panel, -1, _(u"Replace"))
  self.Bind(wx.EVT_BUTTON, self.onReplace, replace)
  replaceAll = wx.Button(panel, -1, _(u"Replace all"))
  self.Bind(wx.EVT_BUTTON, self.onReplaceAll, replaceAll)
  close = wx.Button(panel, wx.ID_CANCEL)
  btnBox = wx.BoxSizer(wx.HORIZONTAL)
  btnBox.Add(ignore)
  btnBox.Add(ignoreAll)
  btnBox.Add(replace)
  btnBox.Add(replaceAll)
  btnBox.Add(close)
  sizer.Add(wordBox)
  sizer.Add(contextBox)
  sizer.Add(suggestionsBox)
  sizer.Add(btnBox)
  panel.SetSizerAndFit(sizer)
  self.check()

 def check(self):
  try:
   self.checker.next()
   textToSay = _(u"Mis-spelled word: %s") % (self.checker.word,)
   context = u"... %s %s %s" % (self.checker.leading_context(10), self.checker.word, self.checker.trailing_context(10))
   self.SetTitle(textToSay)
   output.speak(textToSay)
   self.word.SetValue(self.checker.word)
   self.context.ChangeValue(context)
   self.suggestions.Set(self.checker.suggest())
   self.suggestions.SetFocus()
  except StopIteration:
   wx.MessageDialog(self, _(u"The spelling review has finished."), _("Finished"), style=wx.OK).ShowModal()
   self.EndModal(wx.ID_OK)
  except AttributeError:
   pass

 def onIgnore(self, ev):
  self.check()

 def onIgnoreAll(self, ev):
  self.checker.ignore_always(word=self.checker.word)
  self.check()

 def onReplace(self, ev):
  self.checker.replace(self.suggestions.GetStringSelection())
  self.check()

 def onReplaceAll(self, ev):
  self.checker.replace_always(self.suggestions.GetStringSelection())
  self.check()
开发者ID:Oire,项目名称:TWBlue,代码行数:82,代码来源:gui.py


注:本文中的enchant.checker.SpellChecker.ignore_always方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。