本文整理汇总了Python中enchant.checker.SpellChecker.add方法的典型用法代码示例。如果您正苦于以下问题:Python SpellChecker.add方法的具体用法?Python SpellChecker.add怎么用?Python SpellChecker.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类enchant.checker.SpellChecker
的用法示例。
在下文中一共展示了SpellChecker.add方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: BeardBotModule
# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import add [as 别名]
class BeardBotModule(ModuleBase):
"""Checks the spelling of all words in the channel.
Add a word to the dictionary (addressed):
* [word] is a word!
Add a word in reply to the bot's taunts (addressed):
* Yes I [expletive] do
"""
def __init__(self, *args, **kwargs):
ModuleBase.__init__(self, *args, **kwargs)
self.spell_checker = SpellChecker("en_UK")
self.last_word = None
def on_channel_message(self, source_name, source_host, message):
self.spell_checker.set_text(message)
for error in self.spell_checker:
self.bot.say("%s? You call that a word?" % error.word)
self.last_word = error.word
def on_addressed_message(self, source_name, source_host, message):
is_a_word_match = is_a_word.search(message)
yes_i_do_match = yes_i_do.search(message)
if is_a_word_match:
word = match.group(1)
self.bot.say("You're right, %s is a word :(" % word)
self.spell_checker.add(word)
elif yes_i_do_match and self.last_word:
self.spell_checker.add(self.last_word)
self.bot.say("Yes Master...")
示例2: SpellCheckHighlighter
# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import add [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 ###
示例3: BeardBotModule
# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import add [as 别名]
class BeardBotModule(ModuleBase):
def __init__(self, *args, **kwargs):
ModuleBase.__init__(self, *args, **kwargs)
self.spell_checker = SpellChecker("en_UK")
self.last_word = None
def on_channel_message(self, source_name, source_host, message):
self.spell_checker.set_text(message)
for error in self.spell_checker:
self.bot.say("%s? You call that a word?" % error.word)
self.last_word = error.word
def on_addressed_message(self, source_name, source_host, message):
is_a_word_match = is_a_word.search(message)
yes_i_do_match = yes_i_do.search(message)
if is_a_word_match:
word = match.group(1)
self.bot.say("You're right, %s is a word :(" % word)
self.spell_checker.add(word)
elif yes_i_do_match and self.last_word:
self.spell_checker.add(self.last_word)
self.bot.say("Yes Master...")
示例4: SpellCheck
# 需要导入模块: from enchant.checker import SpellChecker [as 别名]
# 或者: from enchant.checker.SpellChecker import add [as 别名]
class SpellCheck(wx.Panel):
def __init__(self, parent):
self.parent = parent
wx.Panel.__init__(self, parent, -1)
self.pref = Globals.pref
self.sizer = sizer = ui.VBox(padding=0, namebinding='widget').create(self).auto_layout()
h = sizer.add(ui.HBox)
h.add(ui.Label(tr("Replace with") + ':'))
h.add(ui.Text('', size=(150, -1)), name='text')
h.add(ui.Button(tr('Start')), name='btnRun').bind('click', self.OnRun)
h.add(ui.Button(tr('Replace')), name='btnReplace').bind('click', self.OnReplace)
h.add(ui.Button(tr('Replace All')), name='btnReplaceAll').bind('click', self.OnReplaceAll)
h.add(ui.Button(tr('Ignore')), name='btnIgnore').bind('click', self.OnIgnore)
h.add(ui.Button(tr('Ignore All')), name='btnIgnoreAll').bind('click', self.OnIgnoreAll)
h.add(ui.Button(tr('Add')), name='btnAdd').bind('click', self.OnAdd)
h = sizer.add(ui.HBox, proportion=1)
h.add(ui.Label(tr("Suggest") + ':'))
h.add(ui.ListBox(size=(250, -1)), name='list').binds(
(wx.EVT_LISTBOX, self._OnReplSelect),
(wx.EVT_LISTBOX_DCLICK, self.OnReplace),
)
h.add(ui.Label(tr("Available Dict") + ':'))
h.add(ui.ListBox(size=(100, -1), choices=enchant.list_languages()), name='dict_list').bind(
wx.EVT_LISTBOX, self.OnDictSelect
)
sizer.auto_fit(0)
self.init()
self._DisableButtons()
def init(self):
defLoc = locale.getdefaultlocale()[0]
if self.pref.default_spellcheck_dict:
defLoc = self.pref.default_spellcheck_dict
index = self.dict_list.FindString(defLoc)
if index > -1:
self.dict_list.SetSelection(index)
else:
defLoc = 'en_US'
self.pref.default_spellcheck_dict = defLoc
self.pref.save()
#todo add multi dict support
self.chkr = SpellChecker(defLoc)
self.mainframe = Globals.mainframe
self._buttonsEnabled = True
self.running = False
def OnRun(self, event):
if self.running:
self.running = False
self._DisableButtons()
else:
self.running = True
self.document = self.mainframe.document
if self.document.edittype != 'edit':
common.showerror(self, tr("This document can't be spell checked"))
return
self.begin_line = 0
self.begin_pos = 0
self.last_line_pos = 0
self.last_col = 0
self.ignore_list = []
self.new = True
self._Advance()
def _Advance(self):
"""Advance to the next error.
This method advances the SpellChecker to the next error, if
any. It then displays the error and some surrounding context,
and well as listing the suggested replacements.
"""
# Advance to next error, disable if not available
while 1:
try:
if self.new:
self.begin_pos = self.document.PositionFromLine(self.begin_line)
line = self.document.getLineText(self.begin_line)
line_len = self.document.GetLineEndPosition(self.begin_line) - self.begin_pos
new = False
if self.last_line_pos < line_len:
self.chkr.set_text(line[self.last_col:])
self.chkr.next()
# while self.chkr.word in self.ignore_list:
# self.chkr.next()
# pass
self.last_col += self.chkr.wordpos
self.last_line_pos = len(line[:self.last_col].encode('utf-8'))
break
except StopIteration:
if self.begin_line < self.document.GetLineCount():
self.begin_line += 1
#.........这里部分代码省略.........