public CategoryId getId() { return new CategoryId(id); }
public Category getCategory(ResourceBundle messages) { return new Category(new CategoryId(id), messages.getString(messageKey)); } }
public AbstractFillerWordsRule(ResourceBundle messages, Language lang, UserConfig userConfig, boolean defaultActive) { super(messages); super.setCategory(new Category(new CategoryId("CREATIVE_WRITING"), messages.getString("category_creative_writing"), Location.INTERNAL, false)); this.lang = lang; if (!defaultActive) { setDefaultOff(); } if (userConfig != null) { int confPercent = userConfig.getConfigValueByID(getId()); if(confPercent >= 0) { this.minPercent = confPercent; } } setLocQualityIssueType(ITSIssueType.Style); }
public LongParagraphRule(ResourceBundle messages, Language lang, UserConfig userConfig, int defaultWords, boolean defaultActive) { super(messages); super.setCategory(new Category(new CategoryId("CREATIVE_WRITING"), messages.getString("category_creative_writing"), Location.INTERNAL, false)); this.lang = lang; if (!defaultActive) { setDefaultOff(); } if (defaultWords > 0) { this.maxWords = defaultWords; } if (userConfig != null) { int confWords = userConfig.getConfigValueByID(getId()); if (confWords > 0) { this.maxWords = confWords; } } setLocQualityIssueType(ITSIssueType.Style); }
boolean onByDefault = !OFF.equals(attrs.getValue(DEFAULT)); String tabName = attrs.getValue(TABNAME); category = new Category(catId != null ? new CategoryId(catId) : null, catName, location, onByDefault, tabName); if (attrs.getValue(TYPE) != null) { categoryIssueType = attrs.getValue(TYPE);
JLanguageTool.Mode mode = JLanguageTool.Mode.ALL; InputSentence inputSentence1a = new InputSentence("foo", lang, lang, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))), userConfig1, altLanguages, mode); InputSentence inputSentence1b = new InputSentence("foo", lang, lang, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))), userConfig1, altLanguages, mode); assertEquals(inputSentence1a, inputSentence1b); InputSentence inputSentence2 = new InputSentence("foo", lang, null, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))), userConfig1, altLanguages, mode); assertNotEquals(inputSentence1a, inputSentence2); assertNotEquals(inputSentence1b, inputSentence2); UserConfig userConfig2 = new UserConfig(Arrays.asList("foo1", "foo2")); InputSentence inputSentence1bUserConfig2 = new InputSentence("foo", lang, lang, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))), userConfig2, altLanguages, mode); assertEquals(inputSentence1a, inputSentence1bUserConfig2); new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))), userConfig1, altLanguages, JLanguageTool.Mode.TEXTLEVEL_ONLY); assertNotEquals(inputSentence1a, inputSentence1aOtherMode); List<Language> altLanguages2 = Arrays.asList(Languages.getLanguageForShortCode("xx")); InputSentence inputSentence1aSameAltLang = new InputSentence("foo", lang, lang, new HashSet<>(Arrays.asList("ID1")), new HashSet<>(Arrays.asList(new CategoryId("C1"))), new HashSet<>(Arrays.asList("ID2")), new HashSet<>(Arrays.asList(new CategoryId("C2"))), userConfig1, altLanguages1, mode); assertEquals(inputSentence1a, inputSentence1aSameAltLang); InputSentence inputSentence1aOtherAltLang = new InputSentence("foo", lang, lang,
public ReadabilityRule(ResourceBundle messages, Language lang, UserConfig userConfig, boolean tooEasyTest, int level, boolean defaultOn) { super(messages); super.setCategory(new Category(new CategoryId("TEXT_ANALYSIS"), "Text Analysis", Location.INTERNAL, false)); setLocQualityIssueType(ITSIssueType.Style); if(!defaultOn) { setDefaultOff(); } this.lang = lang; this.tooEasyTest = tooEasyTest; if (userConfig != null) { linguServices = userConfig.getLinguServices(); if(level >= 0) { this.level = level; } else { int lv = userConfig.getConfigValueByID(getId()); if(lv >= 0) { this.level = lv; } else { this.level = tooEasyTest ? 4 : 2; } } } else { linguServices = null; } }
@Test public void testRuleMatchesToXMLWithCategory() throws IOException { List<RuleMatch> matches = new ArrayList<>(); String text = "This is a test sentence."; List<PatternToken> patternTokens = Collections.emptyList(); Rule patternRule = new PatternRule("MY_ID", LANG, patternTokens, "my description", "my message", "short message"); patternRule.setCategory(new Category(new CategoryId("TEST_ID"), "MyCategory")); RuleMatch match = new RuleMatch(patternRule, null, 8, 10, "myMessage"); match.setColumn(99); match.setEndColumn(100); match.setLine(44); match.setEndLine(45); matches.add(match); String xml = SERIALIZER.ruleMatchesToXml(matches, text, 5, LANG, LANG); assertTrue(xml.contains(">\n" + "<error fromy=\"44\" fromx=\"98\" toy=\"45\" tox=\"99\" ruleId=\"MY_ID\" msg=\"myMessage\" " + "replacements=\"\" context=\"...s is a test ...\" contextoffset=\"8\" offset=\"8\" errorlength=\"2\" category=\"MyCategory\" " + "categoryid=\"TEST_ID\" locqualityissuetype=\"uncategorized\"/>\n" + "</matches>\n")); patternRule.setCategory(new Category(new CategoryId("CAT_ID"), "MyCategory")); RuleMatch match2 = new RuleMatch(patternRule, null, 8, 10, "myMessage"); String xml2 = SERIALIZER.ruleMatchesToXml(Collections.singletonList(match2), text, 5, LANG, LANG); assertTrue(xml2.contains("category=\"MyCategory\"")); assertTrue(xml2.contains("categoryid=\"CAT_ID\"")); }
public CategoryId getId() { return new CategoryId(id); }
public Category getCategory(ResourceBundle messages) { return new Category(new CategoryId(id), messages.getString(messageKey)); } }
public GermanReadabilityRule(ResourceBundle messages, Language lang, UserConfig userConfig, boolean tooEasyTest, int level, boolean defaultOn) { super(messages, lang, userConfig, tooEasyTest, level, defaultOn); super.setCategory(new Category(new CategoryId("TEXT_ANALYSIS"), "Textanalyse", Location.INTERNAL, false)); this.tooEasyTest = tooEasyTest; }
@NotNull private List<CategoryId> getCategoryIds(String paramName, Map<String, String> parameters) { List<String> stringIds = getCommaSeparatedStrings(paramName, parameters); List<CategoryId> ids = new ArrayList<>(); for (String stringId : stringIds) { ids.add(new CategoryId(stringId)); } return ids; }
public AbstractFillerWordsRule(ResourceBundle messages, Language lang, UserConfig userConfig, boolean defaultActive) { super(messages); super.setCategory(new Category(new CategoryId("CREATIVE_WRITING"), messages.getString("category_creative_writing"), Location.INTERNAL, false)); this.lang = lang; if (!defaultActive) { setDefaultOff(); } if (userConfig != null) { int confPercent = userConfig.getConfigValueByID(getId()); if(confPercent >= 0) { this.minPercent = confPercent; } } setLocQualityIssueType(ITSIssueType.Style); }
public SimpleReplaceRule(ResourceBundle messages) throws IOException { super(messages, new Dutch()); setLocQualityIssueType(ITSIssueType.Misspelling); setCategory(new Category(new CategoryId("VERGISSINGEN"), "Vergissingen")); addExamplePair(Example.wrong("<marker>ofzo</marker>."), Example.fixed("<marker>of zo</marker>.")); }
public LongParagraphRule(ResourceBundle messages, Language lang, UserConfig userConfig, int defaultWords, boolean defaultActive) { super(messages); super.setCategory(new Category(new CategoryId("CREATIVE_WRITING"), messages.getString("category_creative_writing"), Location.INTERNAL, false)); this.lang = lang; if (!defaultActive) { setDefaultOff(); } if (defaultWords > 0) { this.maxWords = defaultWords; } if (userConfig != null) { int confWords = userConfig.getConfigValueByID(getId()); if (confWords > 0) { this.maxWords = confWords; } } setLocQualityIssueType(ITSIssueType.Style); }
public SimpleReplaceRule(final ResourceBundle messages) throws IOException { super(messages); setLocQualityIssueType(ITSIssueType.Misspelling); setCategory(new Category(new CategoryId("PRAWDOPODOBNE_LITEROWKI"), "Prawdopodobne literówki")); setCheckLemmas(false); addExamplePair(Example.wrong("Uspokój <marker>sei</marker>."), Example.fixed("Uspokój <marker>się</marker>.")); }
boolean onByDefault = !OFF.equals(attrs.getValue(DEFAULT)); String tabName = attrs.getValue(TABNAME); category = new Category(catId != null ? new CategoryId(catId) : null, catName, location, onByDefault, tabName); if (attrs.getValue(TYPE) != null) { categoryIssueType = attrs.getValue(TYPE);
public ReadabilityRule(ResourceBundle messages, Language lang, UserConfig userConfig, boolean tooEasyTest, int level, boolean defaultOn) { super(messages); super.setCategory(new Category(new CategoryId("TEXT_ANALYSIS"), "Text Analysis", Location.INTERNAL, false)); setLocQualityIssueType(ITSIssueType.Style); if(!defaultOn) { setDefaultOff(); } this.lang = lang; this.tooEasyTest = tooEasyTest; if (userConfig != null) { linguServices = userConfig.getLinguServices(); if(level >= 0) { this.level = level; } else { int lv = userConfig.getConfigValueByID(getId()); if(lv >= 0) { this.level = lv; } else { this.level = tooEasyTest ? 4 : 2; } } } else { linguServices = null; } }
/** * @since 3.3 */ public static void configureFromRules(JLanguageTool langTool, Configuration config) { Set<String> disabledRules = config.getDisabledRuleIds(); if (disabledRules != null) { for (String ruleId : disabledRules) { langTool.disableRule(ruleId); } } Set<String> disabledCategories = config.getDisabledCategoryNames(); if (disabledCategories != null) { for (String categoryName : disabledCategories) { langTool.disableCategory(new CategoryId(categoryName)); } } if(config.getEnabledRulesOnly()) { for (Rule rule : langTool.getAllRules()) { langTool.disableRule(rule.getId()); } } Set<String> enabledRules = config.getEnabledRuleIds(); if (enabledRules != null) { for (String ruleName : enabledRules) { langTool.enableRule(ruleName); } } langTool.setConfigValues(config.getConfigurableValues()); }