Search in sources :

Example 6 with Polish

use of org.languagetool.language.Polish in project languagetool by languagetool-org.

the class PolishWordRepeatRuleTest method testRule.

@Test
public void testRule() throws IOException {
    final PolishWordRepeatRule rule = new PolishWordRepeatRule(TestTools.getEnglishMessages());
    RuleMatch[] matches;
    JLanguageTool langTool = new JLanguageTool(new Polish());
    //correct
    matches = rule.match(langTool.getAnalyzedSentence("To jest zdanie próbne."));
    assertEquals(0, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("On tak się bardzo nie martwił, bo przecież musiał się umyć."));
    assertEquals(0, matches.length);
    //repeated prepositions, don't count'em
    matches = rule.match(langTool.getAnalyzedSentence("Na dyskotece tańczył jeszcze, choć był na bani."));
    assertEquals(0, matches.length);
    // sf bug report:
    matches = rule.match(langTool.getAnalyzedSentence("Żadnych „ale”."));
    assertEquals(0, matches.length);
    //incorrect
    matches = rule.match(langTool.getAnalyzedSentence("Był on bowiem pięknym strzelcem bowiem."));
    assertEquals(1, matches.length);
    matches = rule.match(langTool.getAnalyzedSentence("Mówiła długo, żeby tylko mówić długo."));
    assertEquals(2, matches.length);
}
Also used : RuleMatch(org.languagetool.rules.RuleMatch) Polish(org.languagetool.language.Polish) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 7 with Polish

use of org.languagetool.language.Polish in project languagetool by languagetool-org.

the class SimpleReplaceRuleTest method setUp.

@Before
public void setUp() throws Exception {
    rule = new SimpleReplaceRule(TestTools.getMessages("pl"));
    langTool = new JLanguageTool(new Polish());
}
Also used : Polish(org.languagetool.language.Polish) JLanguageTool(org.languagetool.JLanguageTool) Before(org.junit.Before)

Example 8 with Polish

use of org.languagetool.language.Polish in project languagetool by languagetool-org.

the class ToolsTest method testCorrect.

@Test
public void testCorrect() throws IOException, ParserConfigurationException, SAXException {
    JLanguageTool tool = new JLanguageTool(new Polish());
    tool.setCleanOverlappingMatches(false);
    String correct = Tools.correctText("To jest całkowicie prawidłowe zdanie.", tool);
    assertEquals("To jest całkowicie prawidłowe zdanie.", correct);
    correct = Tools.correctText("To jest jest problem.", tool);
    assertEquals("To jest problem.", correct);
    // more sentences, need to apply more suggestions > 1 in subsequent sentences
    correct = Tools.correctText("To jest jest problem. Ale to już już nie jest problem.", tool);
    assertEquals("To jest problem. Ale to już nie jest problem.", correct);
    correct = Tools.correctText("To jest jest problem. Ale to już już nie jest problem. Tak sie nie robi. W tym zdaniu brakuje przecinka bo go zapomniałem.", tool);
    assertEquals("To jest problem. Ale to już nie jest problem. Tak się nie robi. W tym zdaniu brakuje przecinka, bo go zapomniałem.", correct);
}
Also used : Polish(org.languagetool.language.Polish) JLanguageTool(org.languagetool.JLanguageTool) Test(org.junit.Test)

Example 9 with Polish

use of org.languagetool.language.Polish in project languagetool by languagetool-org.

the class FalseFriendsAsBitextLoaderTest method testHintsForPolishTranslators.

@Test
public void testHintsForPolishTranslators() throws IOException, ParserConfigurationException, SAXException {
    Polish polish = new Polish();
    English english = new English();
    JLanguageTool langTool = new JLanguageTool(english, polish);
    JLanguageTool trgTool = new JLanguageTool(polish);
    FalseFriendsAsBitextLoader ruleLoader = new FalseFriendsAsBitextLoader();
    String name = "/false-friends.xml";
    List<BitextPatternRule> rules = ruleLoader.getFalseFriendsAsBitext(name, english, polish);
    assertErrors(1, rules, "This is an absurd.", "To absurd.", langTool, trgTool);
    assertErrors(1, rules, "I have to speak to my advocate.", "Muszę porozmawiać z adwokatem.", langTool, trgTool);
    assertErrors(1, rules, "This is not actual.", "To nie jest aktualne.", langTool, trgTool);
    assertErrors(0, rules, "This is not actual.", "To nie jest rzeczywiste.", langTool, trgTool);
}
Also used : English(org.languagetool.language.English) Polish(org.languagetool.language.Polish) JLanguageTool(org.languagetool.JLanguageTool) BitextPatternRule(org.languagetool.rules.patterns.bitext.BitextPatternRule) FalseFriendsAsBitextLoader(org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader) Test(org.junit.Test)

Example 10 with Polish

use of org.languagetool.language.Polish in project languagetool by languagetool-org.

the class MatchTest method testSpeller.

@Test
public void testSpeller() throws Exception {
    //tests with synthesizer
    Match match = getMatch("POS1", "POS2", true);
    final Polish polish = new Polish();
    MatchState matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    //getting empty strings, which is what we want
    assertEquals("[]", Arrays.toString(matchState.toFinalString(polish)));
    // contrast with a speller = false!
    match = getMatch("POS1", "POS2", false);
    matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("inflectedform11", "POS1", "Lemma1"));
    assertEquals("[(inflectedform11)]", Arrays.toString(matchState.toFinalString(polish)));
    //and now a real word - we should get something
    match = getMatch("subst:sg:acc.nom:m3", "subst:sg:gen:m3", true);
    matchState = new MatchState(match, polish.getSynthesizer());
    matchState.setToken(getAnalyzedTokenReadings("AON", "subst:sg:acc.nom:m3", "AON"));
    assertEquals("[AON-u]", Arrays.toString(matchState.toFinalString(polish)));
    //and now pure text changes        
    match = getTextMatch("^(.*)$", "$0-u", true);
    match.setLemmaString("AON");
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[AON-u]", Arrays.toString(matchState.toFinalString(polish)));
    match.setLemmaString("batalion");
    //should be empty
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[]", Arrays.toString(matchState.toFinalString(polish)));
    match.setLemmaString("ASEAN");
    //and this one not
    matchState = new MatchState(match, polish.getSynthesizer());
    assertEquals("[ASEAN-u]", Arrays.toString(matchState.toFinalString(polish)));
}
Also used : Polish(org.languagetool.language.Polish) MatchState(org.languagetool.rules.patterns.MatchState) Match(org.languagetool.rules.patterns.Match) Test(org.junit.Test)

Aggregations

Polish (org.languagetool.language.Polish)17 Test (org.junit.Test)13 JLanguageTool (org.languagetool.JLanguageTool)12 RuleMatch (org.languagetool.rules.RuleMatch)6 Before (org.junit.Before)4 InputStream (java.io.InputStream)1 Scanner (java.util.Scanner)1 Language (org.languagetool.Language)1 English (org.languagetool.language.English)1 AbstractCompoundRuleTest (org.languagetool.rules.AbstractCompoundRuleTest)1 MultipleWhitespaceRule (org.languagetool.rules.MultipleWhitespaceRule)1 WordRepeatRule (org.languagetool.rules.WordRepeatRule)1 AbstractPatternRule (org.languagetool.rules.patterns.AbstractPatternRule)1 Match (org.languagetool.rules.patterns.Match)1 MatchState (org.languagetool.rules.patterns.MatchState)1 BitextPatternRule (org.languagetool.rules.patterns.bitext.BitextPatternRule)1 FalseFriendsAsBitextLoader (org.languagetool.rules.patterns.bitext.FalseFriendsAsBitextLoader)1 PolishTagger (org.languagetool.tagging.pl.PolishTagger)1 SRXSentenceTokenizer (org.languagetool.tokenizers.SRXSentenceTokenizer)1 WordTokenizer (org.languagetool.tokenizers.WordTokenizer)1