Skip to content

Commit

Permalink
add test and fix errors
Browse files Browse the repository at this point in the history
Signed-off-by: Hiroshi Miura <[email protected]>
  • Loading branch information
miurahr committed Nov 22, 2024
1 parent b9d340a commit 41b598e
Show file tree
Hide file tree
Showing 28 changed files with 880 additions and 74 deletions.
9 changes: 8 additions & 1 deletion language-modules/ar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,14 @@ dependencies {
testImplementation(libs.junit4)
testImplementation(libs.assertj)
testImplementation(testFixtures(project.rootProject))
testImplementation(libs.commons.io)
testImplementation(libs.languagetool.core)
testImplementation(project(":spellchecker:hunspell"))
testRuntimeOnly(libs.commons.io)
}

test {
dependsOn jar
dependsOn project(":spellchecker:hunspell").tasks.jar
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,13 @@ public Path installHunspellDictionary(Path dictionaryDir, String language) {
if (LANG.equals(language)) {
try {
Path dictionaryPath = dictionaryDir.resolve(LANG + ".dic");
try (InputStream dicStream = JLanguageTool.getDataBroker()
.getFromResourceDirAsStream(DICTIONARY_PATH);
FileOutputStream fos = new FileOutputStream(dictionaryPath.toFile())) {
try (InputStream dicStream = JLanguageTool.getDataBroker().getAsStream(DICTIONARY_PATH);
FileOutputStream fos = new FileOutputStream(dictionaryPath.toFile())) {
IOUtils.copy(dicStream, fos);
}
File affixFile = dictionaryDir.resolve(LANG + ".aff").toFile();
try (InputStream affStream = JLanguageTool.getDataBroker()
.getFromResourceDirAsStream(AFFIX_PATH);
FileOutputStream fos = new FileOutputStream(affixFile)) {
try (InputStream affStream = JLanguageTool.getDataBroker().getAsStream(AFFIX_PATH);
FileOutputStream fos = new FileOutputStream(affixFile)) {
IOUtils.copy(affStream, fos);
}
return dictionaryPath;
Expand Down
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();
}

}
7 changes: 7 additions & 0 deletions language-modules/ast/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ dependencies {
testImplementation(libs.junit4)
testImplementation(libs.assertj)
testImplementation(testFixtures(project.rootProject))
testImplementation(libs.languagetool.core)
testImplementation project(":spellchecker:morfologik")
testImplementation(libs.commons.io)
}

test {
dependsOn jar
dependsOn project(":spellchecker:morfologik").tasks.jar
}

jar {
archiveFileName.set("omegat-language-ast.${archiveExtension.get()}")
destinationDirectory.set(rootProject.layout.buildDirectory.dir("modules").get())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public final class AsturianPlugin {

private static final String ASTURIAN = "org.languagetool.language.Asturian";
private static final String SPELLCHECK_DICITONARY = "org.omegat.languages.ast"
+ ".AstruianSpellCheckerDictionary";
+ ".AsturianSpellCheckerDictionary";

private AsturianPlugin() {
}
Expand Down
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.ast;

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.morfologik.MorfologikSpellchecker;
import org.omegat.util.Language;
import org.omegat.util.TestPreferencesInitializer;


public class MorfologikTest {

private static final String LANGUAGE = "ast";
// 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 MorfologikSpellchecker();
assertThat(checker.initialize()).as("Success initialize").isTrue();
// assertThat(checker.isCorrect(GOOD)).as("Spell check for correct word").isTrue();
}

}
7 changes: 7 additions & 0 deletions language-modules/be/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,16 @@ dependencies {
testImplementation(libs.junit4)
testImplementation(libs.assertj)
testImplementation(testFixtures(project.rootProject))
testImplementation(libs.languagetool.core)
testImplementation project(":spellchecker:morfologik")
testImplementation(libs.commons.io)
}

test {
dependsOn jar
dependsOn project(":spellchecker:morfologik").tasks.jar
}

jar {
archiveFileName.set("omegat-language-be.${archiveExtension.get()}")
destinationDirectory.set(rootProject.layout.buildDirectory.dir("modules").get())
Expand Down
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.be;

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.morfologik.MorfologikSpellchecker;
import org.omegat.util.Language;
import org.omegat.util.TestPreferencesInitializer;


public class MorfologikTest {

private static final String LANGUAGE = "be_BY";
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 MorfologikSpellchecker();
assertThat(checker.initialize()).as("Success initialize").isTrue();
assertThat(checker.isCorrect(GOOD)).as("Spell check for correct word").isTrue();
}

}
7 changes: 7 additions & 0 deletions language-modules/br/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,16 @@ dependencies {
testImplementation(libs.junit4)
testImplementation(libs.assertj)
testImplementation(testFixtures(project.rootProject))
testImplementation(libs.languagetool.core)
testImplementation project(":spellchecker:morfologik")
testImplementation(libs.commons.io)
}

test {
dependsOn jar
dependsOn project(":spellchecker:morfologik").tasks.jar
}

jar {
archiveFileName.set("omegat-language-br.${archiveExtension.get()}")
destinationDirectory.set(rootProject.layout.buildDirectory.dir("modules").get())
Expand Down
Loading

0 comments on commit 41b598e

Please sign in to comment.