use of org.languagetool.AnalyzedToken in project languagetool by languagetool-org.
the class UnifierTest method testUnificationNumber.
// slightly non-trivial unification = test if the grammatical number is the same
@Test
public void testUnificationNumber() {
UnifierConfiguration unifierConfig = new UnifierConfiguration();
unifierConfig.setEquivalence("number", "singular", preparePOSElement(".*[\\.:]sg:.*"));
unifierConfig.setEquivalence("number", "plural", preparePOSElement(".*[\\.:]pl:.*"));
Unifier uni = unifierConfig.createUnifier();
AnalyzedToken sing1 = new AnalyzedToken("mały", "adj:sg:blahblah", "mały");
AnalyzedToken sing2 = new AnalyzedToken("człowiek", "subst:sg:blahblah", "człowiek");
Map<String, List<String>> equiv = new HashMap<>();
List<String> list1 = new ArrayList<>();
list1.add("singular");
equiv.put("number", list1);
boolean satisfied = uni.isSatisfied(sing1, equiv);
uni.startUnify();
satisfied &= uni.isSatisfied(sing2, equiv);
satisfied &= uni.getFinalUnificationValue(equiv);
assertEquals(true, satisfied);
uni.reset();
//for multiple readings - OR for interpretations, AND for tokens
AnalyzedToken sing1a = new AnalyzedToken("mały", "adj:pl:blahblah", "mały");
satisfied = uni.isSatisfied(sing1, equiv);
satisfied |= uni.isSatisfied(sing1a, equiv);
uni.startUnify();
satisfied &= uni.isSatisfied(sing2, equiv);
satisfied &= uni.getFinalUnificationValue(equiv);
assertEquals(true, satisfied);
uni.reset();
//check if any of the equivalences is there
list1.add("plural");
equiv.clear();
equiv.put("number", list1);
sing1a = new AnalyzedToken("mały", "adj:pl:blahblah", "mały");
satisfied = uni.isSatisfied(sing1, equiv);
satisfied |= uni.isSatisfied(sing1a, equiv);
uni.startUnify();
satisfied &= uni.isSatisfied(sing2, equiv);
satisfied &= uni.getFinalUnificationValue(equiv);
assertEquals(true, satisfied);
uni.reset();
//now test all possible feature equivalences by leaving type blank
sing1a = new AnalyzedToken("mały", "adj:pl:blahblah", "mały");
equiv.clear();
equiv.put("number", null);
satisfied = uni.isSatisfied(sing1, equiv);
satisfied |= uni.isSatisfied(sing1a, equiv);
uni.startUnify();
satisfied &= uni.isSatisfied(sing2, equiv);
satisfied &= uni.getFinalUnificationValue(equiv);
assertEquals(true, satisfied);
uni.reset();
//test non-agreeing tokens with blank types
satisfied = uni.isSatisfied(sing1a, equiv);
uni.startUnify();
satisfied &= uni.isSatisfied(sing2, equiv);
satisfied &= uni.getFinalUnificationValue(equiv);
assertEquals(false, satisfied);
uni.reset();
}
use of org.languagetool.AnalyzedToken in project languagetool by languagetool-org.
the class ManualTaggerAdapterTest method testMultiplePOS.
@Test
public void testMultiplePOS() throws Exception {
List<String> l = Arrays.asList("inflectedform2");
List<AnalyzedTokenReadings> analyzedTokenReadings = tagger.tag(l);
assertNotNull(analyzedTokenReadings);
assertEquals(1, analyzedTokenReadings.size());
AnalyzedTokenReadings analyzedTokenReading = analyzedTokenReadings.get(0);
assertEquals("inflectedform2", analyzedTokenReading.getToken());
assertNotNull(analyzedTokenReading.getReadings());
assertEquals(3, analyzedTokenReading.getReadingsLength());
AnalyzedToken analyzedToken;
analyzedToken = analyzedTokenReading.getReadings().get(0);
assertEquals("POS1a", analyzedToken.getPOSTag());
assertEquals("inflectedform2", analyzedToken.getToken());
assertEquals("lemma2", analyzedToken.getLemma());
analyzedToken = analyzedTokenReading.getReadings().get(1);
assertEquals("POS1b", analyzedToken.getPOSTag());
assertEquals("inflectedform2", analyzedToken.getToken());
assertEquals("lemma2", analyzedToken.getLemma());
analyzedToken = analyzedTokenReading.getReadings().get(2);
assertEquals("POS1c", analyzedToken.getPOSTag());
assertEquals("inflectedform2", analyzedToken.getToken());
assertEquals("lemma2", analyzedToken.getLemma());
}
use of org.languagetool.AnalyzedToken in project languagetool by languagetool-org.
the class ManualTaggerAdapterTest method testMultipleLemma.
@Test
public void testMultipleLemma() throws Exception {
List<String> l = Arrays.asList("inflectedform3");
List<AnalyzedTokenReadings> analyzedTokenReadings = tagger.tag(l);
assertNotNull(analyzedTokenReadings);
assertEquals(1, analyzedTokenReadings.size());
AnalyzedTokenReadings analyzedTokenReading = analyzedTokenReadings.get(0);
assertEquals("inflectedform3", analyzedTokenReading.getToken());
assertNotNull(analyzedTokenReading.getReadings());
assertEquals(4, analyzedTokenReading.getReadingsLength());
AnalyzedToken analyzedToken;
analyzedToken = analyzedTokenReading.getReadings().get(0);
assertEquals("inflectedform3", analyzedToken.getToken());
assertEquals("lemma3a", analyzedToken.getLemma());
assertEquals("POS3a", analyzedToken.getPOSTag());
analyzedToken = analyzedTokenReading.getReadings().get(1);
assertEquals("inflectedform3", analyzedToken.getToken());
assertEquals("lemma3b", analyzedToken.getLemma());
assertEquals("POS3b", analyzedToken.getPOSTag());
analyzedToken = analyzedTokenReading.getReadings().get(2);
assertEquals("inflectedform3", analyzedToken.getToken());
assertEquals("lemma3c", analyzedToken.getLemma());
assertEquals("POS3c", analyzedToken.getPOSTag());
analyzedToken = analyzedTokenReading.getReadings().get(3);
assertEquals("inflectedform3", analyzedToken.getToken());
assertEquals("lemma3d", analyzedToken.getLemma());
assertEquals("POS3d", analyzedToken.getPOSTag());
}
use of org.languagetool.AnalyzedToken in project languagetool by languagetool-org.
the class RuleFilterEvaluatorTest method testDuplicateKey.
@Test(expected = RuntimeException.class)
public void testDuplicateKey() throws Exception {
AnalyzedTokenReadings[] readingsList = { new AnalyzedTokenReadings(new AnalyzedToken("fake1", "SENT_START", null), 0), new AnalyzedTokenReadings(new AnalyzedToken("fake1", "pos", null), 0), new AnalyzedTokenReadings(new AnalyzedToken("fake2", "pos", null), 0) };
eval.getResolvedArguments("year:\\1 year:\\2", readingsList, Arrays.asList(1, 2));
}
use of org.languagetool.AnalyzedToken in project languagetool by languagetool-org.
the class GermanHelperTest method testHasReadingOfType.
@Test
public void testHasReadingOfType() throws Exception {
AnalyzedTokenReadings readings = new AnalyzedTokenReadings(new AnalyzedToken("der", "ART:DEF:DAT:SIN:FEM", null), 0);
assertTrue(GermanHelper.hasReadingOfType(readings, GermanToken.POSType.DETERMINER));
assertFalse(GermanHelper.hasReadingOfType(readings, GermanToken.POSType.NOMEN));
}
Aggregations