Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.PatternRule


      fail("Exception should be thrown for unsupported PatternRule");
    } catch (UnsupportedPatternRuleException expected) {}
  }

  public void testSpecialRegexSyntax() throws Exception {
    final PatternRule patternRule = makeRule("<token regexp='yes'>\\p{Punct}</token>", false);
    final PatternRuleQueryBuilder queryBuilder = new PatternRuleQueryBuilder(language);
    final Query query = queryBuilder.buildRelaxedQuery(patternRule);
    assertEquals("+fieldLowercase:\\p{Punct}", query.toString());
    assertEquals(RegexQuery.class, ((BooleanQuery)query).clauses().get(0).getQuery().getClass());
    assertMatches(patternRule, 2);
View Full Code Here


    assertEquals(RegexQuery.class, ((BooleanQuery)query).clauses().get(0).getQuery().getClass());
    assertMatches(patternRule, 2);
  }

  public void testSpecialRegexSyntax2() throws Exception {
    final PatternRule patternRule = makeRule("<token regexp='yes' inflected='yes'>\\p{Lu}\\p{Ll}+</token>", false);
    final PatternRuleQueryBuilder queryBuilder = new PatternRuleQueryBuilder(language);
    final Query query = queryBuilder.buildRelaxedQuery(patternRule);
    assertEquals("+fieldLowercase:\\p{Lu}\\p{Ll}+", query.toString());
    assertEquals(RegexQuery.class, ((BooleanQuery)query).clauses().get(0).getQuery().getClass());
    assertMatches(patternRule, 0);
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

   * 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

  }

  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

    langTool.addRule(rule);
    final List<RuleMatch> matches = langTool.check("This is a typoh.");
    assertEquals(1, matches.size());
    assertEquals(MorfologikAmericanSpellerRule.RULE_ID, matches.get(0).getRule().getId());

    final PatternRule ruleWithSuggestion = new PatternRule("TEST_ID", new AmericanEnglish(),
            Collections.<Element>emptyList(), "description",
            "Did you mean <suggestion>typoh</suggestion>?", null);
    langTool.addRule(ruleWithSuggestion);
    final List<RuleMatch> matches2 = langTool.check("This is a typoh.");
    assertEquals(0, matches2.size());   // no error anymore, as this is a suggestion
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.