-
-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: implement spell checker dictionaries
Signed-off-by: Hiroshi Miura <[email protected]>
- Loading branch information
Showing
153 changed files
with
1,173,870 additions
and
539 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
language-modules/ar/src/main/java/org/omegat/languages/ar/ArabicHunspellDictionary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* OmegaT - Computer Assisted Translation (CAT) tool | ||
* with fuzzy matching, translation memory, keyword search, | ||
* glossaries, and translation leveraging into updated projects. | ||
* | ||
* Copyright (C) 2023-2024 Hiroshi Miura | ||
* Home page: https://www.omegat.org/ | ||
* Support center: https://omegat.org/support | ||
* | ||
* This file is part of OmegaT. | ||
* | ||
* OmegaT is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OmegaT is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.omegat.languages.ar; | ||
|
||
import java.io.InputStream; | ||
|
||
import org.languagetool.JLanguageTool; | ||
|
||
import org.omegat.core.spellchecker.AbstractHunspellDictionary; | ||
|
||
public class ArabicHunspellDictionary extends AbstractHunspellDictionary { | ||
|
||
private static final String DICTIONARY_BASE = "/org/languagetool/resource/ar/hunspell/"; | ||
private static final String[] LANG = {"ar"}; | ||
|
||
@Override | ||
protected String[] getDictionaries() { | ||
return LANG; | ||
} | ||
|
||
@Override | ||
protected InputStream getResourceAsStream(final String resource) { | ||
return JLanguageTool.getDataBroker().getAsStream(DICTIONARY_BASE + resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
language-modules/ar/src/main/java/org/omegat/languages/ar/ArabicSpellCheckerDictionary.java
This file was deleted.
Oops, something went wrong.
83 changes: 83 additions & 0 deletions
83
language-modules/ar/src/test/java/org/omegat/languages/ar/HunspellTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
/******************************************************************************* | ||
OmegaT - Computer Assisted Translation (CAT) tool | ||
with fuzzy matching, translation memory, keyword search, | ||
glossaries, and translation leveraging into updated projects. | ||
Copyright (C) 2024 Hiroshi Miura | ||
Home page: https://www.omegat.org/ | ||
Support center: https://omegat.org/support | ||
This file is part of OmegaT. | ||
OmegaT is free software: you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or | ||
(at your option) any later version. | ||
OmegaT is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
******************************************************************************/ | ||
package org.omegat.languages.ar; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.languagetool.JLanguageTool; | ||
|
||
import org.omegat.core.Core; | ||
import org.omegat.core.data.NotLoadedProject; | ||
import org.omegat.core.data.ProjectProperties; | ||
import org.omegat.core.spellchecker.ISpellChecker; | ||
import org.omegat.filters2.master.PluginUtils; | ||
import org.omegat.languagetools.LanguageDataBroker; | ||
import org.omegat.spellchecker.hunspell.HunSpellChecker; | ||
import org.omegat.util.Language; | ||
import org.omegat.util.TestPreferencesInitializer; | ||
|
||
|
||
public class HunspellTest { | ||
|
||
private static final String LANGUAGE = "ar"; | ||
private static final String GOOD = "مرحبا."; | ||
private static Path tmpDir; | ||
|
||
@BeforeClass | ||
public static void setUpClass() throws IOException { | ||
JLanguageTool.setDataBroker(new LanguageDataBroker()); | ||
PluginUtils.loadPlugins(Collections.emptyMap()); | ||
tmpDir = Files.createTempDirectory("omegat"); | ||
assertThat(tmpDir.toFile()).isDirectory(); | ||
Path configDir = Files.createDirectory(tmpDir.resolve(".omegat")); | ||
TestPreferencesInitializer.init(configDir.toString()); | ||
Files.createDirectory(configDir.resolve("spelling")); | ||
FileUtils.forceDeleteOnExit(tmpDir.toFile()); | ||
} | ||
|
||
@Test | ||
public void testDictionary() throws Exception { | ||
ProjectProperties props = new ProjectProperties(tmpDir.toFile()); | ||
props.setTargetLanguage(new Language(LANGUAGE)); | ||
Core.setProject(new NotLoadedProject() { | ||
@Override | ||
public ProjectProperties getProjectProperties() { | ||
return props; | ||
} | ||
}); | ||
ISpellChecker checker = new HunSpellChecker(); | ||
assertThat(checker.initialize()).as("Success initialize").isTrue(); | ||
assertThat(checker.isCorrect(GOOD)).as("Spell check for correct word").isTrue(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...uage-modules/ast/src/main/java/org/omegat/languages/ast/AsturianMorfologikDictionary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* OmegaT - Computer Assisted Translation (CAT) tool | ||
* with fuzzy matching, translation memory, keyword search, | ||
* glossaries, and translation leveraging into updated projects. | ||
* | ||
* Copyright (C) 2023-2024 Hiroshi Miura | ||
* Home page: https://www.omegat.org/ | ||
* Support center: https://omegat.org/support | ||
* | ||
* This file is part of OmegaT. | ||
* | ||
* OmegaT is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* OmegaT is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
package org.omegat.languages.ast; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
import morfologik.stemming.Dictionary; | ||
import org.languagetool.JLanguageTool; | ||
|
||
import org.omegat.core.spellchecker.ISpellCheckerDictionary; | ||
import org.omegat.core.spellchecker.SpellCheckDictionaryType; | ||
|
||
public class AsturianMorfologikDictionary implements ISpellCheckerDictionary, AutoCloseable { | ||
|
||
private static final String DICTIONARY_PATH = "/org/languagetool/resource/ast/hunspell/"; | ||
|
||
private InputStream infoInputStream; | ||
private InputStream dictInputStream; | ||
|
||
@Override | ||
public Dictionary getMorfologikDictionary(String language) { | ||
if ("ast_ES".startsWith(language)) { | ||
infoInputStream = JLanguageTool.getDataBroker().getAsStream(DICTIONARY_PATH + "ast_ES.info"); | ||
dictInputStream = JLanguageTool.getDataBroker().getAsStream(DICTIONARY_PATH + "ast_ES.dict"); | ||
try { | ||
return Dictionary.read(dictInputStream, infoInputStream); | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@Override | ||
public SpellCheckDictionaryType getDictionaryType() { | ||
return SpellCheckDictionaryType.MORFOLOGIK; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
try { | ||
infoInputStream.close(); | ||
dictInputStream.close(); | ||
} catch (IOException ignored) { | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.