Grammar Checker in Python using Language-check

Python is an open-source programming language. It offers a vast variety of libraries that provide greater functionalities. The one such library is language_check. The language_check library doesn’t come bundled with Python 3. Instead, you have to manually download it from the command line or download it from the pypi.org and then install it manually.

Installation

To install via pip:

$ pip install --upgrade language-check

If you are using Python 2, you’ll need to install 3to2 beforehand:

$ pip install --upgrade 3to2

Requirements

  • Python v3.3+ (or 2.7)
  • Java v6.0 or higher.

The language_check specifies the mistakes along with Rule Id, Message, Suggestion, and line number in the document. Also using this we can directly correct the mistakes in the file only. It points out the mistakes accurately but it doesn’t guarantee 100% success in finding mistakes. Sometimes it may happen that it misses out some important mistake. So relying on it completely is not advisable.

Below python code demonstrates the use of language_check on Text Document.



filter_none

edit
close

play_arrow

link
brightness_4
code

import language_check
  
  
# Mention the language keyword
tool = language_check.LanguageTool('en-US')
i = 0
  
# Path of file which needs to be checked
with open(r'transcript1.txt', 'r') as fin:  
               
    for line in fin:
        matches = tool.check(line)
        i = i + len(matches)     
        pass
  
# prints total mistakes which are found 
# from the document
print("No. of mistakes found in document is ", i)
print()
    
# prints mistake one by one 
for mistake in matches:
    print(mistake)
    print()

chevron_right


Output :

No. of mistakes found in document is 3

Line 1, column 1, Rule ID: UPPERCASE_SENTENCE_START
Message: This sentence does not start with an uppercase letter
Suggestion: So
so as you can see buying a new car doesn’t…
^^

Line 1, column 102, Rule ID: ENGLISH_WORD_REPEAT_RULE
Message: Possible typo: you repeated a word
Suggestion: research
…ing if you’ll follow three simple steps research research research read and find out everything y…
^^^^^^^^^^^^^^^^^

Line 1, column 1025, Rule ID: MORFOLOGIK_RULE_EN_US
Message: Possible spelling mistake found
Suggestion: speech; spec; specs; speck; spec h
…unny way to start the speech and in the spech and now use the listener knew that I’m …

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

1


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.