Search in sources :

Example 46 with Rule

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);
    }
}
Also used : JLanguageTool(org.languagetool.JLanguageTool) Rule(org.languagetool.rules.Rule) File(java.io.File)

Example 47 with Rule

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;
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Rule(org.languagetool.rules.Rule)

Example 48 with Rule

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;
}
Also used : ArrayList(java.util.ArrayList) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule) Rule(org.languagetool.rules.Rule) GermanSpellerRule(org.languagetool.rules.de.GermanSpellerRule)

Example 49 with Rule

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;
        }
    }
}
Also used : Rule(org.languagetool.rules.Rule)

Example 50 with Rule

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);
}
Also used : Rule(org.languagetool.rules.Rule)

Aggregations

Rule (org.languagetool.rules.Rule)67 JLanguageTool (org.languagetool.JLanguageTool)16 PatternRule (org.languagetool.rules.patterns.PatternRule)15 ArrayList (java.util.ArrayList)14 RuleMatch (org.languagetool.rules.RuleMatch)14 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)12 Test (org.junit.Test)11 Language (org.languagetool.Language)11 IncorrectExample (org.languagetool.rules.IncorrectExample)8 English (org.languagetool.language.English)7 SpellingCheckRule (org.languagetool.rules.spelling.SpellingCheckRule)7 File (java.io.File)6 PatternToken (org.languagetool.rules.patterns.PatternToken)6 AnalyzedSentence (org.languagetool.AnalyzedSentence)5 AmericanEnglish (org.languagetool.language.AmericanEnglish)5 BitextRule (org.languagetool.rules.bitext.BitextRule)5 GermanSpellerRule (org.languagetool.rules.de.GermanSpellerRule)4 DisambiguationPatternRule (org.languagetool.tagging.disambiguation.rules.DisambiguationPatternRule)4 FileReader (java.io.FileReader)3 IOException (java.io.IOException)3