public CategoryId getId() { return new CategoryId(id); }
private void writeCategory(JsonGenerator g, Category category) throws IOException { g.writeObjectFieldStart("category"); CategoryId catId = category.getId(); if (catId != null) { g.writeStringField("id", catId.toString()); g.writeStringField("name", category.getName()); } g.writeEndObject(); }
public Category getCategory(ResourceBundle messages) { return new Category(new CategoryId(id), messages.getString(messageKey)); } }
CategoryId id = category.getId(); if (id != null) { xml.append(" categoryid=\"").append(escapeXMLForAPIOutput(id.toString())).append('"');
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); }
private void validateRuleIds(Language lang, JLanguageTool languageTool) { List<Rule> allRules = languageTool.getAllRules(); Set<String> ids = new HashSet<>(); Set<Class> ruleClasses = new HashSet<>(); Set<String> categoryIds = new HashSet<>(); for (Rule rule : allRules) { assertIdUniqueness(ids, ruleClasses, lang, rule); if (rule.getId().equalsIgnoreCase("ID")) { System.err.println("WARNING: " + lang.getShortCodeWithCountryAndVariant() + " has a rule with id 'ID', this should probably be changed"); } Category category = rule.getCategory(); if (category != null && category.getId() != null) { String catId = category.getId().toString(); if (!catId.matches("[A-Z0-9_-]+") && !categoryIds.contains(catId)) { System.err.println("WARNING: category id '" + catId + "' doesn't match expected regexp [A-Z0-9_-]+"); categoryIds.add(catId); } } } }
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); }
private int getMatchPriority(RuleMatch r) { if (r.getRule().getCategory().getId() == null) { return 0; } int categoryPriority = language.getPriorityForId(r.getRule().getCategory().getId().toString()); int rulePriority = language.getPriorityForId(r.getRule().getId()); // if there is a priority defined for rule it takes precedence over category priority if (rulePriority != 0) { return rulePriority; } else { return categoryPriority; } }
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);
private void writeCategory(JsonGenerator g, Category category) throws IOException { g.writeObjectFieldStart("category"); CategoryId catId = category.getId(); if (catId != null) { g.writeStringField("id", catId.toString()); g.writeStringField("name", category.getName()); } g.writeEndObject(); }
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,
@Override public void treeNodesRemoved(TreeModelEvent e) { DefaultMutableTreeNode removedNode = (DefaultMutableTreeNode) e.getChildren()[0]; if (removedNode instanceof RuleNode) { if (((RuleNode) removedNode).isEnabled()) { enabledRuleIds.remove(((RuleNode) removedNode).getRule().getId()); } else { disabledRuleIds.remove(((RuleNode) removedNode).getRule().getId()); } } if (removedNode instanceof CategoryNode) { disabledCategories.remove(((CategoryNode) removedNode).getCategory().getId().toString()); } }
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; } }
private boolean getEnabledState(Rule rule) { boolean ret = true; if (disabledRuleIds.contains(rule.getId())) { ret = false; } if (disabledCategories.contains(rule.getCategory().getId().toString())) { ret = false; } if ((rule.isDefaultOff() || rule.getCategory().isDefaultOff()) && !enabledRuleIds.contains(rule.getId())) { ret = false; } if (rule.isDefaultOff() && rule.getCategory().isDefaultOff() && enabledRuleIds.contains(rule.getId())) { disabledCategories.remove(rule.getCategory().getId().toString()); } return ret; }
@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\"")); }
Map<String, DefaultMutableTreeNode> parents = new TreeMap<>(); for (Rule rule : rules) { if (!parents.containsKey(rule.getCategory().getId().toString())) { boolean enabled = true; if (disabledCategories != null && disabledCategories.contains(rule.getCategory().getId().toString())) { enabled = false; parents.put(rule.getCategory().getId().toString(), categoryNode); CategoryNode parent = (CategoryNode) parents.get(rule.getCategory().getId().toString()); parent.add(ruleNode);
public CategoryId getId() { return new CategoryId(id); }
CategoryId id = category.getId(); if (id != null) { xml.append(" categoryid=\"").append(escapeXMLForAPIOutput(id.toString())).append('"');
public Category getCategory(ResourceBundle messages) { return new Category(new CategoryId(id), messages.getString(messageKey)); } }
/** * @since 4.4 * Initialize set of style like categories */ public void initStyleCategories(List<Rule> allRules) { for (Rule rule : allRules) { if (rule.getCategory().getTabName() != null) { if (!specialTabCategories.containsKey(rule.getCategory().getName())) { specialTabCategories.put(rule.getCategory().getName(), rule.getCategory().getTabName()); } } if (rule.getLocQualityIssueType().toString().equalsIgnoreCase("STYLE") || rule.getLocQualityIssueType().toString().equalsIgnoreCase("REGISTER") || rule.getCategory().getId().toString().equals("STYLE") || rule.getCategory().getId().toString().equals("TYPOGRAPHY")) { if (!styleLikeCategories.contains(rule.getCategory().getName())) { styleLikeCategories.add(rule.getCategory().getName()); } } } }