cpg314 / ltapiserv-rs

Server implementation of the LanguageTool API for offline grammar and spell checking, based on nlprule and symspel. And a small graphical command-line client.

Home Page:https://c.pgdm.ch/code/ltapiserv-rs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ltapiserv-rs

Server implementation of the LanguageTool API for offline grammar and spell checking, based on:

This also contains a simple command-line client, displaying results graphically with ariadne.

See https://c.pgdm.ch/eps-projects/ltapiserv-rs

Installation

The recommended method is to get a binary from the releases page.

The .deb and Arch Linux packages will install a service definition in /usr/lib/systemd/user/ltapiser-rs.service, and it should suffice to enable it with

$ systemctl --user enable --now ltapiserv-rs

A path to a custom dictionary can be passed to the server via the --dictionary option. The default systemd configuration places it in ~/dictionary.txt.

tar.gz archive

$ sudo cp ltapiserv-rs /usr/local/bin
$ sudo chmod +x /usr/local/bin/ltapiserv-rs
$ ln -s $(pwd)/ltapiserv-rs.service ~/.config/systemd/user/ltapiserv-rs.service
$ systemctl --user daemon-reload && systemctl --user enable --now ltapiserv-rs
$ systemctl --user status ltapiserv-rs

From source

Alternatively, binaries can be built from source as follows:

$ # Create en_US.tar.gz data archive (will be embedded in the binary).
$ cargo make create-archive
$ cargo build --release

Usage

The following clients have been tested. The server should be compatible with others, but there might be idiosyncrasies; don't hesitate to send a PR.

Browser extension

Install the official LanguageTool browser extension (e.g. for Chrome or Firefox) and configure it to use your local server:

Chrome extension settings

Command line client

A command line client, ltapi-client, is also included in this codebase.

$ cat text.txt | ltapi-client --server http://localhost:8875
$ ltapi-client --server http://localhost:8875 test.txt

Command line interface

The return code will be 1 if any error is detected.

The server address can be configured through the LTAPI_SERVER environment variable.

Formats like Markdown, HTML, LaTeX etc. can be processed through pandoc:

$ pandoc README.md -t plain | ltapi-client

flycheck-languagetool (emacs)

See https://github.com/emacs-languagetool/flycheck-languagetool

(use-package flycheck-languagetool
  :ensure t
  :hook (text-mode . flycheck-languagetool-setup)
  :init
  (setq flycheck-languagetool-url "http://127.0.0.1:8875")
)

ltex-ls (language server protocol for markup)

See https://github.com/valentjn/ltex-ls.

This currently requires this patch to send the proper content type in the requests (this also could be done in ltapiserv-rs with an axum middleware to edit the content type).

Use the ltex.languageToolHttpServerUri variable to set the URL, e.g. with lsp-ltex in emacs:

(use-package lsp-ltex
  :ensure t
  :hook (text-mode . (lambda ()
                       (require 'lsp-ltex)
                       (lsp)))  ; or lsp-deferred
  :init
  (setq lsp-ltex-version "16.0.0"
        lsp-ltex-languagetool-http-server-uri "http://localhost:8875"
        )
)

TODO

  • Dynamic editing of the dictionary (/words endpoint).
  • Tests

About

Server implementation of the LanguageTool API for offline grammar and spell checking, based on nlprule and symspel. And a small graphical command-line client.

https://c.pgdm.ch/code/ltapiserv-rs

License:GNU General Public License v3.0


Languages

Language:Rust 92.8%Language:Handlebars 7.2%