2

I'm looking for a fast way to count grammar errors in Python. For example, I need something along these lines:

matches = grammar_checker.check('You is awesome!')
assert len(matches) == 1

Speed is much more an issue than accuracy. I could live with a few false positives or negatives as a trade-off for fast checks. I am talking here about problem sizes on the order of 100k documents (with roughly 5-10k characters) in only a few minutes.

I came across LanguageTool in Java and its Python wrapper language_check. However, these are unfortunately too slow for my purposes. Any other suggestions or ideas? Thanks!

SmCaterpillar
  • 6,683
  • 7
  • 42
  • 70
  • On hold, really? [This question](https://stackoverflow.com/questions/10252448/how-to-check-whether-a-sentence-is-correct-simple-grammar-check-in-python) is much less specific (without the efficiency constraint) and has over 20 votes. Why is that one not on hold? – SmCaterpillar Feb 21 '18 at 07:23

2 Answers2

6

You should look How to check whether a sentence is correct (simple grammar check in Python)?

Also, you should use "grammar-check 1.3.1" module and works fast.

For more information, check out https://pypi.python.org/pypi/grammar-check/1.3.1

import grammar_check
tool = grammar_check.LanguageTool('en-GB')
text = 'This are bad.'
matches = tool.check(text)
len(matches)
>>>1

grammar_check.correct(text, matches)
>>>'These are bad'
Orhan Solak
  • 789
  • 2
  • 15
  • 30
  • 1
    I'll look into the NLTK stuff thanks. Nonetheless, I cannot use `grammar_check` because it's just a fork of `language_check`. Therefore, also uses the Java LanguageTool which is too slow for my purposes. Still could be that I can configure the LanguageTool server better that it internally uses multiprocessing, but I haven't found a way to do that, yet. – SmCaterpillar Feb 21 '18 at 07:22
0

You can try Grammarly, it is one of the most popular speller checkers. Probably, they can provide some kind of an API. (I am not an expert in Python frameworks but I guess you should try this if you need to just check grammar as fast as possible.

MAP Inc.
  • 17
  • 1
  • 8
  • 2
    I don't think there is an API for Grammarly, but I feel like this would be even slower because you would have to make requests to their server with large amounts of text. And even as I'm typing this, Grammarly is taking a few seconds for each mistake in this text box. – whackamadoodle3000 Feb 20 '18 at 21:51
  • there is an api for Grammarly now at https://grammarbot.io that you can use for free through the pypi package https://pypi.org/project/grammarbot/ – aldorath Jan 31 '21 at 07:08