Package org.languagetool

Examples of org.languagetool.JLanguageTool


  private JLanguageTool langTool;

  @Override
  public void setUp() throws IOException {
    rule = new ComplexAdjectiveConcordanceRule(null);
    langTool = new JLanguageTool(new Catalan());
  }
View Full Code Here


  public void testMorfologikSpeller() throws IOException {
    final AustralianEnglish language = new AustralianEnglish();
    final MorfologikAustralianSpellerRule rule =
            new MorfologikAustralianSpellerRule (TestTools.getMessages("English"), language);

    final JLanguageTool langTool = new JLanguageTool(language);

    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("This is an example: we get behaviour as a dictionary word.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Why don't we speak today.")).length);
    //with doesn't
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("He doesn't know what to do.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);

    //Australian dict:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Agnathia")).length);

    //incorrect sentences:

    final RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("behavior"));
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(8, matches[0].getToPos());
    assertEquals("behaviour", matches[0].getSuggestedReplacements().get(0));

    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);
  }
View Full Code Here

public class CompoundRuleTest extends CompoundRuleTestAbs {

  @Override
  protected void setUp() throws Exception {
    super.setUp();
    langTool = new JLanguageTool(new English());
    rule = new CompoundRule(null);
  }
View Full Code Here

    final Malayalam language = new Malayalam();
    final MorfologikMalayalamSpellerRule rule =
            new MorfologikMalayalamSpellerRule (TestTools.getMessages("Malayalam"), language);

    RuleMatch[] matches;
    final JLanguageTool langTool = new JLanguageTool(language);

    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("എന്തുകൊണ്ട്‌ അംഗത്വം")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("എങ്ങനെ അംഗമാകാം?")).length);
    //test for "LanguageTool":
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("LanguageTool")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);

    //incorrect sentences:

    matches = rule.match(langTool.getAnalyzedSentence("Zolw"));
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(4, matches[0].getToPos());
    assertEquals(matches[0].getSuggestedReplacements().isEmpty(), true);

    matches = rule.match(langTool.getAnalyzedSentence("എaങ്ങനെ"));
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(7, matches[0].getToPos());
    assertEquals(matches[0].getSuggestedReplacements().get(0), "എങ്ങനെ");

    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("a")).length);
  }
View Full Code Here

    new Thread() {
      @Override
      public void run() {
        setWaitCursor();
        try {
          final JLanguageTool langTool = getCurrentLanguageTool(getCurrentLanguage());
          tagTextAndDisplayResults(langTool);
        } finally {
          unsetWaitCursor();
        }
      }
View Full Code Here

  public void testJavaRuleIds() throws IOException {
    final Set<String> ids = new HashSet<>();
    final Set<Class> ruleClasses = new HashSet<>();
    for (Language language : Language.LANGUAGES) {
      final JLanguageTool lt = new JLanguageTool(language);
      final List<Rule> allRules = lt.getAllRules();
      for (Rule rule : allRules) {
        assertIdUniqueness(ids, ruleClasses, language, rule);
        assertIdValidity(language, rule);
        if (rule instanceof PatternRule) {
          // doesn't make sense, but that's the way it works for PatternRules
View Full Code Here

    if (langTool == null) {
      try {
        config = new Configuration(new File(System.getProperty("user.home")), CONFIG_FILE, currentLanguage);
        resultArea.setConfiguration(config);
        final ConfigurationDialog configDialog = getCurrentConfigDialog(currentLanguage);
        langTool = new JLanguageTool(currentLanguage, configDialog.getMotherTongue());
        langTool.activateDefaultPatternRules();
        langTool.activateDefaultFalseFriendRules();
        resultArea.setLanguageTool(langTool);
        final Set<String> disabledRules = configDialog.getDisabledRuleIds();
        if (disabledRules != null) {
View Full Code Here

                          final String startCheckText = HTML_GREY_FONT_START +
                                  Tools.makeTexti18n(messages, "startChecking", langName) + "..." + HTML_FONT_END;
                          resultArea.setText(startCheckText);
                          resultArea.repaint();
                          try {
                            final JLanguageTool langTool = getCurrentLanguageTool(lang);
                            ruleMatches = ltSupport._check();
                            resultArea.setStartText(startCheckText);
                            resultArea.setInputText(textArea.getText());
                            resultArea.setRuleMatches(ruleMatches);
                            resultArea.setRunTime(System.currentTimeMillis() - startTime);
View Full Code Here

  @Test
  public void testRule() throws IOException {
    final MixedAlphabetsRule rule = new MixedAlphabetsRule(TestTools.getMessages("Ukrainian"));

    final JLanguageTool langTool = new JLanguageTool(new Ukrainian());

    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("сміття")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("not mixed")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("123454")).length);

    //incorrect sentences:

    RuleMatch[] matches = rule.match(langTool.getAnalyzedSentence("смiття"));   //latin i
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("сміття"), matches[0].getSuggestedReplacements());

    matches = rule.match(langTool.getAnalyzedSentence("mіхed"))// cyrillic i and x

    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("mixed"), matches[0].getSuggestedReplacements());
   
    matches = rule.match(langTool.getAnalyzedSentence("XІ"))// cyrillic І and latin X

    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("XI"), matches[0].getSuggestedReplacements());

    matches = rule.match(langTool.getAnalyzedSentence("ХI"))// cyrillic X and latin I

    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("XI"), matches[0].getSuggestedReplacements());

    matches = rule.match(langTool.getAnalyzedSentence("ХІ"))// cyrillic both X and I used for latin number

    assertEquals(1, matches.length);
    assertEquals(Arrays.asList("XI"), matches[0].getSuggestedReplacements());

  }
View Full Code Here

  public void testRule() throws IOException {
    PunctuationCheckRule rule = new PunctuationCheckRule(TestTools.getEnglishMessages());

    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(new Ukrainian());
   
    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Дві, коми. Ось: дві!!!"));
    assertEquals(0, matches.length);

    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("- Це ваша пряма мова?!!"));
    assertEquals(0, matches.length);

    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Дві,- коми!.."));
    assertEquals(0, matches.length);

    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Таке питання?.."));
    assertEquals(0, matches.length);

    // correct sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Два  пробіли."))// поки що ігноруємо - не царська це справа :)
    assertEquals(0, matches.length);

    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Дві крапки.."));
    assertEquals(1, matches.length);
    assertEquals(1, matches[0].getSuggestedReplacements().size());
    assertEquals(".", matches[0].getSuggestedReplacements().get(0));

    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Дві,, коми."));
    assertEquals(1, matches.length);

    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Не там ,кома."));
    assertEquals(1, matches.length);

    // incorrect sentences:
    matches = rule.match(langTool.getAnalyzedSentence("Двокрапка:- з тире."));
    assertEquals(1, matches.length);
  }
View Full Code Here

TOP

Related Classes of org.languagetool.JLanguageTool

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.