languagetool

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package languagetool is the library behind the languagetool command: the HTTP client, request shaping, and the typed data models for the LanguageTool API.

The public API at api.languagetool.org is open: no API key, no auth. This package wraps it with a rate-limited client that the kit operations consume.

Index

Constants

View Source
const DefaultUserAgent = "languagetool/dev (+https://github.com/tamnd/languagetool-cli)"

DefaultUserAgent identifies the client to LanguageTool.

View Source
const Host = "api.languagetool.org"

Host is the LanguageTool API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a rate-limited HTTP client for the LanguageTool API.

func NewClient

func NewClient(cfg Config) *Client

NewClient returns a Client configured with cfg.

func (*Client) Check

func (c *Client) Check(ctx context.Context, text, lang string) ([]GrammarIssue, error)

Check submits text to the grammar check endpoint and returns any matches.

func (*Client) ListLanguages

func (c *Client) ListLanguages(ctx context.Context) ([]Language, error)

ListLanguages fetches the list of supported languages.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	Rate      time.Duration
	Retries   int
	Timeout   time.Duration
}

Config holds constructor parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults for the LanguageTool public API.

type Domain

type Domain struct{}

Domain is the LanguageTool driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (uriType, id). A language code (2-letter or IETF like en-US) maps to ("lang", input); anything else is treated as text to check and maps to ("text", input).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme and the identity the single-site binary inherits.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate returns the canonical URL for a (uriType, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and the two LanguageTool operations.

type GrammarIssue

type GrammarIssue struct {
	Sentence     string   `kit:"id" json:"sentence"`
	Offset       int      `json:"offset"`
	Length       int      `json:"length"`
	Message      string   `json:"message"`
	ShortMessage string   `json:"short_message"`
	Replacements []string `json:"replacements"`
	RuleID       string   `json:"rule_id"`
	Category     string   `json:"category"`
	IssueType    string   `json:"issue_type"`
	Context      string   `json:"context"`
}

GrammarIssue is one grammar or style match from the LanguageTool check endpoint.

type Language

type Language struct {
	Code     string `kit:"id" json:"code"`
	Name     string `json:"name"`
	LongCode string `json:"long_code"`
}

Language is one supported language entry from the languages endpoint.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL