Start your own Grammar Check website

As I often need to write narratives at work and English is my second language, I need a tool to help me with proofreading. Word’s built-in function is too basic, it is good at spellcheck but not so much on grammar check. There are many services available online, such as Grammarly, which offers a browser add-on that highlights spell or grammar mistakes. They usually work well, but with one problem: you cannot trust such tools with your confidential document, especially for the ones that send your text to the back-end server. Therefore, you will need your own website + server behind your company’s firewall.

After some research, I decided to go with an open-source software called LanguageTool because of its flexibility.

Step 1: Set up the LanguageTool server

  1. Check out the package from GitHub.
  2. Build the “standalone” directory:
    ./build.sh languagetool-standalone package -DskipTests
  3. Find the generated JAR file and run the following command:
    java -cp languagetool-server.jar org.languagetool.server.HTTPServer --port 7777 --public --allow-origin
  4. Do a quick test:
    curl --data "language=en-US&text=a simple test" http://localhost:7777/v2/check

Step 2: Set up the website with TinyMCE TextEditor & LanguageTool plugin

  1. Set up the Meteor server – my favorite web app framework:)
  2. Although Meteor has a TinyMCE package, we unfortunately cannot use it without lots of effort, why? The LanguageTool plugin for TinyMCE was developed in 2007 and it was using TinyMCE API version 3. TinyMCE package uses API version 4, which is not backward compatible. Even worse, certain APIs do not have a migration path, e.g. ControlManager. So we have to manually import TinyMCE to the web app.
  3. Download the 3.5.11 version from this page. Extract tiny_mce.js, “themes” & “langs” folder to the relevant Meteor folders.
  4. Checkout the following file and move to the relevant Meteor folder, e.g. imports/ui/js/.
    wget https://www.languagetool.org/online-check/tiny_mce/plugins/atd-tinymce/editor_plugin2.js
  5. Make sure you go through all the Javascript files and remove any logging functions and references.
  6. Copy/paste the HTML code from here, change the LanguageTool URL to point to your server.
  7. Run meteor!

Congrats! You have your own and safe grammar check website!

What’s the next step? The server takes the raw text and returns a list of suggestions based on a set of predefined rules. The rules are not comprehensive, but it is possible to add additional rules, even better, a language model either locally or hosted on AWS.

Advertisements