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.
Python3
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 () |
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 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 speech and now use the listener knew that I’m …