Skip to content

Commit

Permalink
[pt] Make AO and MZ variants use PT dict
Browse files Browse the repository at this point in the history
  • Loading branch information
p-goulart committed Oct 27, 2023
1 parent 4f48419 commit 1b0f6b0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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());
}
Expand All @@ -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);
}

Expand All @@ -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[]{});
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1b0f6b0

Please sign in to comment.