Examples of JLanguageTool


Examples of org.languagetool.JLanguageTool

 
  public void testRule() throws IOException {
    final DifferentLengthRule rule = new DifferentLengthRule();
      //(TestTools.getEnglishMessages(), Language.ENGLISH);
    RuleMatch[] matches;
    final JLanguageTool trgLangTool = new JLanguageTool(Language.DEMO);
    final JLanguageTool srcLangTool = new JLanguageTool(new FakeLanguage());
    rule.setSourceLang(Language.DEMO);
    // correct sentences:
    matches = rule.match(
        srcLangTool.getAnalyzedSentence("This is a test sentence."),
        trgLangTool.getAnalyzedSentence("To zdanie testowe."));
    assertEquals(0, matches.length);
   
    matches = rule.match(
        srcLangTool.getAnalyzedSentence("Click this button."),
        trgLangTool.getAnalyzedSentence("Kliknij ten przycisk."));
    assertEquals(0, matches.length);
   
    // incorrect sentences:
    matches = rule.match(
        srcLangTool.getAnalyzedSentence("Open a file, and check if it is corrupt."),
        trgLangTool.getAnalyzedSentence("Otwórz plik."));
    assertEquals(1, matches.length);
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

public class UppercaseSentenceStartRuleTest extends TestCase {

  public void testRule() throws IOException {
    final UppercaseSentenceStartRule rule = new UppercaseSentenceStartRule(TestTools.getEnglishMessages(), Language.DEMO);
    RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(Language.DEMO);

    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("a) This is a test sentence."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("iv. This is a test sentence..."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("\"iv. This is a test sentence...\""));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("This"));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("This is"));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("This is a test sentence"));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence(""));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("http://www.languagetool.org"));
    assertEquals(0, matches.length);
  
   
    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("this is a test sentence."));
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(4, matches[0].getToPos());
    matches = rule.match(langTool.getAnalyzedSentence("this"));
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(4, matches[0].getToPos());
    //matches = rule.match(langTool.getAnalyzedSentence("'a"));
    //assertEquals(1, matches.length);
View Full Code Here

Examples of org.languagetool.JLanguageTool

 
  public void testRule() throws IOException {
    final SameTranslationRule rule = new SameTranslationRule();
      //(TestTools.getEnglishMessages(), Language.ENGLISH);
    RuleMatch[] matches;
    final JLanguageTool srcLangTool = new JLanguageTool(Language.DEMO);
    final JLanguageTool trgLangTool = new JLanguageTool(new FakeLanguage());
    rule.setSourceLang(Language.DEMO);
    // correct sentences:
    matches = rule.match(
        srcLangTool.getAnalyzedSentence("This is a test sentence."),
        trgLangTool.getAnalyzedSentence("C'est la vie !"));
    assertEquals(0, matches.length);
   
    //tricky: proper names should be left as is!
    matches = rule.match(
        srcLangTool.getAnalyzedSentence("Elvis Presley"),
        trgLangTool.getAnalyzedSentence("Elvis Presley"));
    assertEquals(0, matches.length);
   
    // incorrect sentences:
    matches = rule.match(
        srcLangTool.getAnalyzedSentence("This this is a test sentence."),
        trgLangTool.getAnalyzedSentence("This this is a test sentence."));
    assertEquals(1, matches.length);
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

  }

  private void initLanguageTool() {
    try {
      prepareConfig(docLanguage);
      langTool = new JLanguageTool(docLanguage, config.getMotherTongue());
      langTool.activateDefaultPatternRules();
      langTool.activateDefaultFalseFriendRules();
      for (Rule rule : langTool.getAllActiveRules()) {
        if (rule.isSpellingRule()) {
          langTool.disableRule(rule.getId());
View Full Code Here

Examples of org.languagetool.JLanguageTool

      } catch (RuntimeException ignored) {
        // thrown if there is no bitext.xml file
        continue;
      }
      System.out.println("Running tests for " + lang.getName() + "...");
      final JLanguageTool languageTool = new JLanguageTool(lang);
      final List<BitextPatternRule> rules = ruleLoader.getRules(is, name);
      testBitextRulesFromXML(rules, languageTool, lang);
    }
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

    }
  }

  private void testBitextRule(final BitextPatternRule rule, final Language lang,
                              final JLanguageTool languageTool) throws IOException {
    final JLanguageTool srcTool = new JLanguageTool(rule.getSourceLang());
    final List<StringPair> goodSentences = rule.getCorrectBitextExamples();
    for (StringPair goodSentence : goodSentences) {
      assertTrue(cleanSentence(goodSentence.getSource()).trim().length() > 0);
      assertTrue(cleanSentence(goodSentence.getTarget()).trim().length() > 0);
      assertFalse(lang + ": Did not expect error in: " + goodSentence
View Full Code Here

Examples of org.languagetool.JLanguageTool

  private JLanguageTool langTool;
 
  @Override
  public void setUp() throws IOException {
    rule = new CommaWhitespaceRule(TestTools.getEnglishMessages());
    langTool = new JLanguageTool(Language.DEMO);
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

public class WhitespaceRuleTest extends TestCase {

  public void testRule() throws IOException {
    final WhitespaceRule rule = new WhitespaceRule(TestTools.getEnglishMessages(), Language.DEMO);
    RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(Language.DEMO);

    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("This is a test sentence."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("This is a test sentence..."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("\n\tThis is a test sentence..."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Multiple tabs\t\tare okay"));
    assertEquals(0, matches.length);

    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("This  is a test sentence."));
    assertEquals(1, matches.length);
    assertEquals(4, matches[0].getFromPos());
    assertEquals(6, matches[0].getToPos());
   
    matches = rule.match(langTool.getAnalyzedSentence("This is a test   sentence."));
    assertEquals(1, matches.length);
    assertEquals(14, matches[0].getFromPos());
    assertEquals(17, matches[0].getToPos());
    matches = rule.match(langTool.getAnalyzedSentence("This is   a  test   sentence."));
    assertEquals(3, matches.length);
    assertEquals(7, matches[0].getFromPos());
    assertEquals(10, matches[0].getToPos());
    assertEquals(11, matches[1].getFromPos());
    assertEquals(13, matches[1].getToPos());
    assertEquals(17, matches[2].getFromPos());
    assertEquals(20, matches[2].getToPos());
    matches = rule.match(langTool.getAnalyzedSentence("\t\t\t    \t\t\t\t  "));
    assertEquals(1, matches.length);
    //with non-breakable spaces
    matches = rule.match(langTool.getAnalyzedSentence("This \u00A0is a test sentence."));
    assertEquals(1, matches.length);
    assertEquals(4, matches[0].getFromPos());
    assertEquals(6, matches[0].getToPos());   
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

public class DoublePunctuationRuleTest extends TestCase {

  public void testRule() throws IOException {
    final DoublePunctuationRule rule = new DoublePunctuationRule(TestTools.getEnglishMessages());
    RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(Language.DEMO);
   
    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("This is a test sentence..."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("This is a test sentence... More stuff...."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("This is a test sentence..... More stuff...."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("This, is, a test sentence."));
    assertEquals(0, matches.length);

    // errors:
    matches = rule.match(langTool.getAnalyzedSentence("This,, is a test sentence."));
    assertEquals(1, matches.length);
    assertEquals(4, matches[0].getFromPos());
    assertEquals(6, matches[0].getToPos());
    matches = rule.match(langTool.getAnalyzedSentence("This is a test sentence.. Another sentence"));
    assertEquals(1, matches.length);
    assertEquals(23, matches[0].getFromPos());
    assertEquals(25, matches[0].getToPos());
  }
View Full Code Here

Examples of org.languagetool.JLanguageTool

    System.setOut(this.stdout);
    System.setErr(this.stderr);
  }

  public void testCheck() throws IOException, ParserConfigurationException, SAXException {
    final JLanguageTool tool = new JLanguageTool(Language.DEMO);
    tool.activateDefaultPatternRules();
    tool.activateDefaultFalseFriendRules();
    int matches = Tools.checkText("Foo.", tool);
    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
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.