Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.PatternRule


  @Test
  public void testRuleMatchesToXMLWithCategory() throws IOException {
    final List<RuleMatch> matches = new ArrayList<>();
    final String text = "This is a test sentence.";
    final List<Element> elements = Collections.emptyList();
    final Rule patternRule = new PatternRule("MY_ID", language, elements, "my description", "my message", "short message");
    patternRule.setCategory(new Category("MyCategory"));
    final RuleMatch match = new RuleMatch(patternRule, 8, 10, "myMessage");
    match.setColumn(99);
    match.setEndColumn(100);
    match.setLine(44);
    match.setEndLine(45);
View Full Code Here


  private static final Language language = TestTools.getDemoLanguage();

  public void testFilter() {
    final List<Element> fakeElements = new ArrayList<>();
    final PatternRule rule1 = new PatternRule("id1", language, fakeElements, "desc1", "msg1", "shortMsg1");
    final PatternRule rule2 = new PatternRule("id1", language, fakeElements, "desc2", "msg2", "shortMsg2");
    final RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
    final RuleMatch match2 = new RuleMatch(rule2, 15, 25, "Match2");
    final SameRuleGroupFilter filter = new SameRuleGroupFilter();
    final List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
    assertEquals(1, filteredMatches.size());
View Full Code Here

    assertEquals("Match1", filteredMatches.get(0).getMessage());
  }

  public void testNoFilteringIfNotOverlapping() {
    final List<Element> fakeElements = new ArrayList<>();
    final PatternRule rule1 = new PatternRule("id1", language, fakeElements, "desc1", "msg1", "shortMsg1");
    final PatternRule rule2 = new PatternRule("id1", language, fakeElements, "desc2", "msg2", "shortMsg2");
    final RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
    final RuleMatch match2 = new RuleMatch(rule2, 21, 25, "Match2");
    final SameRuleGroupFilter filter = new SameRuleGroupFilter();
    final List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, filteredMatches.size());
View Full Code Here

    assertEquals(2, filteredMatches.size());
  }

  public void testNoFilteringIfDifferentRulegroups() {
    final List<Element> fakeElements = new ArrayList<>();
    final Rule rule1 = new PatternRule("id1", language, fakeElements, "desc1", "msg1", "shortMsg1");
    final Rule rule2 = new PatternRule("id2", language, fakeElements, "desc2", "msg2", "shortMsg2");
    final RuleMatch match1 = new RuleMatch(rule1, 10, 20, "Match1");
    final RuleMatch match2 = new RuleMatch(rule2, 15, 25, "Match2");
    final SameRuleGroupFilter filter = new SameRuleGroupFilter();
    final List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, filteredMatches.size());
View Full Code Here

    contextTools.setContextSize(contextSize);
    for (final RuleMatch match : ruleMatches) {
      String output = i + prevMatches + ".) Line " + (match.getLine() + 1) + ", column "
              + match.getColumn() + ", Rule ID: " + match.getRule().getId();
      if (match.getRule() instanceof PatternRule) {
        final PatternRule pRule = (PatternRule) match.getRule();
        output += "[" + pRule.getSubId() + "]";
      }
      System.out.println(output);
      String msg = match.getMessage();
      msg = msg.replaceAll("<suggestion>", "'");
      msg = msg.replaceAll("</suggestion>", "'");
View Full Code Here

    contextTools.setErrorMarkerEnd("");

    for (RuleMatch match : ruleMatches) {
      String subId = "";
      if (match.getRule() instanceof PatternRule) {
        PatternRule pRule = (PatternRule) match.getRule();
        if (pRule.getSubId() != null) {
          subId = " subId=\"" + escapeXMLForAPIOutput(pRule.getSubId()) + "\" ";
        }
      }
      xml.append("<error fromy=\"").append(match.getLine()).append('"')
              .append(" fromx=\"").append(match.getColumn() - 1).append('"')
              .append(" toy=\"").append(match.getEndLine()).append('"')
View Full Code Here

    exampleCorrection = new StringBuilder();
    return example;
  }

  private PatternRule finalizeRule() {
    PatternRule rule = null;
    phraseElementInit();
    if (phraseElementList.isEmpty()) {
      rule = new PatternRule(id, language, elementList,
          name, "", shortMessage.toString());
      prepareRule(rule);             
    } else {
      if (!elementList.isEmpty()) {
        for (List<Element> ph : phraseElementList) {
          ph.addAll(new ArrayList<>(elementList));
        }
      }
      for (List<Element> phraseElement : phraseElementList) {
        processElement(phraseElement);
        rule = new PatternRule(id, language, phraseElement,
            name, message.toString(), shortMessage.toString(), "",
            phraseElementList.size() > 1);
        prepareRule(rule);
      }
    }
View Full Code Here

      System.out.println("\nTitle: " + sentence.getTitle());
      for (RuleMatch match : ruleMatches) {
        String output = i + ".) Line " + (match.getLine() + 1) + ", column "
                + match.getColumn() + ", Rule ID: " + match.getRule().getId();
        if (match.getRule() instanceof PatternRule) {
          final PatternRule pRule = (PatternRule) match.getRule();
          output += "[" + pRule.getSubId() + "]";
        }
        System.out.println(output);
        String msg = match.getMessage();
        msg = msg.replaceAll("<suggestion>", "'");
        msg = msg.replaceAll("</suggestion>", "'");
View Full Code Here

        insertSt.setString(1, language.getShortName());
        final Rule rule = match.getRule();
        insertSt.setString(2, rule.getId());
        insertSt.setString(3, rule.getCategory().getName());
        if (rule instanceof PatternRule) {
          final PatternRule patternRule = (PatternRule) rule;
          insertSt.setString(4, patternRule.getSubId());
        } else {
          insertSt.setNull(4, Types.VARCHAR);
        }
        insertSt.setString(5, rule.getDescription());
        insertSt.setString(6, StringUtils.abbreviate(match.getMessage(), 255));
View Full Code Here

    int exceptionCount = 0;

    final List<Rule> rules = lt.getAllActiveRules();
    for (Rule rule : rules) {
      if (rule instanceof PatternRule && !rule.isDefaultOff()) {
        final PatternRule patternRule = (PatternRule) rule;
        try {
          ruleCounter++;
          final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(patternRule, language);
          final List<MatchingSentence> matchingSentences = searcherResult.getMatchingSentences();
          boolean foundExpectedMatch = false;
View Full Code Here

TOP

Related Classes of org.languagetool.rules.patterns.PatternRule

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.