Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.PatternRule


  }

  public void testOverlapFilter() throws IOException {
    final Category category = new Category("test category");
    final List<Element> elements1 = Arrays.asList(new Element("one", true, false, false));
    final PatternRule rule1 = new PatternRule("id1", new English(), elements1, "desc1", "msg1", "shortMsg1");
    rule1.setSubId("1");
    rule1.setCategory(category);

    final List<Element> elements2 = Arrays.asList(new Element("one", true, false, false), new Element("two", true, false, false));
    final PatternRule rule2 = new PatternRule("id1", new English(), elements2, "desc2", "msg2", "shortMsg2");
    rule2.setSubId("2");
    rule2.setCategory(category);

    final JLanguageTool tool = new JLanguageTool(new English());
    tool.addRule(rule1);
    tool.addRule(rule2);
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 (final ArrayList<Element> ph : phraseElementList) {
          ph.addAll(new ArrayList<>(elementList));
        }
      }
      for (final ArrayList<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

    final Language language = Language.getLanguageForShortName(languageCode);
    final File indexDir = new File(args[3]);
    final Searcher searcher = new Searcher(new SimpleFSDirectory(indexDir));
    for (String ruleId : ruleIds) {
      final long ruleStartTime = System.currentTimeMillis();
      final PatternRule rule = searcher.getRuleById(ruleId, ruleFile);
      final SearcherResult searcherResult = searcher.findRuleMatchesOnIndex(rule, language);
      int i = 1;
      if (searcherResult.getMatchingSentences().size() == 0) {
        System.out.println("[no matches]");
      }
View Full Code Here

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

        System.out.println("\nTitle: " + title);
        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

   * Get the tokens of simple suggestions, i.e. those that don't use back references.
   */
  public List<String> getSuggestionTokens(Rule rule, Language language) {
    final List<String> wordsToBeIgnored = new ArrayList<>();
    if (rule instanceof PatternRule) {
      final PatternRule patternRule = (PatternRule) rule;
      final String message = patternRule.getMessage();
      final List<String> suggestions = getSimpleSuggestions(message);
      final List<String> tokens = getSuggestionTokens(suggestions, language);
      wordsToBeIgnored.addAll(tokens);
    }
    return wordsToBeIgnored;
View Full Code Here

    contextTools.setErrorMarkerEnd("");

    for (final RuleMatch match : ruleMatches) {
      String subId = "";
      if (match.getRule() instanceof PatternRule) {
        final 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

    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

    for (String ruleId : ruleIds) {
      for (Rule rule : rules) {
        if (rule.getId().equals(ruleId)) {
          // can only display pattern rules
          try {
            PatternRule patternRule = (PatternRule) rule;
            String tempRuleString = patternRule.toXML();
            tempRuleString = tempRuleString.replaceAll("\\<",
                "&lt;").replaceAll("\\>", "&gt;");
            fetchedRuleString = fetchedRuleString.concat(
                tempRuleString).concat("<br>");
            break;
View Full Code Here

public class SameRuleGroupFilterTest extends TestCase {

  public void testFilter() {
    final List<Element> fakeElements = new ArrayList<>();
    final PatternRule rule1 = new PatternRule("id1", Language.DEMO, fakeElements, "desc1", "msg1", "shortMsg1");
    final PatternRule rule2 = new PatternRule("id1", Language.DEMO, 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

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.