use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class CompactStdoutHandler method handleResult.
@Override
protected void handleResult(Sentence sentence, List<RuleMatch> ruleMatches, Language language) {
if (ruleMatches.size() > 0) {
for (RuleMatch match : ruleMatches) {
String ruleId = match.getRule().getId();
if (match.getRule() instanceof AbstractPatternRule) {
AbstractPatternRule pRule = (AbstractPatternRule) match.getRule();
ruleId = pRule.getFullId();
}
System.out.println(ruleId + ": " + contextTools.getContext(match.getFromPos(), match.getToPos(), sentence.getText()));
checkMaxErrors(++errorCount);
}
}
checkMaxSentences(++sentenceCount);
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class LanguageToolSupport method updateHighlights.
private void updateHighlights(String disabledRule) {
List<Span> spans = new ArrayList<>();
List<RuleMatch> matches = new ArrayList<>();
for (RuleMatch match : ruleMatches) {
if (match.getRule().getId().equals(disabledRule)) {
continue;
}
matches.add(match);
spans.add(new Span(match));
}
prepareUpdateHighlights(matches, spans);
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class LanguageToolSupport method updateHighlights.
private void updateHighlights(List<RuleMatch> matches) {
List<Span> spans = new ArrayList<>();
for (RuleMatch match : matches) {
spans.add(new Span(match));
}
prepareUpdateHighlights(matches, spans);
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class MorfologikAsturianSpellerRuleTest method testMorfologikSpeller.
@Test
public void testMorfologikSpeller() throws IOException {
Asturian language = new Asturian();
MorfologikAsturianSpellerRule rule = new MorfologikAsturianSpellerRule(TestTools.getMessages("en"), language);
JLanguageTool langTool = new JLanguageTool(language);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("¿Festeyate colos correutores gramaticales?")).length);
RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("¿Afáyeste colos correutores gramaticales?"));
assertEquals(1, matches.length);
assertEquals(1, matches[0].getFromPos());
assertEquals(9, matches[0].getToPos());
assertEquals("Afayesti", matches[0].getSuggestedReplacements().get(0));
}
use of org.languagetool.rules.RuleMatch in project languagetool by languagetool-org.
the class CommandLineTools method printMatches.
/**
* Displays matches in a simple text format.
* @param ruleMatches Matches from rules.
* @param prevMatches Number of previously found matches.
* @param contents The text that was checked.
* @param contextSize The size of contents displayed.
* @since 1.0.1
*/
private static void printMatches(List<RuleMatch> ruleMatches, int prevMatches, String contents, int contextSize) {
int i = 1;
ContextTools contextTools = new ContextTools();
contextTools.setContextSize(contextSize);
for (RuleMatch match : ruleMatches) {
Rule rule = match.getRule();
String output = i + prevMatches + ".) Line " + (match.getLine() + 1) + ", column " + match.getColumn() + ", Rule ID: " + rule.getId();
if (rule instanceof AbstractPatternRule) {
AbstractPatternRule pRule = (AbstractPatternRule) rule;
if (pRule.getSubId() != null) {
output += "[" + pRule.getSubId() + "]";
}
}
System.out.println(output);
String msg = match.getMessage();
msg = msg.replaceAll("</?suggestion>", "'");
System.out.println("Message: " + msg);
List<String> replacements = match.getSuggestedReplacements();
if (!replacements.isEmpty()) {
System.out.println("Suggestion: " + String.join("; ", replacements));
}
System.out.println(contextTools.getPlainTextContext(match.getFromPos(), match.getToPos(), contents));
if (rule.getUrl() != null) {
System.out.println("More info: " + rule.getUrl());
}
if (i < ruleMatches.size()) {
System.out.println();
}
i++;
}
}
Aggregations