Package org.languagetool

Examples of org.languagetool.JLanguageTool.addRule()


  private JLanguageTool getLanguageToolWithOneRule(Language lang, PatternRule patternRule) throws IOException {
    final JLanguageTool langTool = new JLanguageTool(lang);
    for (Rule rule : langTool.getAllActiveRules()) {
      langTool.disableRule(rule.getId());
    }
    langTool.addRule(patternRule);
    return langTool;
  }

  class PossiblyLimitedTopDocs {
    TopDocs topDocs;
View Full Code Here


    String output = new String(this.out.toByteArray());
    assertEquals(0, output.indexOf("Time:"));
    assertEquals(0, matches);

    tool.disableRule("test_unification_with_negation");
    tool.addRule(new WordRepeatRule(TestTools.getEnglishMessages(), Language.DEMO));
    matches = Tools.checkText("To jest problem problem.", tool);
    output = new String(this.out.toByteArray());
    assertTrue(output.contains("Rule ID: WORD_REPEAT_RULE"));
    assertEquals(1, matches);
  }
View Full Code Here

  @Test
  public void testMatch() throws Exception {
    SentenceWhitespaceRule rule = new SentenceWhitespaceRule(TestTools.getEnglishMessages());
    JLanguageTool languageTool = new JLanguageTool(TestTools.getDemoLanguage());
    languageTool.addRule(rule);

    assertGood("This is a text. And there's the next sentence.", rule, languageTool);
    assertGood("This is a text! And there's the next sentence.", rule, languageTool);
    assertGood("This is a text\nAnd there's the next sentence.", rule, languageTool);
    assertGood("This is a text\n\nAnd there's the next sentence.", rule, languageTool);
View Full Code Here

  }

  public void testIgnoreSuggestionsWithDynamicHunspellRule() throws IOException {
    final JLanguageTool langTool = new JLanguageTool(new GermanyGerman());
    final SpellingCheckRule rule = new HunspellNoSuggestionRule(TestTools.getEnglishMessages(), new GermanyGerman());
    langTool.addRule(rule);
    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());
View Full Code Here

    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

    langTool.disableRule("TEST_ID");
    final List<RuleMatch> matches3 = langTool.check("Das ist ein Tibbfehla.");
View Full Code Here

  @Test
  public void testMatch() throws Exception {
    SentenceWhitespaceRule rule = new SentenceWhitespaceRule(TestTools.getEnglishMessages());
    JLanguageTool languageTool = new JLanguageTool(new German());
    languageTool.addRule(rule);

    assertGood("Das ist ein Satz. Und hier der nächste.", rule, languageTool);
    assertGood("Das ist ein Satz! Und hier der nächste.", rule, languageTool);
    assertGood("Ist das ein Satz? Hier der nächste.", rule, languageTool);
View Full Code Here

    String output = new String(this.out.toByteArray());
    assertEquals(0, output.indexOf("Time:"));
    assertEquals(0, matches);

    tool.disableRule("test_unification_with_negation");
    tool.addRule(new WordRepeatRule(getMessages("en"), TestTools.getDemoLanguage()));
    matches = CommandLineTools.checkText("To jest problem problem.", tool);
    output = new String(this.out.toByteArray());
    assertTrue(output.contains("Rule ID: WORD_REPEAT_RULE"));
    assertEquals(1, matches);
  }
View Full Code Here

  private JLanguageTool getLanguageToolWithOneRule(Language lang, PatternRule patternRule) {
    final JLanguageTool langTool = new JLanguageTool(lang);
    for (Rule rule : langTool.getAllActiveRules()) {
      langTool.disableRule(rule.getId());
    }
    langTool.addRule(patternRule);
    langTool.enableDefaultOffRule(patternRule.getId()); // rule might be off by default
    return langTool;
  }

  class PossiblyLimitedTopDocs {
View Full Code Here

  }

  public void testIgnoreSuggestionsWithDynamicMorfologikRule() throws IOException {
    final JLanguageTool langTool = new JLanguageTool(new AmericanEnglish());
    final SpellingCheckRule rule = new MorfologikAmericanSpellerRule(TestTools.getEnglishMessages(), new AmericanEnglish());
    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(),
View Full Code Here

    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

    langTool.disableRule("TEST_ID");
    final List<RuleMatch> matches3 = langTool.check("This is a typoh.");
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.