Skip to content

Grammar

POST /v1/text/grammar checks Luganda text and returns a list of issues, each with suggested replacements.

Terminal window
curl https://api.openkob.com/v1/text/grammar \
-H "Authorization: Bearer $OPENKOB_API_KEY" \
-H "Content-Type: application/json" \
-d '{"input":"Oli otya otya ?"}'
Field Type Description
input string Required. 1 to 5,000 characters.
disabled_rules string[] Optional. Rule IDs to skip, for example ["G_REPEATED_WORD"].
ng_style "ng'" or "ŋ" Optional. Preferred spelling of the velar nasal. Defaults to "ng'".

Usage is counted in input characters.

{
"object": "grammar.check",
"issues": [
{ "rule_id": "G_REPEATED_WORD", "offset": 8, "length": 5, "severity": "suggestion",
"message": "Repeated word. Remove it if it's unintended.", "replacements": [""] }
]
}

Each issue has a rule_id, a severity (error, warning or suggestion), a message, and replacements (possibly empty). An empty-string replacement means “delete”.

offset and length count UTF-16 code units, the same as a JavaScript string index. In JavaScript, input.slice(offset, offset + length) gives the flagged text.

In Python, strings index by code point, so convert first:

encoded = text.encode("utf-16-le")
flagged = encoded[offset * 2:(offset + length) * 2].decode("utf-16-le")

Characters outside the Basic Multilingual Plane, such as emoji, take two code units.

Words that start with a capital letter are treated as names and skipped by the word rules.

Rule Detects Severity
G_MULTIPLE_SPACES Two or more spaces between words warning
G_SPACE_BEFORE_PUNCT A space before , . ! ? ; : error
G_MISSING_SPACE_AFTER_PUNCT Punctuation directly followed by a letter (numbers like 3.5, URLs, emails and e.g. are skipped) warning
G_SENTENCE_START_CAPITAL A sentence starting with a lowercase letter warning
G_UNMATCHED_PAIR Unmatched ( ), [ ], or an odd number of " error
G_REPEATED_WORD The same word twice in a row. Luganda uses reduplication, so this is only a suggestion. suggestion
Rule Detects Example Severity
L_TRIPLE_VOWEL The same vowel three or more times baaana → baana error
L_TRIPLE_CONSONANT The same consonant three or more times kkkubo → kkubo error
L_NG_STYLE ŋ or ng' that doesn’t match ng_style aŋa → ang'a suggestion
L_R_L l after e/i, or r after a/o/u okuraba → okulaba, ekilabo → ekirabo suggestion
L_LONG_VOWEL_BEFORE_NASAL A double vowel before a nasal compound (mb, nd, ng, …) omuuntu → omuntu warning
L_NON_LUGANDA_LETTER h, q or x in a word xyz suggestion
L_SPELLING A word not in the Luganda wordlist, with up to 3 suggestions warning