A simple ruby wrapper for the LanguageTool HTTP API.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
test
.document
.gitignore
Gemfile
Gemfile.lock
LICENSE.txt
README.md
Rakefile
VERSION
languagetool.gemspec

README.md

Gem Version Dependency Status CircleCI

languagetool

A simple ruby wrapper for the LanguageTool HTTP API. This gem is only compatible with LanguageTool 3.4 and above.

Please visit the this link for more information about the public LanguageTool HTTP API, and its allowed parameters.

This project uses jeweler for managing and releasing this gem.

Installation

Add this line to your application's Gemfile:

gem 'languagetool'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install languagetool

Usage

First, you need to init the API:

require 'languagetool'
api = LanguageTool::API.new # Public LanguageTool API by default

Please bear in mind that Ruby uses underscore names (long_code), while the LanguageTool API uses camelcase names (longCode).

Available languages

You can retrieve the available languages with languages method:

languages = api.languages
# Play with the result!
languages.last.name      # English (US)
languages.last.code      # en
languages.last.long_code # en-US

Check

A text can be checked an validated with the check method:

check = api.check text: 'this ish a invalid text', language: 'en-US'
# Play with the result!
check.software # LanguageTool::Resources::Software
check.language # LanguageTool::Resources::Language
check.matches  # Array of LanguageTool::Resources::Match

You can also let the gem try to auto-correct the errors:

check.auto_fix # "This is an invalid text."

Error handling

If something went wrong, then the api wrapper will raise an LanguageTool::APIError exception. For example:

begin
  api.check text: 'Text' # Missing required 'language' parameter. Will raise a LanguageTool::APIError
rescue LanguageTool::APIError => e
  puts e.exception
end

Self-host LanguageTool server

First, create your own LanguageTool server (3.4 or above) by following this instructions.

Then, use your custom local or remote url in your ruby code:

require 'languagetool'
api = LanguageTool::API.new base_uri: 'http://localhost:8081/v2/'

Custom options

The api initialization accepts the following options:

Name Description Default
base_uri Base URI to make the HTTP requests. https://languagetool.org/api/v2

Authors

This project has been developed by:

Avatar Name Nickname Email
Daniel Herzog Wikiti wikiti.doghound@gmail.com