use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.
the class ConstraintsVerifierTest method test.
@Test
public void test() throws Exception {
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/6.rules"));
Parse p = parser.Parse();
ParsedConstraints constraints = p.accept(new ParserVisitor());
// Get imports
Map<String, String> imports = new LinkedHashMap<>();
imports = constraints.getImports();
// Get rules
// List<Rule> rules = new ArrayList<>();
JCas jcas = JCasFactory.createJCas();
jcas.setDocumentText("Just some text.");
Lemma lemma1 = new Lemma(jcas, 0, 1);
lemma1.setValue("good");
lemma1.addToIndexes();
Lemma lemma2 = new Lemma(jcas, 1, 2);
lemma2.setValue("bad");
lemma2.addToIndexes();
Verifiable cVerifier = new ConstraintsVerifier();
for (Lemma lemma : select(jcas, Lemma.class)) {
if (lemma == lemma1) {
assertEquals(true, cVerifier.verify(lemma, constraints));
}
if (lemma == lemma2) {
assertEquals(false, cVerifier.verify(lemma, constraints));
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.
the class ConditionVisitorTest method test.
@Test
public void test() throws Exception {
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/6.rules"));
Parse p = parser.Parse();
List<Condition> conditions = new ArrayList<>();
p.accept(new ConditionVisitor(), conditions);
for (Condition cond : conditions) {
System.out.printf("%s %n", cond);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.
the class RestrictionVisitorTest method test.
@Test
public void test() throws Exception {
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/6.rules"));
Parse p = parser.Parse();
List<Restriction> restrictions = new ArrayList<>();
p.accept(new RestrictionVisitor(), restrictions);
for (Restriction res : restrictions) {
System.out.printf("%s %n", res);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.
the class RuleVisitorTest method test.
@Test
public void test() throws Exception {
ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/6.rules"));
Parse p = parser.Parse();
List<Rule> rules = new ArrayList<>();
p.accept(new RuleVisitor(), rules);
for (Rule rule : rules) {
System.out.printf("%s %n", rule);
}
}
use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse 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);
}
Aggregations