使用语言工具检查语法。
language-check的Python项目详细描述
语言工具的python包装器。
这是叉子 https://bitbucket.org/spirit/language_tool更容易分解 命令行的结果。
示例用法
来自口译员:
>>> import language_check >>> tool = language_check.LanguageTool('en-US') >>> text = u'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy' >>> matches = tool.check(text) >>> len(matches) 2
查看一些Match对象属性:
>>> matches[0].fromy, matches[0].fromx (0, 16) >>> matches[0].ruleId, matches[0].replacements ('EN_A_VS_AN', ['an']) >>> matches[1].fromy, matches[1].fromx (0, 50) >>> matches[1].ruleId, matches[1].replacements ('TOT_HE', ['to the'])
打印Match对象:
>>> print(matches[1]) Line 1, column 51, Rule ID: TOT_HE[1] Message: Did you mean 'to the'? Suggestion: to the ...
自动将建议应用于文本:
>>> language_check.correct(text, matches) 'A sentence with an error in the Hitchhiker’s Guide to the Galaxy'
从命令行:
$ echo 'This are bad.' > example.txt $ language-check example.txt example.txt:1:1: THIS_NNS[3]: Did you mean 'these'?
安装
通过PIP安装:
$ pip install --upgrade language-check
如果您使用的是python 2,则需要事先安装3to2:
$ pip install --upgrade 3to2
先决条件
- Python 3.3+(或2.7)
- lib3to2 (如果为python 2安装)
- LanguageTool(Java 6.0+)
安装过程应注意下载语言工具(它可能 花几分钟)。否则,您可以手动下载 LanguageTool-stable.zip然后解压缩 放入language_check包所在的位置。
VIM插件
要在vim中使用语言检查,请安装Syntastic,并使用以下命令 设置:
letg:syntastic_text_checkers = ['language_check'] letg:syntastic_text_language_check_args ='--language=en-US'
根据需要自定义语言。