use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class Main method initLanguageTool.
private void initLanguageTool() {
try {
prepareConfig(docLanguage);
// not using MultiThreadedJLanguageTool here fixes "osl::Thread::Create failed", see https://bugs.documentfoundation.org/show_bug.cgi?id=90740:
langTool = new JLanguageTool(docLanguage, config.getMotherTongue());
File ngramDirectory = config.getNgramDirectory();
if (ngramDirectory != null) {
File ngramLangDir = new File(config.getNgramDirectory(), docLanguage.getShortCode());
if (ngramLangDir.exists()) {
// user might have ngram data only for some languages and that's okay
langTool.activateLanguageModelRules(ngramDirectory);
}
}
for (Rule rule : langTool.getAllActiveRules()) {
if (rule.isDictionaryBasedSpellingRule()) {
langTool.disableRule(rule.getId());
}
if (rule.useInOffice()) {
langTool.enableRule(rule.getId());
}
}
recheck = false;
} catch (Throwable t) {
showError(t);
}
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class ConfigurationDialog method createTree.
private DefaultMutableTreeNode createTree(List<Rule> rules) {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Rules");
String lastRuleId = null;
Map<String, DefaultMutableTreeNode> parents = new TreeMap<>();
for (Rule rule : rules) {
if (!parents.containsKey(rule.getCategory().getName())) {
boolean enabled = true;
if (config.getDisabledCategoryNames() != null && config.getDisabledCategoryNames().contains(rule.getCategory().getName())) {
enabled = false;
}
if (rule.getCategory().isDefaultOff()) {
enabled = false;
}
DefaultMutableTreeNode categoryNode = new CategoryNode(rule.getCategory(), enabled);
root.add(categoryNode);
parents.put(rule.getCategory().getName(), categoryNode);
}
if (!rule.getId().equals(lastRuleId)) {
RuleNode ruleNode = new RuleNode(rule, getEnabledState(rule));
parents.get(rule.getCategory().getName()).add(ruleNode);
}
lastRuleId = rule.getId();
}
return root;
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class SwissGerman 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 LanguageToolSupport method addDisabledRulesToMenu.
private void addDisabledRulesToMenu(List<Rule> disabledRules, JMenu menu) {
if (disabledRules.size() <= MAX_RULES_NO_CATEGORY_MENU) {
createRulesMenu(menu, disabledRules);
return;
}
TreeMap<String, ArrayList<Rule>> categories = new TreeMap<>();
for (Rule rule : disabledRules) {
if (!categories.containsKey(rule.getCategory().getName())) {
categories.put(rule.getCategory().getName(), new ArrayList<>());
}
categories.get(rule.getCategory().getName()).add(rule);
}
JMenu parent = menu;
int count = 0;
for (String category : categories.keySet()) {
count++;
JMenu submenu = new JMenu(category);
parent.add(submenu);
createRulesMenu(submenu, categories.get(category));
if (categories.keySet().size() <= MAX_CATEGORIES_PER_MENU) {
continue;
}
//but only if the remain entries are more than one
if ((count % (MAX_CATEGORIES_PER_MENU - 1) == 0) && (categories.keySet().size() - count > 1)) {
JMenu more = new JMenu(messages.getString("guiActivateRuleMoreCategories"));
parent.add(more);
parent = more;
}
}
}
use of org.languagetool.rules.Rule in project languagetool by languagetool-org.
the class LanguageToolSupport method enableRule.
void enableRule(String ruleId) {
Rule rule = this.getRuleForId(ruleId);
if (rule == null) {
//System.err.println("No rule with id: <"+ruleId+">");
return;
}
if (rule.isDefaultOff()) {
config.getEnabledRuleIds().add(ruleId);
} else {
config.getDisabledRuleIds().remove(ruleId);
}
languageTool.enableRule(ruleId);
fireEvent(LanguageToolEvent.Type.RULE_ENABLED, null);
checkImmediately(null);
}
Aggregations