<commit_before>/* LanguageTool, a natural language style checker 
 * Copyright (C) 2012 <NAME> (http://www.languagetool.org)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

package org.languagetool.rules;

import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Test;
import org.languagetool.JLanguageTool;
import org.languagetool.Language;
import org.languagetool.TestTools;

import org.languagetool.rules.spelling.hunspell.*;

public class HunspellRuleTest {

  @Test
  public void testRule() throws UnsatisfiedLinkError, UnsupportedOperationException, IOException {

    HunspellRule rule =
            new HunspellRule(TestTools.getMessages("Polish"), Language.POLISH);

    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(Language.POLISH);


    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("To jest test bez jakiegokolwiek błędu.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Żółw na starość wydziela dziwną woń.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).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("Żółw", matches[0].getSuggestedReplacements().get(0));

    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);

    // Catalan
    HunspellRule catRule =
    		new HunspellRule(TestTools.getMessages("Catalan"), Language.CATALAN);
    JLanguageTool catTool = new JLanguageTool(Language.CATALAN);

    // correct sentences:
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence("Allò que més l'interessa.")).length);
    // checks that "WORDCHARS ·-'" is added to Hunspell .aff file
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence("Porta'n quatre al col·legi.")).length);
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence("Has de portar-me'n moltes.")).length);
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence(",")).length);

    //incorrect sentences:
    matches = catRule.match(catTool.getAnalyzedSentence("Pecra"));
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(5, matches[0].getToPos());
    assertEquals("Pera", matches[0].getSuggestedReplacements().get(0));
  }

  @Test
  public void testRuleWithGerman() throws UnsatisfiedLinkError, UnsupportedOperationException, IOException {
    final HunspellRule rule = new HunspellRule(TestTools.getMessages("German"), Language.GERMANY_GERMAN);
    final JLanguageTool langTool = new JLanguageTool(Language.GERMAN);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentestversuch")).length);  // compound
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der äußere Übeltäter.")).length);  // umlauts
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der äussere Übeltäter.")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentestversuch orkt")).length);
  }

  @Test
  public void testRuleWithSwissGerman() throws UnsatisfiedLinkError, UnsupportedOperationException, IOException {
    final HunspellRule rule = new HunspellRule(TestTools.getMessages("German"), Language.SWISS_GERMAN);
    final JLanguageTool langTool = new JLanguageTool(Language.GERMAN);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentestversuch")).length);  // compound
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der äußere Übeltäter.")).length);  // ß not allowed in Swiss
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der äussere Übeltäter.")).length);  // ss is used instead of ß
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentestversuch orkt")).length);
  }

}<commit_msg>[de] adding more tests for spell checker<commit_after>/* LanguageTool, a natural language style checker 
 * Copyright (C) 2012 <NAME> (http://www.languagetool.org)
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
 * USA
 */

package org.languagetool.rules;

import static org.junit.Assert.*;

import java.io.IOException;

import org.junit.Test;
import org.languagetool.JLanguageTool;
import org.languagetool.Language;
import org.languagetool.TestTools;

import org.languagetool.rules.spelling.hunspell.*;

public class HunspellRuleTest {

  @Test
  public void testRule() throws Exception {

    HunspellRule rule =
            new HunspellRule(TestTools.getMessages("Polish"), Language.POLISH);

    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(Language.POLISH);


    // correct sentences:
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("To jest test bez jakiegokolwiek błędu.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Żółw na starość wydziela dziwną woń.")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).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("Żółw", matches[0].getSuggestedReplacements().get(0));

    assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);

    // Catalan
    HunspellRule catRule =
    		new HunspellRule(TestTools.getMessages("Catalan"), Language.CATALAN);
    JLanguageTool catTool = new JLanguageTool(Language.CATALAN);

    // correct sentences:
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence("Allò que més l'interessa.")).length);
    // checks that "WORDCHARS ·-'" is added to Hunspell .aff file
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence("Porta'n quatre al col·legi.")).length);
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence("Has de portar-me'n moltes.")).length);
    assertEquals(0, catRule.match(catTool.getAnalyzedSentence(",")).length);

    //incorrect sentences:
    matches = catRule.match(catTool.getAnalyzedSentence("Pecra"));
    // check match positions:
    assertEquals(1, matches.length);
    assertEquals(0, matches[0].getFromPos());
    assertEquals(5, matches[0].getToPos());
    assertEquals("Pera", matches[0].getSuggestedReplacements().get(0));
  }

  @Test
  public void testRuleWithGerman() throws Exception {
    final HunspellRule rule = new HunspellRule(TestTools.getMessages("German"), Language.GERMANY_GERMAN);
    final JLanguageTool langTool = new JLanguageTool(Language.GERMAN);
    commonGermanAsserts(rule, langTool);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der äußere Übeltäter.")).length);  // umlauts
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der äussere Übeltäter.")).length);
  }

  @Test
  public void testRuleWithAustrianGerman() throws Exception {
    final HunspellRule rule = new HunspellRule(TestTools.getMessages("German"), Language.AUSTRIAN_GERMAN);
    final JLanguageTool langTool = new JLanguageTool(Language.GERMAN);
    commonGermanAsserts(rule, langTool);
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der äußere Übeltäter.")).length);  // umlauts
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der äussere Übeltäter.")).length);
  }

  @Test
  public void testRuleWithSwissGerman() throws Exception {
    final HunspellRule rule = new HunspellRule(TestTools.getMessages("German"), Language.SWISS_GERMAN);
    final JLanguageTool langTool = new JLanguageTool(Language.GERMAN);
    commonGermanAsserts(rule, langTool);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der äußere Übeltäter.")).length);  // ß not allowed in Swiss
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der äussere Übeltäter.")).length);  // ss is used instead of ß
  }

  private void commonGermanAsserts(HunspellRule rule, JLanguageTool langTool) throws IOException {
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentestversuch")).length);  // compound
    assertEquals(0, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentest-Versuch")).length);  // compound

    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentest-Dftgedgs")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der Dftgedgs-Waschmaschinentest")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentestdftgedgs")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der Waschmaschinentestversuch orkt")).length);
    assertEquals(1, rule.match(langTool.getAnalyzedSentence("Der Arbeitsnehmer")).length);  // wrong infix
    assertEquals(2, rule.match(langTool.getAnalyzedSentence("Der asdegfue orkt")).length);
  }

}
{'fraction_non_alphanumeric': 0.11499382774665275, 'fraction_numerical': 0.009685689868008737, 'mean_word_length': 5.073817762399077, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7251806', 'n_tokens_mistral': 3218, 'n_tokens_neox': 3182, 'n_words': 734}