python语法错误检查_如何检查句子是否正确(Python中的简单语法检查)?

有各种各样的Web服务提供自动校对和语法检查。有些有一个Python库来简化查询。

据我所知,大多数工具(当然是在截止日期和语言工具之后)都是基于规则的。将选中的文本与描述常见错误的大量规则进行比较。如果规则匹配,软件将其称为错误。如果规则不匹配,则软件不执行任何操作(它无法检测没有规则的错误)。import ATD

ATD.setDefaultKey("your API key")

errors = ATD.checkDocument("Looking too the water. Fixing your writing typoss.")

for error in errors:

print "%s error for: %s **%s**" % (error.type, error.precontext, error.string)

print "some suggestions: %s" % (", ".join(error.suggestions),)

预期产量:grammar error for: Looking **too the**

some suggestions: to the

spelling error for: writing **typoss**

some suggestions: typos

可以在自己的计算机上运行服务器应用程序,建议使用4 GB RAM。>>> import language_check

>>> tool = language_check.LanguageTool('en-US')

>>> text = 'A sentence with a error in the Hitchhiker’s Guide tot he Galaxy'

>>> matches = tool.check(text)

>>> 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'])

>>> 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'

也可以私下运行服务器端。

另外,this是Ginger的一个黑库(screen scraping),可以说是最完善的免费语法检查选项之一。

Microsoft Word

应该可以编写Microsoft Word脚本并使用其语法检查功能。

更多

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值