Search in sources :

Example 1 with Verifiable

use of de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Verifiable 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)

Aggregations

ConstraintsVerifier (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ConstraintsVerifier)1 Verifiable (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Verifiable)1 ConstraintsGrammar (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.ConstraintsGrammar)1 Parse (de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse)1 ParsedConstraints (de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints)1 ParserVisitor (de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor)1 Lemma (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Lemma)1 FileInputStream (java.io.FileInputStream)1 LinkedHashMap (java.util.LinkedHashMap)1 JCas (org.apache.uima.jcas.JCas)1 Test (org.junit.Test)1