コード例 #1
0
ファイル: tests.py プロジェクト: bopopescu/DomainSearch
 def _check_docstrings(self,obj,errors):
     import enchant
     if hasattr(obj,"__doc__"):
         skip_errors = [w for w in getattr(obj,"_DOC_ERRORS",[])]
         chkr = enchant.checker.SpellChecker("en_AU",obj.__doc__,filters=[enchant.tokenize.URLFilter])
         for err in chkr:
             if len(err.word) == 1:
                 continue
             if err.word.lower() in self.WORDS:
                 continue
             if skip_errors and skip_errors[0] == err.word:
                 skip_errors.pop(0)
                 continue
             errors.append((obj,err.word,err.wordpos))
             msg = "\nDOCSTRING SPELLING ERROR: %s %s %d %s\n" % (obj,err.word,err.wordpos,chkr.suggest())
             printf([msg],file=sys.stderr)
     #  Find and yield all child objects that should be checked
     for name in dir(obj):
         if name.startswith("__"):
             continue
         child = getattr(obj,name)
         if hasattr(child,"__file__"):
             if not hasattr(globals(),"__file__"):
                 continue
             if not child.__file__.startswith(os.path.dirname(__file__)):
                 continue
         else:
             cmod = getattr(child,"__module__",None)
             if not cmod:
                 cclass = getattr(child,"__class__",None)
                 cmod = getattr(cclass,"__module__",None)
             if cmod and not cmod.startswith("enchant"):
                 continue
         yield child
コード例 #2
0
ファイル: CmdLineChecker.py プロジェクト: amlweems/pyenchant
    def read_command(self):
        try:
            cmd = raw_input(">> ") # Python 2.x
        except NameError:
            cmd = input(">> ") # Python 3.x
        cmd = cmd.strip()

        if cmd.isdigit():
            repl = int(cmd)
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf([warning("No suggestion number"), repl])
                return False
            printf([success("Replacing '%s' with '%s'" % (color(self.error.word, color='red'),color(suggs[repl], color='green')))])
            self.error.replace(suggs[repl])
            return True

        if cmd[0] == "R":
            if not cmd[1:].isdigit():
                printf([warning("Badly formatted command (try 'help')")])
                return False
            repl = int(cmd[1:])
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf([warning("No suggestion number"), repl])
                return False
            self.error.replace_always(suggs[repl])
            return True

        if cmd == "i":
            return True

        if cmd == "I":
            self.error.ignore_always()
            return True

        if cmd == "a":
            self.error.add()
            return True

        if cmd == "e":
            repl = raw_input(info("New Word: "))
            self.error.replace(repl.strip())
            return True

        if cmd == "q":
            self._stop = True
            return True

        if "help".startswith(cmd.lower()):
            self.print_help()
            return False

        printf([warning("Badly formatted command (try 'help')")])
        return False
コード例 #3
0
ファイル: CmdLineChecker.py プロジェクト: dot-Sean/PACKlib
    def read_command(self):
        cmd = raw_input(">> ")
        cmd = cmd.strip()

        if cmd.isdigit():
            repl = int(cmd)
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf(["No suggestion number", repl])
                return False
            printf(
                ["Replacing '%s' with '%s'" % (self.error.word, suggs[repl])])
            self.error.replace(suggs[repl])
            return True

        if cmd[0] == "R":
            if not cmd[1:].isdigit():
                printf(["Badly formatted command (try 'help')"])
                return False
            repl = int(cmd[1:])
            suggs = self.error.suggest()
            if repl >= len(suggs):
                printf(["No suggestion number", repl])
                return False
            self.error.replace_always(suggs[repl])
            return True

        if cmd == "i":
            return True

        if cmd == "I":
            self.error.ignore_always()
            return True

        if cmd == "a":
            self.error.add()
            return True

        if cmd == "e":
            repl = raw_input("New Word: ")
            self.error.replace(repl.strip())
            return True

        if cmd == "q":
            self._stop = True
            return True

        if "help".startswith(cmd.lower()):
            self.print_help()
            return False

        printf(["Badly formatted command (try 'help')"])
        return False
コード例 #4
0
 def run(self):
     """Run the spellchecking loop."""
     self._stop = False
     for err in self._checker:
         self.error = err
         printf(["ERROR:", err.word])
         printf(["HOW ABOUT:", err.suggest()])
         status = self.read_command()
         while not status and not self._stop:
             status = self.read_command()
         if self._stop:
                 break
コード例 #5
0
 def read_command(self):
     cmd = raw_input(">> ")
     cmd = cmd.strip()
     
     if cmd.isdigit():
         repl = int(cmd)
         suggs = self.error.suggest()
         if repl >= len(suggs):
             printf(["No suggestion number", repl])
             return False
         printf(["Replacing '%s' with '%s'" % (self.error.word,suggs[repl])])
         self.error.replace(suggs[repl])
         return True
     
     if cmd[0] == "R":
         if not cmd[1:].isdigit():
             printf(["Badly formatted command (try 'help')"])
             return False
         repl = int(cmd[1:])
         suggs = self.error.suggest()
         if repl >= len(suggs):
             printf(["No suggestion number", repl])
             return False
         self.error.replace_always(suggs[repl])
         return True
     
     if cmd == "i":
         return True
     
     if cmd == "I":
         self.error.ignore_always()
         return True
         
     if cmd == "a":
         self.error.add()
         return True
     
     if cmd == "e":
         repl = raw_input("New Word: ")
         self.error.replace(repl.strip())
         return True
          
     if cmd == "q":
         self._stop = True
         return True
     
     if "help".startswith(cmd.lower()):
         self.print_help()
         return False
     
     printf(["Badly formatted command (try 'help')"])
     return False
コード例 #6
0
def _test():
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    chk_dlg = GtkSpellCheckerDialog()
    chk_dlg.show()
    chk_dlg.connect('delete_event', gtk.main_quit)

    chkr = SpellChecker("en_US",text)

    chk_dlg.setSpellChecker(chkr)
    chk_dlg.updateUI()
    gtk.main()
コード例 #7
0
def _test():
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    chk_dlg = GtkSpellCheckerDialog()
    chk_dlg.show()
    chk_dlg.connect('delete_event', gtk.main_quit)

    chkr = SpellChecker("en_US", text)

    chk_dlg.setSpellChecker(chkr)
    chk_dlg.updateUI()
    gtk.main()
コード例 #8
0
ファイル: CmdLineChecker.py プロジェクト: amlweems/pyenchant
 def print_suggestions(self):
     """Prints out the suggestions for a given error
     This function will add vertical pipes to separate choices
     as well as the index of the replacement as expected by the replace function.
     I don't believe zero indexing is a problem as long as the user can see the numbers :)
     """
     result = ""
     suggestions = self.error.suggest()
     for index, sugg in enumerate(suggestions):
         if index is 0:
             result = result + color(str(index), color='yellow') + ": " + color(sugg, color='bold')
         else:
             result = result + " | " + color(str(index), color='yellow') + ": " + color(sugg, color='bold')
     printf([info("HOW ABOUT:"), result])
コード例 #9
0
def _test():
    class TestDialog(wxSpellCheckerDialog):
        def __init__(self,*args):
            wxSpellCheckerDialog.__init__(self,*args)
            wx.EVT_CLOSE(self,self.OnClose)
        def OnClose(self,evnt):
            if self._checker is not None:
                printf(["AFTER:", self._checker.get_text()])
            self.Destroy()
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    app = wx.PySimpleApp()
    dlg = TestDialog()
    chkr = SpellChecker("en_US",text)
    dlg.SetSpellChecker(chkr)
    dlg.Show()
    app.MainLoop()
コード例 #10
0
def _test():
    class TestDialog(wxSpellCheckerDialog):
        def __init__(self,*args):
            wxSpellCheckerDialog.__init__(self,*args)
            wx.EVT_CLOSE(self,self.OnClose)
        def OnClose(self,evnt):
            chkr = dlg.GetSpellChecker()
            if chkr is not None:
                printf(["AFTER:", chkr.get_text()])
            self.Destroy()
    from enchant.checker import SpellChecker
    text = "This is sme text with a fw speling errors in it. Here are a fw more to tst it ut."
    printf(["BEFORE:", text])
    app = wx.PySimpleApp()
    dlg = TestDialog()
    chkr = SpellChecker("en_US",text)
    dlg.SetSpellChecker(chkr)
    dlg.Show()
    app.MainLoop()
コード例 #11
0
def _test():
  class TestDialog(wxSpellCheckerDialog):
    def __init__(self, *args):
      wxSpellCheckerDialog.__init__(self, *args)
      wx.EVT_CLOSE(self, self.OnClose)

    def OnClose(self, evnt):
      if self._checker is not None:
        printf(["AFTER:", self._checker.get_text()])
      self.Destroy()

  from enchant.checker import SpellChecker
  text = "Alinuța are mre."
  printf(["BEFORE:", text])
  app = wx.PySimpleApp()
  dlg = TestDialog()
  chkr = SpellChecker("ro_RO", text)
  dlg.SetSpellChecker(chkr)
  dlg.Show()
  app.MainLoop()
コード例 #12
0
ファイル: CmdLineChecker.py プロジェクト: rfk/pyenchant
    def print_error(self):
        """print the spelling error to the console.

        Prints the misspelled word along with 100 characters of
        context on either side.  This number was arbitrarily chosen
        and could be modified to be tunable or changed entirely.
        It seems to be enough context to be helpful though
        """
        error_string = self._build_context(self.error.get_text(), self.error.word, self.error.wordpos)
        printf([error("ERROR: %s" % color(self.error.word, color='red'))])
        printf([info("")])
        printf([info(error_string)])
        printf([info("")])
コード例 #13
0
ファイル: CmdLineChecker.py プロジェクト: amlweems/pyenchant
 def run_on_file(self,infile,outfile=None,enc=None):
     """Run spellchecking on the named file.
     This method can be used to run the spellchecker over the named file.
     If <outfile> is not given, the corrected contents replace the contents
     of <infile>.  If <outfile> is given, the corrected contents will be
     written to that file.  Use "-" to have the contents written to stdout.
     If <enc> is given, it specifies the encoding used to read the
     file's contents into a unicode string.  The output will be written
     in the same encoding.
     """
     inStr = "".join(file(infile,"r").readlines())
     if enc is not None:
         inStr = inStr.decode(enc)
     self._checker.set_text(inStr)
     begin_msg = "Beginning spell check of %s" % infile
     printf([info(begin_msg)])
     printf([info("-" * len(begin_msg))])
     self.run()
     printf([success("Completed spell check of %s" % infile)])
     outStr = self._checker.get_text()
     if enc is not None:
         outStr = outStr.encode(enc)
     if outfile is None:
         outF = file(infile,"w")
     elif outfile == "-":
         outF = sys.stdout
     else:
         outF = file(outfile,"w")
     outF.write(outStr)
     outF.close()
コード例 #14
0
ファイル: CmdLineChecker.py プロジェクト: amlweems/pyenchant
 def print_error(self):
     """Prints the misspelled word along with 100 characters of
     context on either side.  This number was arbitrarily chosen
     and could be modified to be tunable or changed entirely.
     It seems to be enough context to be helpful though
     """
     error_string = self.error.leading_context(100) + color(self.error.word, color='red') + self.error.trailing_context(100)
     printf([error("ERROR: %s" % color(self.error.word, color='red'))])
     printf([info("")])
     for line in error_string.split("\n"):
         printf([info(line)])
コード例 #15
0
ファイル: CmdLineChecker.py プロジェクト: dot-Sean/PACKlib
 def run(self):
     """Run the spellchecking loop."""
     self._stop = False
     for err in self._checker:
         self.error = err
         printf(["ERROR:", err.word])
         printf(["HOW ABOUT:", err.suggest()])
         status = self.read_command()
         while not status and not self._stop:
             status = self.read_command()
         if self._stop:
             break
     printf(["DONE"])
コード例 #16
0
 def OnClose(self, evnt):
     chkr = dlg.GetSpellChecker()
     if chkr is not None:
         printf(["AFTER:", chkr.get_text()])
     self.Destroy()
コード例 #17
0
 def OnClose(self,evnt):
     if self._checker is not None:
         printf(["AFTER:", self._checker.get_text()])
     self.Destroy()
コード例 #18
0
 def _onIgnore(self, w, *args):
     printf(["ignore"])
     self._advance()
コード例 #19
0
ファイル: CmdLineChecker.py プロジェクト: amlweems/pyenchant
 def print_help(self):
     printf([info(color("0", color='yellow') + ".." + color("N", color='yellow') + ":\t" + color("replace", color='bold') + " with the numbered suggestion")])
     printf([info(color("R", color='cyan') + color("0", color='yellow') + ".." + color("R", color='cyan') + color("N", color='yellow') + ":\t" + color("always replace", color='bold') + " with the numbered suggestion")])
     printf([info(color("i", color='cyan') + ":\t\t" + color("ignore", color='bold') + " this word")])
     printf([info(color("I", color='cyan') + ":\t\t" + color("always ignore", color='bold') + " this word")])
     printf([info(color("a", color='cyan') + ":\t\t" + color("add", color='bold') + " word to personal dictionary")])
     printf([info(color("e", color='cyan') + ":\t\t" + color("edit", color='bold') + " the word")])
     printf([info(color("q", color='cyan') + ":\t\t" + color("quit", color='bold') + " checking")])
     printf([info(color("h", color='cyan') + ":\t\tprint this " + color("help", color='bold') + " message")])
     printf([info("----------------------------------------------------")])
     self.print_suggestions()
コード例 #20
0
 def _onIgnoreAll(self, w, *args):
     printf(["ignore all"])
     self._checker.ignore_always()
     self._advance()
コード例 #21
0
 def _onIgnore(self,w,*args):
     printf(["ignore"])
     self._advance()
コード例 #22
0
 def OnClose(self, evnt):
     if self._checker is not None:
         printf(["AFTER:", self._checker.get_text()])
     self.Destroy()
コード例 #23
0
 def _onIgnoreAll(self,w,*args):
     printf(["ignore all"])
     self._checker.ignore_always()
     self._advance()
コード例 #24
0
 def _onReplace(self,*args):
     printf(["Replace"])
     repl = self._getRepl()
     self._checker.replace(repl)
     self._advance()
コード例 #25
0
 def _onReplace(self, *args):
     printf(["Replace"])
     repl = self._getRepl()
     self._checker.replace(repl)
     self._advance()
コード例 #26
0
 def _onReplaceAll(self, *args):
     printf(["Replace all"])
     repl = self._getRepl()
     self._checker.replace_always(repl)
     self._advance()
コード例 #27
0
 def OnClose(self, evnt):
     chkr = dlg.GetSpellChecker()
     if chkr is not None:
         printf(["AFTER:", chkr.get_text()])
     self.Destroy()
コード例 #28
0
 def _onReplaceAll(self,*args):
     printf(["Replace all"])
     repl = self._getRepl()
     self._checker.replace_always(repl)
     self._advance()
コード例 #29
0
 def print_help(self):
     printf(["0..N:    replace with the numbered suggestion"])
     printf(["R0..rN:  always replace with the numbered suggestion"])
     printf(["i:       ignore this word"])
     printf(["I:       always ignore this word"])
     printf(["a:       add word to personal dictionary"])
     printf(["e:       edit the word"])
     printf(["q:       quit checking"])
     printf(["h:       print this help message"])
     printf(["----------------------------------------------------"])
     printf(["HOW ABOUT:", self.error.suggest()])
コード例 #30
0
ファイル: CmdLineChecker.py プロジェクト: dot-Sean/PACKlib
 def print_help(self):
     printf(["0..N:    replace with the numbered suggestion"])
     printf(["R0..rN:  always replace with the numbered suggestion"])
     printf(["i:       ignore this word"])
     printf(["I:       always ignore this word"])
     printf(["a:       add word to personal dictionary"])
     printf(["e:       edit the word"])
     printf(["q:       quit checking"])
     printf(["h:       print this help message"])
     printf(["----------------------------------------------------"])
     printf(["HOW ABOUT:", self.error.suggest()])
コード例 #31
0
 def _onButtonPress(self,widget,event):
     if event.type == gtk.gdk._2BUTTON_PRESS:
         printf(["Double click!"])
         self._onReplace()
コード例 #32
0
 def _onButtonPress(self, widget, event):
     if event.type == gtk.gdk._2BUTTON_PRESS:
         printf(["Double click!"])
         self._onReplace()