Skip to content

Commit

Permalink
Fix false positives for some Slovak rules
Browse files Browse the repository at this point in the history
  • Loading branch information
valentjn committed Jan 24, 2021
1 parent 3a7f027 commit 42b5124
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@

# Changelog

## 9.1.1 (upcoming)

- Fix false positives for words added by `Add to dictionary` for Slovak rule IDs `MUZSKY_ROD_NEZIV_A`, `ZENSKY_ROD_A`, and `STREDNY_ROD_A` (fixes [vscode-ltex#221](https://github.com/valentjn/vscode-ltex/issues/221))

## 9.1.0 (January 24, 2021)

- Add support for BibT<sub>E</sub>X files (language code `bibtex`, fixes [vscode-ltex#211](https://github.com/valentjn/vscode-ltex/issues/211))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.xml.sax.SAXException;

public class LanguageToolJavaInterface extends LanguageToolInterface {
private Set<String> dictionary;
private @MonotonicNonNull ResultCache resultCache;
private @MonotonicNonNull JLanguageTool languageTool;

Expand All @@ -54,6 +55,8 @@ public class LanguageToolJavaInterface extends LanguageToolInterface {
*/
public LanguageToolJavaInterface(String languageShortCode, String motherTongueShortCode,
int sentenceCacheSize, Set<String> dictionary) {
this.dictionary = dictionary;

if (!Languages.isLanguageSupported(languageShortCode)) {
Tools.logger.severe(Tools.i18n("notARecognizedLanguage", languageShortCode));
return;
Expand Down Expand Up @@ -157,10 +160,20 @@ public void write(int b) {
return Collections.emptyList();
}

String code = annotatedTextFragment.getCodeFragment().getCode();
List<LanguageToolRuleMatch> result = new ArrayList<>();

for (RuleMatch match : matches) {
result.add(new LanguageToolRuleMatch(match, annotatedTextFragment));
LanguageToolRuleMatch languageToolRuleMatch =
new LanguageToolRuleMatch(match, annotatedTextFragment);

if (languageToolRuleMatch.isUnknownWordRule()
&& this.dictionary.contains(code.substring(languageToolRuleMatch.getFromPos(),
languageToolRuleMatch.getToPos()))) {
continue;
}

result.add(languageToolRuleMatch);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,15 @@ public void testDictionary() {
Pair<List<LanguageToolRuleMatch>, List<AnnotatedTextFragment>> checkingResult =
checkDocument(document, settings);
Assertions.assertEquals(1, checkingResult.getKey().size());

document = createDocument("latex", "S pekn\u00e9 inteligentn\u00fdmi dubmi.\n");
settings = settings.withLanguageShortCode("sk-SK");
checkingResult = checkDocument(document, settings);
Assertions.assertEquals(1, checkingResult.getKey().size());

settings = settings.withDictionary(Collections.singleton("pekn\u00e9"));
checkingResult = checkDocument(document, settings);
Assertions.assertEquals(0, checkingResult.getKey().size());
}

@Test
Expand Down

0 comments on commit 42b5124

Please sign in to comment.