Search in sources :

Example 11 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar 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));
        }
    }
}
Also used : Verifiable(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Verifiable) Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) Lemma(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma) ParserVisitor(de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) JCas(org.apache.uima.jcas.JCas) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) LinkedHashMap(java.util.LinkedHashMap) ConstraintsVerifier(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ConstraintsVerifier) Test(org.junit.Test)

Example 12 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar 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);
    }
}
Also used : Condition(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Condition) Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ArrayList(java.util.ArrayList) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 13 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar 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);
    }
}
Also used : Restriction(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Restriction) Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ArrayList(java.util.ArrayList) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 14 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar 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);
    }
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ArrayList(java.util.ArrayList) Rule(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Rule) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 15 with ConstraintsGrammar

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar 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);
}
Also used : TypeSystem(org.apache.uima.cas.TypeSystem) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ParserVisitor(de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) Feature(org.apache.uima.cas.Feature) FileInputStream(java.io.FileInputStream) LinkedList(java.util.LinkedList) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CAS(org.apache.uima.cas.CAS) PossibleValue(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) Test(org.junit.Test)

Aggregations

ConstraintsGrammar (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar)23 Parse (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse)23 FileInputStream (java.io.FileInputStream)22 Test (org.junit.Test)22 ParsedConstraints (de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints)10 ParserVisitor (de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor)9 Evaluator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator)7 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)7 ValuesGenerator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator)7 ArrayList (java.util.ArrayList)7 JCas (org.apache.uima.jcas.JCas)6 Lemma (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma)4 LinkedList (java.util.LinkedList)4 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)3 CAS (org.apache.uima.cas.CAS)3 Type (org.apache.uima.cas.Type)3 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)3 Scope (de.tudarmstadt.ukp.clarin.webanno.constraints.model.Scope)2 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)2 LinkedHashMap (java.util.LinkedHashMap)2