use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class GermanyGerman method getRelevantRules.
@Override
public List<Rule> getRelevantRules(ResourceBundle messages) throws IOException {
List<Rule> rules = new ArrayList<>(super.getRelevantRules(messages));
rules.add(new GermanSpellerRule(messages, this));
return rules;
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class ResultAreaHelper method getDisabledRulesHtml.
private String getDisabledRulesHtml() {
StringBuilder sb = new StringBuilder(40);
sb.append(messages.getString("deactivatedRulesText"));
int i = 0;
int deactivatedRuleCount = 0;
for (String ruleId : ltSupport.getConfig().getDisabledRuleIds()) {
if (ruleId.trim().isEmpty()) {
continue;
}
Rule rule = ltSupport.getRuleForId(ruleId);
if (rule == null || rule.isDefaultOff()) {
continue;
}
if (i++ > 0) {
sb.append(',');
}
RuleLink reactivationLink = RuleLink.buildReactivationLink(rule);
sb.append(" <a href=\"").append(reactivationLink).append("\">").append(rule.getDescription()).append("</a>");
deactivatedRuleCount++;
}
sb.append("<br>");
if (deactivatedRuleCount == 0) {
return "";
} else {
return sb.toString();
}
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class LanguageToolSupport method getDisabledRules.
private List<Rule> getDisabledRules() {
List<Rule> disabledRules = new ArrayList<>();
for (String ruleId : languageTool.getDisabledRules()) {
Rule rule = getRuleForId(ruleId);
if (rule == null || rule.isDefaultOff()) {
continue;
}
disabledRules.add(rule);
}
Collections.sort(disabledRules, (r1, r2) -> r1.getDescription().compareTo(r2.getDescription()));
return disabledRules;
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class LanguageToolSupport method createRulesMenu.
private void createRulesMenu(JMenu parent, List<Rule> rules) {
JMenu menu = parent;
int count = 0;
for (Rule rule : rules) {
count++;
String id = rule.getId();
JMenuItem ruleItem = new JMenuItem(rule.getDescription());
ruleItem.addActionListener(e -> enableRule(id));
menu.add(ruleItem);
if (rules.size() <= MAX_RULES_PER_MENU) {
continue;
}
//but only if the remain entries are more than one
if ((count % (MAX_RULES_PER_MENU - 1) == 0) && (rules.size() - count > 1)) {
JMenu more = new JMenu(messages.getString("guiActivateRuleMoreRules"));
menu.add(more);
menu = more;
}
}
}
use of org.languagetool.rules.Rule 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