Search in sources :

Example 21 with Parse

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

Example 22 with Parse

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

the class ImportVisitorTest method test.

@Test
public void test() throws Exception {
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/6.rules"));
    Parse p = parser.Parse();
    Map<String, String> imports = new LinkedHashMap<>();
    p.accept(new ImportVisitor(), imports);
    for (Entry<String, String> e : imports.entrySet()) {
        System.out.printf("[%s] is short for [%s]%n", e.getKey(), e.getValue());
    }
    assertEquals("de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma", imports.get("Lemma"));
}
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) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 23 with Parse

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

the class ParserVisitorTest 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());
    System.out.printf("%s %n", constraints);
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) 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