def jupyterspellchecker(): parser = argparse.ArgumentParser( description='''Spell check a Jupyter/IPython notebook to a LaTeX file. Raw cells and markdown cells are spell checked in American English. ''') parser.add_argument('infile', help='path and filename of the input notebook file.') parser.add_argument('outfile', help='path and filename of the output file.') args = parser.parse_args() chkr = enchant.checker.SpellChecker("en_US", filters=[LatexCommandFilter]) cmdln = CmdLineChecker() cmdln.set_checker(chkr) with open(args.infile, 'r') as f: print('Parsing ', args.infile) ipynb = json.load(f) if 'cells' in ipynb: # newer versions of notebook cells = ipynb['cells'] else: # notebook format 1 cells = ipynb['worksheets'][0]['cells'] for cell in cells: if cell['cell_type'] in ['markdown', 'raw', 'heading']: for i, line in enumerate(cell['source']): chkr.set_text(line) cmdln.run() cell['source'][i] = chkr.get_text() with open(args.outfile, 'w') as f: print('Writing ', args.outfile) json.dump(ipynb, f) sys.exit()
def __init__(self, language, pwl=None): if pwl: language = enchant.DictWithPWL(language, pwl) self._checker = _SpellChecker(lang=language, filters=filters_to_use) self.cmdln = CmdLineChecker() self.cmdln.set_checker(self._checker)
# Pretty simple command line spellchecker for NWN dialogs... # Note this requires PyEnchant and it's command line is some # what wonky. Type 'h' at the command prompt to get options # for correcting wor import enchant import enchant.checker from enchant.checker.CmdLineChecker import CmdLineChecker from pynwn.module import Module if __name__ == '__main__': # Using US english dictionary. chkr = enchant.checker.SpellChecker('en_US') cmdln = CmdLineChecker() cmdln.set_checker(chkr) mod = Module('test.mod') for dlg in mod.glob('*.dlg'): print(dlg.resref) for n in dlg.entries: if n.get_text(0) is None or len(n.get_text(0)) == 0: continue print n.get_text(0) chkr.set_text(n.get_text(0)) cmdln.run() n.set_text(0, chkr.get_text())