use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator in project webanno by webanno.
the class ComplexTypeTest method testCountryType.
@Test
public void testCountryType() throws Exception {
TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");
CAS cas = CasCreationUtils.createCas(tsd, null, null);
cas.setDocumentText("Asia is the largest continent on Earth. Asia is subdivided into 48 countries, two of them (Russia and Turkey) having part of their land in Europe. The most active place on Earth for tropical cyclone activity lies northeast of the Philippines and south of Japan. The Gobi Desert is in Mongolia and the Arabian Desert stretches across much of the Middle East. The Yangtze River in China is the longest river in the continent. The Himalayas between Nepal and China is the tallest mountain range in the world. Tropical rainforests stretch across much of southern Asia and coniferous and deciduous forests lie farther north.");
TypeSystem ts = cas.getTypeSystem();
Type continentType = ts.getType("de.Continent");
Feature continentName = continentType.getFeatureByBaseName("name");
AnnotationFS asiaContinent = cas.createAnnotation(continentType, 0, 4);
asiaContinent.setStringValue(continentName, "Asia");
cas.addFsToIndexes(asiaContinent);
Type countryType = ts.getType("de.Country");
Feature countryName = countryType.getFeatureByBaseName("name");
AnnotationFS russia = cas.createAnnotation(countryType, 56, 62);
russia.setStringValue(countryName, "Russian Federation");
Feature continentFeature = countryType.getFeatureByBaseName("continent");
russia.setFeatureValue(continentFeature, asiaContinent);
cas.addFsToIndexes(russia);
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/region.rules"));
Parse p = parser.Parse();
ParsedConstraints constraints = p.accept(new ParserVisitor());
Evaluator constraintsEvaluator = new ValuesGenerator();
List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(russia, "regionType", constraints);
List<PossibleValue> exValues = new LinkedList<>();
exValues.add(new PossibleValue("cold", true));
assertEquals(possibleValues, exValues);
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator in project webanno by webanno.
the class ComplexTypeTest method testProfType.
@Test
public void testProfType() throws Exception {
TypeSystemDescription tsd = TypeSystemDescriptionFactory.createTypeSystemDescription("desc.types.TestTypeSystemDescriptor");
CAS cas = CasCreationUtils.createCas(tsd, null, null);
cas.setDocumentText("I listen to lectures by Prof. Gurevych sometimes.");
TypeSystem ts = cas.getTypeSystem();
Type profType = ts.getType("de.tud.Prof");
Feature profNameFeature = profType.getFeatureByBaseName("fullName");
Feature profBossFeature = profType.getFeatureByBaseName("boss");
AnnotationFS proemel = cas.createAnnotation(profType, 0, 0);
proemel.setStringValue(profNameFeature, "Hans Juergen Proeml");
cas.addFsToIndexes(proemel);
AnnotationFS gurevych = cas.createAnnotation(profType, 24, 38);
gurevych.setStringValue(profNameFeature, "Iryna Gurevych");
gurevych.setFeatureValue(profBossFeature, proemel);
cas.addFsToIndexes(gurevych);
/*
* for (String feature : Arrays.asList("fullName", "boss")) { Feature someFeature =
* gurevych.getType().getFeatureByBaseName(feature); if
* (someFeature.getRange().isPrimitive()) { String value =
* gurevych.getFeatureValueAsString(someFeature); System.out.println(value); } else {
* FeatureStructure value = gurevych.getFeatureValue(someFeature);
* System.out.printf("%s (%s)%n", value.getFeatureValueAsString(profNameFeature),
* value.getType()); } }
*/
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/prof.rules"));
Parse p = parser.Parse();
ParsedConstraints constraints = p.accept(new ParserVisitor());
Evaluator constraintsEvaluator = new ValuesGenerator();
List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(gurevych, "professorName", constraints);
List<PossibleValue> exValues = new LinkedList<>();
exValues.add(new PossibleValue("Iryna Gurevych", false));
assertEquals(possibleValues, exValues);
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator in project webanno by webanno.
the class ConstraintsGeneratorTest method testSimpleFeature.
@Test
public void testSimpleFeature() throws Exception {
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/9.rules"));
Parse p = parser.Parse();
ParsedConstraints constraints = p.accept(new ParserVisitor());
JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText("is");
Lemma lemma = new Lemma(jcas, 0, 2);
lemma.setValue("be");
lemma.addToIndexes();
Evaluator constraintsEvaluator = new ValuesGenerator();
List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(lemma, "value", constraints);
List<PossibleValue> expectedOutput = new LinkedList<>();
expectedOutput.add(new PossibleValue("be", true));
assertEquals(expectedOutput, possibleValues);
}
Aggregations