Search in sources :

Example 1 with NamedEntity

use of de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity in project webanno by webanno.

the class ConstraintsGeneratorTest method testTwoConditions.

@Test
public void testTwoConditions() throws Exception {
    JCas jcas = makeJCasOneSentence();
    CAS cas = jcas.getCas();
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));
    Token t1 = tokens.get(0);
    Token t2 = tokens.get(tokens.size() - 1);
    NamedEntity gov = new NamedEntity(jcas, t1.getBegin(), t1.getEnd());
    gov.setValue("Animal");
    gov.addToIndexes();
    NamedEntity dep = new NamedEntity(jcas, t2.getBegin(), t2.getEnd());
    dep.setValue("NotWeight");
    dep.addToIndexes();
    Type relationType = cas.getTypeSystem().getType("webanno.custom.Relation");
    AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd());
    FSUtil.setFeature(fs1, "Governor", gov);
    FSUtil.setFeature(fs1, "Dependent", dep);
    cas.addFsToIndexes(fs1);
    ConstraintsGrammar parser = new ConstraintsGrammar(new FileInputStream("src/test/resources/rules/twoConditions.rules"));
    Parse p = parser.Parse();
    ParsedConstraints constraints = p.accept(new ParserVisitor());
    Evaluator constraintsEvaluator = new ValuesGenerator();
    List<PossibleValue> possibleValues = constraintsEvaluator.generatePossibleValues(fs1, "label", constraints);
    System.out.println(possibleValues);
    // "Weight" != "NotWeight", so the rule should not match
    assertEquals(0, possibleValues.size());
}
Also used : Parse(de.tudarmstadt.ukp.clarin.webanno.constraints.grammar.syntaxtree.Parse) ArrayList(java.util.ArrayList) ParserVisitor(de.tudarmstadt.ukp.clarin.webanno.constraints.visitor.ParserVisitor) JCas(org.apache.uima.jcas.JCas) ParsedConstraints(de.tudarmstadt.ukp.clarin.webanno.constraints.model.ParsedConstraints) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) ValuesGenerator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator) Evaluator(de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator) FileInputStream(java.io.FileInputStream) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) 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 2 with NamedEntity

use of de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity in project webanno by webanno.

the class WebAnnoTsv3WriterTestBase method testCrossSentenceSpanWithoutFeatureValue.

@Test
public void testCrossSentenceSpanWithoutFeatureValue() throws Exception {
    JCas jcas = makeJCasTwoSentences();
    NamedEntity ne = new NamedEntity(jcas, 0, jcas.getDocumentText().length());
    ne.addToIndexes();
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(NamedEntity.class));
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) JCas(org.apache.uima.jcas.JCas) Test(org.junit.Test)

Example 3 with NamedEntity

use of de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity in project webanno by webanno.

the class WebAnnoTsv3WriterTestBase method testStackedSubMultiTokenSpanWithFeatureValue.

@Test
public void testStackedSubMultiTokenSpanWithFeatureValue() throws Exception {
    JCas jcas = makeJCasOneSentence("aaaaaa bbbbbb cccccc");
    assertEquals(asList("aaaaaa", "bbbbbb", "cccccc"), toText(select(jcas, Token.class)));
    // 1111111111
    // 01234567890123456789
    // --------------------
    // aaaaaa bbbbbb cccccc
    // 1  ------               - single token
    // 2  ------+------        - multi-token
    // 3           --          - inside token
    // 4         ----          - token prefix
    // 5           ----        - token suffix
    // 6     ---+------        - multi-token prefix
    // 7  ------+---           - multi-token suffix
    // 8     ---+---           - multi-token prefix + suffix
    // 9     ---+------+---    - multi-token prefix + full + suffix
    // 10            |          - zero-span inside token
    // 11         |             - zero-span beginning of token
    // 12               |       - zero-span end of token
    List<NamedEntity> annotations = new ArrayList<>();
    // 1
    annotations.add(new NamedEntity(jcas, 0, 6));
    // 1
    annotations.add(new NamedEntity(jcas, 0, 6));
    // 2
    annotations.add(new NamedEntity(jcas, 0, 13));
    // 2
    annotations.add(new NamedEntity(jcas, 0, 13));
    // 3
    annotations.add(new NamedEntity(jcas, 9, 10));
    // 3
    annotations.add(new NamedEntity(jcas, 9, 10));
    // 4
    annotations.add(new NamedEntity(jcas, 7, 10));
    // 4
    annotations.add(new NamedEntity(jcas, 7, 10));
    // 5
    annotations.add(new NamedEntity(jcas, 9, 13));
    // 5
    annotations.add(new NamedEntity(jcas, 9, 13));
    // 6
    annotations.add(new NamedEntity(jcas, 3, 13));
    // 6
    annotations.add(new NamedEntity(jcas, 3, 13));
    // 7
    annotations.add(new NamedEntity(jcas, 0, 10));
    // 7
    annotations.add(new NamedEntity(jcas, 0, 10));
    // 8
    annotations.add(new NamedEntity(jcas, 3, 10));
    // 8
    annotations.add(new NamedEntity(jcas, 3, 10));
    // 9
    annotations.add(new NamedEntity(jcas, 3, 17));
    // 9
    annotations.add(new NamedEntity(jcas, 3, 17));
    // 10
    annotations.add(new NamedEntity(jcas, 10, 10));
    // 10
    annotations.add(new NamedEntity(jcas, 10, 10));
    // 11
    annotations.add(new NamedEntity(jcas, 7, 7));
    // 11
    annotations.add(new NamedEntity(jcas, 7, 7));
    // 12
    annotations.add(new NamedEntity(jcas, 13, 13));
    // 12
    annotations.add(new NamedEntity(jcas, 13, 13));
    IntStream.range(0, annotations.size()).forEach(idx -> {
        NamedEntity ne = annotations.get(idx);
        ne.setValue(String.valueOf((idx / 2) + 1) + (idx % 2 == 0 ? "a" : "b"));
        ne.addToIndexes();
    });
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(NamedEntity.class));
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Test(org.junit.Test)

Example 4 with NamedEntity

use of de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity in project webanno by webanno.

the class WebAnnoTsv3WriterTestBase method testSingleStackedNonTokenRelationWithoutFeatureValue2.

@Test
public void testSingleStackedNonTokenRelationWithoutFeatureValue2() throws Exception {
    JCas jcas = makeJCasOneSentence();
    CAS cas = jcas.getCas();
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));
    Token t1 = tokens.get(0);
    Token t2 = tokens.get(tokens.size() - 1);
    NamedEntity gov = new NamedEntity(jcas, t1.getBegin(), t1.getEnd());
    gov.addToIndexes();
    NamedEntity dep = new NamedEntity(jcas, t2.getBegin(), t2.getEnd());
    dep.addToIndexes();
    new NamedEntity(jcas, t2.getBegin(), t2.getEnd()).addToIndexes();
    Type relationType = cas.getTypeSystem().getType("webanno.custom.Relation");
    // One at the beginning
    // WebAnno legacy conventions
    // AnnotationFS fs1 = cas.createAnnotation(relationType,
    // min(dep.getBegin(), gov.getBegin()),
    // max(dep.getEnd(), gov.getEnd()));
    // DKPro Core conventions
    AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd());
    FSUtil.setFeature(fs1, "Governor", gov);
    FSUtil.setFeature(fs1, "Dependent", dep);
    cas.addFsToIndexes(fs1);
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(NamedEntity.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.Relation"));
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) Type(org.apache.uima.cas.Type) CAS(org.apache.uima.cas.CAS) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Test(org.junit.Test)

Example 5 with NamedEntity

use of de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity in project webanno by webanno.

the class WebAnnoTsv3WriterTestBase method testSingleNonTokenRelationWithoutFeature.

@Test
public void testSingleNonTokenRelationWithoutFeature() throws Exception {
    JCas jcas = makeJCasOneSentence();
    CAS cas = jcas.getCas();
    List<Token> tokens = new ArrayList<>(select(jcas, Token.class));
    Token t1 = tokens.get(0);
    Token t2 = tokens.get(tokens.size() - 1);
    NamedEntity gov = new NamedEntity(jcas, t1.getBegin(), t1.getEnd());
    gov.addToIndexes();
    NamedEntity dep = new NamedEntity(jcas, t2.getBegin(), t2.getEnd());
    dep.addToIndexes();
    Type relationType = cas.getTypeSystem().getType("webanno.custom.SimpleRelation");
    // One at the beginning
    // WebAnno legacy conventions
    // AnnotationFS fs1 = cas.createAnnotation(relationType,
    // min(dep.getBegin(), gov.getBegin()),
    // max(dep.getEnd(), gov.getEnd()));
    // DKPro Core conventions
    AnnotationFS fs1 = cas.createAnnotation(relationType, dep.getBegin(), dep.getEnd());
    FSUtil.setFeature(fs1, "Governor", gov);
    FSUtil.setFeature(fs1, "Dependent", dep);
    cas.addFsToIndexes(fs1);
    writeAndAssertEquals(jcas, WebannoTsv3Writer.PARAM_SPAN_LAYERS, asList(NamedEntity.class), WebannoTsv3Writer.PARAM_RELATION_LAYERS, asList("webanno.custom.SimpleRelation"));
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) Type(org.apache.uima.cas.Type) CAS(org.apache.uima.cas.CAS) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Test(org.junit.Test)

Aggregations

NamedEntity (de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity)44 Test (org.junit.Test)40 JCas (org.apache.uima.jcas.JCas)39 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)23 ArrayList (java.util.ArrayList)15 Type (org.apache.uima.cas.Type)13 CAS (org.apache.uima.cas.CAS)12 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)12 LinkedHashMap (java.util.LinkedHashMap)2 Evaluator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.Evaluator)1 PossibleValue (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.PossibleValue)1 ValuesGenerator (de.tudarmstadt.ukp.clarin.webanno.constraints.evaluator.ValuesGenerator)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 AgreementResult (de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult)1 ArcDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcDiffAdapter)1 DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult)1 FeatureType (de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.FeatureType)1