跳转到主要内容

使用LanguageTool检查语法。

项目描述

LanguageTool的Python包装器。

Build status

这是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

先决条件

安装过程应负责下载LanguageTool(可能需要几分钟)。否则,您可以手动下载LanguageTool-stable.zip并将其解压缩到language_check包所在的位置。

Vim插件

要使用Vim中的language-check,安装Syntastic并使用以下设置

let g:syntastic_text_checkers = ['language_check']
let g:syntastic_text_language_check_args = '--language=en-US'

根据需要自定义您的语言。

项目详情


下载文件

下载适用于您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分布

language-check-1.1.tar.gz (33.4 kB 查看哈希值)

上传时间