Class GrammarChecker

java.lang.Object
com.codename1.spellcheck.GrammarChecker

public final class GrammarChecker extends Object

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"
}
  • 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: 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: the rule
    • removeRule

      public void removeRule(GrammarChecker.Rule r)

      Removes a rule.

      Parameters
      • r: 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: the text, typically a paragraph
      Returns

      the issues, rule by rule