Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class GrammarChecker

  1. Object
  2. GrammarChecker

Checks text against a list of grammar and style rules. english() holds the rules English text gets by default – a repeated word, “a” against “an”, a sentence that starts in lower case, a space before punctuation, a doubled space – and an application adds its own Rules or replaces the list.

GrammarChecker g = GrammarChecker.english();
for (ProofIssue i : g.check("This is is an test.")) {
    // "Repeated word" over "is is", "Use a before a consonant sound" over "an"
}

Nested types

interface GrammarChecker.RuleOne check over a text.

Fields

public static final GrammarChecker.Rule REPEATED_WORDA word written twice in a row.
public static final GrammarChecker.Rule ARTICLE“a” before a vowel sound and “an” before a consonant one.
public static final GrammarChecker.Rule CAPITALIZATIONA sentence that starts in lower case.
public static final GrammarChecker.Rule SPACINGA space before a comma, period or semicolon, and two spaces in a row.

Constructors

public GrammarChecker()A checker with no rules.
public GrammarChecker(GrammarChecker.Rule... rules)A checker with the given rules.

Methods

public static GrammarChecker english()A checker with the English rules.
public void addRule(GrammarChecker.Rule r)Adds a rule.
public void removeRule(GrammarChecker.Rule r)Removes a rule.
public List<GrammarChecker.Rule> getRules()The rules, in order.
public List<ProofIssue> check(String text)The problems every rule finds in a text.

Inherited methods

Field details

REPEATED_WORD

public static final GrammarChecker.Rule REPEATED_WORD
A word written twice in a row.

ARTICLE

public static final GrammarChecker.Rule ARTICLE
“a” before a vowel sound and “an” before a consonant one.

CAPITALIZATION

public static final GrammarChecker.Rule CAPITALIZATION
A sentence that starts in lower case.

SPACING

public static final GrammarChecker.Rule SPACING
A space before a comma, period or semicolon, and two spaces in a row.

Constructor details

GrammarChecker

public GrammarChecker()
A checker with no rules.

GrammarChecker

public GrammarChecker(GrammarChecker.Rule... rules)
A checker with the given rules.

Parameters

rules GrammarChecker.Rule...
the rules, in order

Method details

english

public static GrammarChecker english()
A checker with the English rules.

Returns

a new checker

addRule

public void addRule(GrammarChecker.Rule r)
Adds a rule.

Parameters

r GrammarChecker.Rule
the rule

removeRule

public void removeRule(GrammarChecker.Rule r)
Removes a rule.

Parameters

r GrammarChecker.Rule
the rule

getRules

public List<GrammarChecker.Rule> getRules()
The rules, in order.

Returns

a copy of the list

check

public List<ProofIssue> check(String text)
The problems every rule finds in a text.

Parameters

text String
the text, typically a paragraph

Returns

the issues, rule by rule