public void testMorfologikSpeller() throws IOException {
MorfologikCatalanSpellerRule rule =
new MorfologikCatalanSpellerRule (TestTools.getMessages("Catalan"), new Catalan());
RuleMatch[] matches;
JLanguageTool langTool = new JLanguageTool(new Catalan());
// prefixes and suffixes.
assertEquals(0, rule.match(langTool.getAnalyzedSentence("S'autodefineixin com a populars.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Redibuixen el futur.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("L'exdirigent del partit.")).length);
// correct sentences:
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Abacallanada")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Abatre-les-en")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Allò que més l'interessa.")).length);
// checks that "WORDCHARS ·-'" is added to Hunspell .aff file
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Porta'n quatre al col·legi.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Has de portar-me'n moltes.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence(",")).length);
// Spellcheck dictionary contains Valencian and general accentuation
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Francès i francés.")).length);
// checks abbreviations
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Viu al núm. 23 del carrer Nou.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("N'hi ha de color vermell, blau, verd, etc.")).length);
// Test for Multiwords.
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Era vox populi.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Aquell era l'statu quo.")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("Va ser la XIV edició.")).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);
//tests for mixed case words
assertEquals(0, rule.match(langTool.getAnalyzedSentence("pH")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("McDonald")).length);
//incorrect sentences:
//TODO: quna --> quan ?, uan --> una, Qie-Què, línees->línies
matches = rule.match(langTool.getAnalyzedSentence("quna"));
assertEquals(1, matches.length);
//assertEquals("quan", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("Video"));
assertEquals(1, matches.length);
assertEquals("vídeo", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("bànner"));
assertEquals(1, matches.length);
assertEquals("bàner", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("colaborassió"));
assertEquals(1, matches.length);
assertEquals("col·laboració", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("sssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss"));
assertEquals(1, matches.length);
matches = rule.match(langTool.getAnalyzedSentence("plassa"));
assertEquals(1, matches.length);
assertEquals("plaça", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("Deú"));
assertEquals(1, matches.length);
assertEquals("Deu", matches[0].getSuggestedReplacements().get(0));
assertEquals("Déu", matches[0].getSuggestedReplacements().get(1));
matches = rule.match(langTool.getAnalyzedSentence("joan"));
assertEquals(1, matches.length);
assertEquals(0, matches[0].getFromPos());
assertEquals(4, matches[0].getToPos());
assertEquals("Joan", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("abatusats"));
assertEquals(1, matches.length);
assertEquals(0, matches[0].getFromPos());
assertEquals(9, matches[0].getToPos());
assertEquals("abatussats", matches[0].getSuggestedReplacements().get(0));
// incomplete multiword
matches = rule.match(langTool.getAnalyzedSentence("L'statu"));
assertEquals(1, matches.length);
assertEquals(2, matches[0].getFromPos());
assertEquals(7, matches[0].getToPos());
assertEquals("tato", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("argüit"));
assertEquals(1, matches.length);
assertEquals(0, matches[0].getFromPos());
assertEquals(6, matches[0].getToPos());
assertEquals("arguït", matches[0].getSuggestedReplacements().get(0));
assertEquals("arguïa", matches[0].getSuggestedReplacements().get(1));
assertEquals("arguïm", matches[0].getSuggestedReplacements().get(2));
matches = rule.match(langTool.getAnalyzedSentence("ángel"));
assertEquals(1, matches.length);
assertEquals("Àngel", matches[0].getSuggestedReplacements().get(0));
assertEquals("àngel", matches[0].getSuggestedReplacements().get(1));
matches = rule.match(langTool.getAnalyzedSentence("caçessim"));
assertEquals(1, matches.length);
assertEquals("cacéssim", matches[0].getSuggestedReplacements().get(0));
assertEquals("caséssim", matches[0].getSuggestedReplacements().get(1));
assertEquals("casséssim", matches[0].getSuggestedReplacements().get(2));
assertEquals("cesséssim", matches[0].getSuggestedReplacements().get(3));
matches = rule.match(langTool.getAnalyzedSentence("cantaríà"));
assertEquals(1, matches.length);
assertEquals("cantaria", matches[0].getSuggestedReplacements().get(0));
assertEquals("Cantàbria", matches[0].getSuggestedReplacements().get(1));
//best suggestion first
matches = rule.match(langTool.getAnalyzedSentence("poguem"));
assertEquals(1, matches.length);
assertEquals("puguem", matches[0].getSuggestedReplacements().get(0));
//incorrect mixed case words
assertEquals(1, rule.match(langTool.getAnalyzedSentence("PH")).length);
assertEquals(1, rule.match(langTool.getAnalyzedSentence("Ph")).length);
assertEquals(1, rule.match(langTool.getAnalyzedSentence("MCDonald")).length);
matches = rule.match(langTool.getAnalyzedSentence("tAula"));
assertEquals(1, matches.length);
assertEquals("taula", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("TAula"));
assertEquals(1, matches.length);
assertEquals("taula", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("col·Labora"));
assertEquals(1, matches.length);
assertEquals("col·labora", matches[0].getSuggestedReplacements().get(0));
matches = rule.match(langTool.getAnalyzedSentence("col·laborÀ"));
assertEquals(1, matches.length);
assertEquals("col·laborà", matches[0].getSuggestedReplacements().get(0));
//capitalized wrong words
matches = rule.match(langTool.getAnalyzedSentence("En la Pecra"));
assertEquals(1, matches.length);
assertEquals("Macra", matches[0].getSuggestedReplacements().get(0));
assertEquals("Pacià", matches[0].getSuggestedReplacements().get(1));
assertEquals(1, rule.match(langTool.getAnalyzedSentence("aõh")).length);
assertEquals(0, rule.match(langTool.getAnalyzedSentence("a")).length);
}