Search in sources :

Example 16 with Parse

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse 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);
}
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)

Example 17 with Parse

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.

the class ScopeVisitorTest 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<Scope> scopes = new ArrayList<>();
    p.accept(new ScopeVisitor(), scopes);
    for (Scope scope : scopes) {
        System.out.printf("%s %n", scope);
    }
}
Also used : Scope(de.tudarmstadt.ukp.clarin.webanno.constraints.model.Scope) 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 18 with Parse

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.

the class ConstraintsParserTest method test5.

@Test
public void test5() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/5.rules"));
    Parse p = parser.Parse();
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 19 with Parse

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.

the class ConstraintsParserTest method test2.

@Test
public void test2() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/2.rules"));
    Parse p = parser.Parse();
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 20 with Parse

use of de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse in project webanno by webanno.

the class ConstraintsParserTest method test6.

@Test
public void test6() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/6.rules"));
    Parse p = parser.Parse();
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ConstraintsGrammar(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar) FileInputStream(java.io.FileInputStream) 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