forked from languagetool-org/languagetool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f39b2a2
commit 187d80b
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
languagetool-server/src/main/java/org/languagetool/server/RemoteSynthesizer.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,31 @@ | ||
package org.languagetool.server; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.languagetool.AnalyzedToken; | ||
import org.languagetool.Language; | ||
import org.languagetool.Languages; | ||
import org.languagetool.synthesis.Synthesizer; | ||
|
||
public class RemoteSynthesizer { | ||
|
||
protected List<String> synthesize(String languageCode, String lemma, String postagRegexp) throws IOException { | ||
Language lang = null; | ||
lang = Languages.getLanguageForShortCode(languageCode); | ||
Synthesizer synth = lang.getSynthesizer(); | ||
AnalyzedToken at = new AnalyzedToken(lemma, postagRegexp, lemma); | ||
String[] synthesizedForms = synth.synthesize(at, postagRegexp, true); | ||
// removing duplicates. TODO: de-duplicate in the original synthesizer (?) | ||
List<String> results = new ArrayList<>(); | ||
for (String s : synthesizedForms) { | ||
if (!results.contains(s)) { | ||
results.add(s); | ||
} | ||
} | ||
return results; | ||
|
||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
languagetool-server/src/test/java/org/languagetool/server/RemoteSynthesizerTest.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,29 @@ | ||
package org.languagetool.server; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class RemoteSynthesizerTest { | ||
|
||
@Test | ||
public void testSynthesis() throws Exception { | ||
RemoteSynthesizer remoteSynth = new RemoteSynthesizer(); | ||
|
||
assertEquals(remoteSynth.synthesize("de", "Äußerung","SUB:NOM:PLU:FEM").toString(), "[Äußerungen]"); | ||
// Removing duplicates! | ||
assertEquals(remoteSynth.synthesize("de", "Äußerung","SUB:.*:PLU:FEM").toString(), "[Äußerungen]"); | ||
assertEquals(remoteSynth.synthesize("pt", "resolver","VMIS3S0").toString(), "[resolveu]"); | ||
assertEquals(remoteSynth.synthesize("es", "cantar","VMIP1S0").toString(), "[canto]"); | ||
assertEquals(remoteSynth.synthesize("es", "señor","NC.P.*").toString(), "[señoras, señores]"); | ||
assertEquals(remoteSynth.synthesize("fr", "monde","N m p").toString(), "[mondes]"); | ||
assertEquals(remoteSynth.synthesize("fr", "chanter","V ppa.*").toString(), "[chantées, chantée, chantés, chanté]"); | ||
assertEquals(remoteSynth.synthesize("en", "be","VBZ").toString(), "[is]"); | ||
assertEquals(remoteSynth.synthesize("en-US", "be","VBZ").toString(), "[is]"); | ||
assertEquals(remoteSynth.synthesize("en-GB", "be","VBZ").toString(), "[is]"); | ||
assertEquals(remoteSynth.synthesize("en", "be","V.*").toString(), "[be, was, were, being, been, are, is]"); | ||
assertEquals(remoteSynth.synthesize("en", "be","N.*").toString(), "[]"); | ||
|
||
} | ||
|
||
} |