From 1b0f6b031b39f083bf2365f7e6fbbe65b3d8e78d Mon Sep 17 00:00:00 2001 From: p-goulart Date: Fri, 27 Oct 2023 15:04:52 +0200 Subject: [PATCH] [pt] Make AO and MZ variants use PT dict --- .../pt/MorfologikPortugueseSpellerRule.java | 7 ++++- .../MorfologikPortugueseSpellerRuleTest.java | 30 +++++++++++++++++-- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRule.java b/languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRule.java index 5ce0ad9a792d..2338a58d6c4a 100644 --- a/languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRule.java +++ b/languagetool-language-modules/pt/src/main/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRule.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.util.List; +import java.util.Objects; import java.util.ResourceBundle; public class MorfologikPortugueseSpellerRule extends MorfologikSpellerRule { @@ -34,6 +35,10 @@ public MorfologikPortugueseSpellerRule(ResourceBundle messages, Language languag language = language.getDefaultLanguageVariant(); } this.language = language; - this.dictFilename = "/pt/spelling/" + language.getShortCodeWithCountryAndVariant() + JLanguageTool.DICTIONARY_FILENAME_EXTENSION; + if (Objects.equals(language.getShortCodeWithCountryAndVariant(), "pt-BR")) { + this.dictFilename = "/pt/spelling/pt-BR" + JLanguageTool.DICTIONARY_FILENAME_EXTENSION; + } else { + this.dictFilename = "/pt/spelling/pt-PT" + JLanguageTool.DICTIONARY_FILENAME_EXTENSION; + } } } diff --git a/languagetool-language-modules/pt/src/test/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRuleTest.java b/languagetool-language-modules/pt/src/test/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRuleTest.java index 7bd9423ab217..2d16fc5d1cb4 100644 --- a/languagetool-language-modules/pt/src/test/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRuleTest.java +++ b/languagetool-language-modules/pt/src/test/java/org/languagetool/rules/pt/MorfologikPortugueseSpellerRuleTest.java @@ -32,6 +32,10 @@ private JLanguageTool getLT(String countryCode) { private void assertErrorLength(String sentence, int length, JLanguageTool lt, MorfologikPortugueseSpellerRule rule, String[] suggestions) throws IOException { RuleMatch[] matches = rule.match(lt.getAnalyzedSentence(sentence)); + // TODO: just debugging, must delete later! + if (matches.length > 0) { + System.out.println(matches[0].getSuggestedReplacements()); + } assertEquals(length, matches.length); for (int i = 0; i < suggestions.length; i++) { assertEquals(suggestions[i], matches[0].getSuggestedReplacements().get(i)); @@ -41,10 +45,10 @@ private void assertErrorLength(String sentence, int length, JLanguageTool lt, private void assertSingleErrorAndPos(String sentence, JLanguageTool lt, MorfologikPortugueseSpellerRule rule, String[] suggestions, int fromPos, int toPos) throws IOException { RuleMatch[] matches = rule.match(lt.getAnalyzedSentence(sentence)); - assertEquals(1, matches.length); for (int i = 0; i < suggestions.length; i++) { assertEquals(suggestions[i], matches[0].getSuggestedReplacements().get(i)); } + assertEquals(1, matches.length); assertEquals(fromPos, matches[0].getFromPos()); assertEquals(toPos, matches[0].getToPos()); } @@ -54,7 +58,7 @@ private void assertNoErrors(String sentence, JLanguageTool lt, MorfologikPortugu } private void assertSingleError(String sentence, JLanguageTool lt, - MorfologikPortugueseSpellerRule rule, String[] suggestions) throws IOException { + MorfologikPortugueseSpellerRule rule, String[] suggestions) throws IOException { assertErrorLength(sentence, 1, lt, rule, suggestions); } @@ -65,6 +69,11 @@ private void assertTwoWayDialectError(String sentenceBR, String sentencePT) thro assertSingleError(sentencePT, ltBR, ruleBR, new String[]{sentenceBR}); } + @Test + public void testSanity() throws Exception { + assertNoErrors("oogaboogatestword", ltBR, ruleBR); + } + @Test public void testBrazilPortugueseSpelling() throws Exception { assertSingleError("ShintaroW.", ltBR, ruleBR, new String[]{}); @@ -163,6 +172,23 @@ public void testBrazilPortugueseSpellingMorfologikWeirdness() throws Exception { new String[]{"autoconhecimento"}, 14, 29); } + @Test + public void testCustomReplacements() throws Exception { + // Testing the info file. + // Here it's less about the error (though of course that's important), and more about the suggestions. + // We want our custom-defined patterns to prioritise specific types of suggestions. + assertSingleError("vinheram", ltBR, ruleBR, new String[]{"vieram"}); + assertSingleError("recadações", ltBR, ruleBR, new String[]{"arrecadações"}); + assertSingleError("me dis", ltBR, ruleBR, new String[]{"diz"}); + assertSingleError("ebook", ltBR, ruleBR, new String[]{"e-book"}); + assertSingleError("quizese", ltBR, ruleBR, new String[]{"quisesse"}); // this one's tricky to get working + assertSingleError("cabesse", ltBR, ruleBR, new String[]{"coubesse"}); + assertSingleError("andância", ltBR, ruleBR, new String[]{"andança"}); + assertSingleError("abto", ltBR, ruleBR, new String[]{"hábito"}); + // this one is overkill, from hunspell, we can prob. comment it out + assertSingleError("difissio", ltBR, ruleBR, new String[]{"difícil"}); + } + @Test public void testEuropeanPortugueseSpelling() throws Exception { assertEquals(0, rulePT.match(ltPT.getAnalyzedSentence("A família.")).length);