Package org.languagetool.rules.patterns

Examples of org.languagetool.rules.patterns.PatternRule


    exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false);
    final List<Element> elements = Arrays.asList(
            new Element("move", false, false, false),
            exceptionElem
    );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
View Full Code Here


    final List<Element> elements = Arrays.asList(
            negatedElement,
            new Element("How", false, false, false)
    );
    final Searcher errorSearcher = new Searcher(directory);
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final SearcherResult searcherResult = errorSearcher.findRuleMatchesOnIndex(rule1, new English());
    assertEquals(1, searcherResult.getCheckedSentences());
    assertEquals(1, searcherResult.getMatchingSentences().size());
    final List<RuleMatch> ruleMatches = searcherResult.getMatchingSentences().get(0).getRuleMatches();
    assertEquals(1, ruleMatches.size());
View Full Code Here

    final Element exceptionElem = new Element("", false, true, false);
    exceptionElem.setStringPosException("exception", false, false, false, false, false, "POS", false, false);
    final List<Element> elements = Arrays.asList(
            exceptionElem
    );
    final PatternRule rule1 = new PatternRule("RULE1", new English(), elements, "desc", "msg", "shortMsg");
    final Searcher errorSearcher = new Searcher(directory);
    try {
      errorSearcher.findRuleMatchesOnIndex(rule1, new English());
      fail();
    } catch (UnsupportedPatternRuleException expected) {
View Full Code Here

    query = patternRuleQueryBuilder.buildRelaxedQuery(rules.get(3));
    assertEquals(1, searcher.search(query, null, 1000).totalHits);
  }

  public void testUnsupportedPatternRule() throws Exception {
    final PatternRule patternRule = makeRule("<token skip='-1'><exception>and</exception></token>", false);
    final PatternRuleQueryBuilder patternRuleQueryBuilder = new PatternRuleQueryBuilder(language);
    try {
      patternRuleQueryBuilder.buildRelaxedQuery(patternRule);
      fail("Exception should be thrown for unsupported PatternRule");
    } catch (UnsupportedPatternRuleException expected) {}
View Full Code Here

      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());
    assertMatches(patternRule, 2);
  }
View Full Code Here

  private final PatternRule rule2;
  private final Language language;

  public MissingVerbRule(ResourceBundle messages, German language) {
    this.language = language;
    rule1 = new PatternRule("internal", language, Arrays.asList(
            new Element("Vielen", true, false, false),
            new Element("Dank", true, false, false)), "", "", "");
    rule2 = new PatternRule("internal", language, Arrays.asList(
            new Element("Herzlichen", true, false, false),
            new Element("Glückwunsch", true, false, false)), "", "", "");
    if (messages != null) {
      super.setCategory(new Category(messages.getString("category_grammar")));
    }
View Full Code Here

    langTool.disableRule(GermanSpellerRule.RULE_ID);
    final List<RuleMatch> matches = langTool.check("Das ist ein Tibbfehla.");
    assertEquals(1, matches.size());
    assertEquals(HunspellNoSuggestionRule.RULE_ID, matches.get(0).getRule().getId());

    final PatternRule ruleWithSuggestion = new PatternRule("TEST_ID", new GermanyGerman(),
            Collections.<Element>emptyList(), "description",
            "Meinten Sie <suggestion>Tibbfehla</suggestion>?", null);
    langTool.addRule(ruleWithSuggestion);
    final List<RuleMatch> matches2 = langTool.check("Das ist ein Tibbfehla.");
    assertEquals(0, matches2.size());   // no error anymore, as this is a suggestion
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 RuleWithMaxFilter filter = new RuleWithMaxFilter();
    List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, filteredMatches.size());
View Full Code Here

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

  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 RuleWithMaxFilter filter = new RuleWithMaxFilter();
    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 RuleWithMaxFilter filter = new RuleWithMaxFilter();
    List<RuleMatch> filteredMatches = filter.filter(Arrays.asList(match1, match2));
    assertEquals(2, 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.