Back to LanguageTool Homepage - Privacy - Imprint

Spell checking and ignore own words


(ravindu) #1

i need to know how to spell check and ignore my own words in java code... i tried code samples that given by your doc. but i can't figure out how to use that codes in one code....
can any one help me?


(ravindu) #2

I think i created code that i need.. Is this code right ?

public static void main(String[] args) {
JLanguageTool lt = new JLanguageTool(new BritishEnglish());
for (Rule rule : lt.getAllActiveRules()) {
if (rule instanceof SpellingCheckRule) {
List wordsToIgnore = Arrays.asList("specialword", "myotherword");
((SpellingCheckRule) rule).addIgnoreTokens(wordsToIgnore);
}
}

    List<RuleMatch> matches = null;
    try {
        matches = lt.check("A sentence with a specialword error in the Hitchhiker's Guide tot he Galaxy");
    } catch (IOException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

    for (RuleMatch match : matches) {
        System.out.println("Potential error at line "
                + match.getLine() + ", column "
                + match.getColumn() + ": " + match.getMessage());
        System.out.println("Suggested correction: "
                + match.getSuggestedReplacements());
    }
}