Search in sources :

Example 21 with NamedEntity

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

the class Tsv3XSerializerTest method testStackedSingleTokenWithValue.

@Test
public void testStackedSingleTokenWithValue() throws Exception {
    // Create test document
    JCas cas = makeJCasOneSentence("This is a test .");
    NamedEntity ne1 = addNamedEntity(cas, 0, 4, "PER");
    NamedEntity ne2 = addNamedEntity(cas, 0, 4, "ORG");
    // Set up TSV schema
    TsvSchema schema = new TsvSchema();
    Type namedEntityType = cas.getCasType(NamedEntity.type);
    schema.addColumn(new TsvColumn(namedEntityType, LayerType.SPAN, "value", FeatureType.PRIMITIVE));
    // Convert test document content to TSV model
    TsvDocument doc = Tsv3XCasDocumentBuilder.of(schema, cas);
    doc.getSentences().get(0).getTokens().get(0).addUimaAnnotation(ne1, true);
    doc.getSentences().get(0).getTokens().get(0).addUimaAnnotation(ne2, true);
    assertEquals("1-1\t0-4\tThis\tPER[1]|ORG[2]\t", doc.getSentences().get(0).getTokens().get(0).toString());
    String expectedSentence = "#Text=This is a test .\n" + "1-1\t0-4\tThis\tPER[1]|ORG[2]\t\n" + "1-2\t5-7\tis\t_\t\n" + "1-3\t8-9\ta\t_\t\n" + "1-4\t10-14\ttest\t_\t\n" + "1-5\t15-16\t.\t_\t\n";
    assertEquals(expectedSentence, doc.getSentences().get(0).toString());
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) LayerType(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.LayerType) Type(org.apache.uima.cas.Type) FeatureType(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.FeatureType) TsvColumn(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvColumn) TsvDocument(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvDocument) JCas(org.apache.uima.jcas.JCas) TsvSchema(de.tudarmstadt.ukp.clarin.webanno.tsv.internal.tsv3x.model.TsvSchema) Test(org.junit.Test)

Example 22 with NamedEntity

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

the class Tsv3XSerializerTest method addNamedEntity.

private NamedEntity addNamedEntity(JCas aJCas, int aBegin, int aEnd, String aValue) {
    NamedEntity ne = new NamedEntity(aJCas, aBegin, aEnd);
    ne.setValue(aValue);
    ne.addToIndexes();
    return ne;
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity)

Example 23 with NamedEntity

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

the class SharedNEsFeatureExtractorTest method extractTest1.

@Test
public void extractTest1() throws Exception {
    NamedEntity ne1 = new NamedEntity(jcas1, 0, 4);
    ne1.addToIndexes();
    SharedNEsFeatureExtractor extractor = new SharedNEsFeatureExtractor();
    Set<Feature> features = extractor.extract(jcas1, jcas2);
    assertEquals(1, features.size());
    for (Feature feature : features) {
        assertFeature("SharedNEs", false, feature);
    }
    NamedEntity ne2 = new NamedEntity(jcas2, 0, 4);
    ne2.addToIndexes();
    features = extractor.extract(jcas1, jcas2);
    assertEquals(1, features.size());
    for (Feature feature : features) {
        assertFeature("SharedNEs", true, feature);
    }
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) FeatureTestUtil.assertFeature(org.dkpro.tc.testing.FeatureTestUtil.assertFeature) Feature(org.dkpro.tc.api.features.Feature) SharedNEsFeatureExtractor(org.dkpro.tc.features.pair.core.ne.SharedNEsFeatureExtractor) Test(org.junit.Test)

Example 24 with NamedEntity

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

the class CasDiff2Test method relationStackedSpansTest.

@Test
public void relationStackedSpansTest() throws Exception {
    TypeSystemDescription global = TypeSystemDescriptionFactory.createTypeSystemDescription();
    TypeSystemDescription local = TypeSystemDescriptionFactory.createTypeSystemDescriptionFromPath("src/test/resources/desc/type/webannoTestTypes.xml");
    TypeSystemDescription merged = CasCreationUtils.mergeTypeSystems(asList(global, local));
    TokenBuilder<Token, Sentence> tb = new TokenBuilder<>(Token.class, Sentence.class);
    JCas jcasA = JCasFactory.createJCas(merged);
    {
        CAS casA = jcasA.getCas();
        tb.buildTokens(jcasA, "This is a test .");
        List<Token> tokensA = new ArrayList<>(select(jcasA, Token.class));
        Token t1A = tokensA.get(0);
        Token t2A = tokensA.get(tokensA.size() - 1);
        NamedEntity govA = new NamedEntity(jcasA, t1A.getBegin(), t1A.getEnd());
        govA.addToIndexes();
        // Here we add a stacked named entity!
        new NamedEntity(jcasA, t1A.getBegin(), t1A.getEnd()).addToIndexes();
        NamedEntity depA = new NamedEntity(jcasA, t2A.getBegin(), t2A.getEnd());
        depA.addToIndexes();
        Type relationTypeA = casA.getTypeSystem().getType("webanno.custom.Relation");
        AnnotationFS fs1A = casA.createAnnotation(relationTypeA, depA.getBegin(), depA.getEnd());
        FSUtil.setFeature(fs1A, "Governor", govA);
        FSUtil.setFeature(fs1A, "Dependent", depA);
        FSUtil.setFeature(fs1A, "value", "REL");
        casA.addFsToIndexes(fs1A);
    }
    JCas jcasB = JCasFactory.createJCas(merged);
    {
        CAS casB = jcasB.getCas();
        tb.buildTokens(jcasB, "This is a test .");
        List<Token> tokensB = new ArrayList<>(select(jcasB, Token.class));
        Token t1B = tokensB.get(0);
        Token t2B = tokensB.get(tokensB.size() - 1);
        NamedEntity govB = new NamedEntity(jcasB, t1B.getBegin(), t1B.getEnd());
        govB.addToIndexes();
        NamedEntity depB = new NamedEntity(jcasB, t2B.getBegin(), t2B.getEnd());
        depB.addToIndexes();
        Type relationTypeB = casB.getTypeSystem().getType("webanno.custom.Relation");
        AnnotationFS fs1B = casB.createAnnotation(relationTypeB, depB.getBegin(), depB.getEnd());
        FSUtil.setFeature(fs1B, "Governor", govB);
        FSUtil.setFeature(fs1B, "Dependent", depB);
        FSUtil.setFeature(fs1B, "value", "REL");
        casB.addFsToIndexes(fs1B);
    }
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));
    List<String> entryTypes = asList("webanno.custom.Relation");
    List<? extends DiffAdapter> diffAdapters = asList(new ArcDiffAdapter("webanno.custom.Relation", WebAnnoConst.FEAT_REL_TARGET, WebAnnoConst.FEAT_REL_SOURCE, "value"));
    DiffResult diff = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    diff.print(System.out);
    assertEquals(1, diff.size());
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
    // Check against new impl
    AgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff, "webanno.custom.Relation", "value", casByUser);
    // Asserts
    System.out.printf("Agreement: %s%n", agreement.toString());
    AgreementUtils.dumpAgreementStudy(System.out, agreement);
    assertEquals(1, agreement.getPluralitySets().size());
}
Also used : AgreementResult(de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult) TokenBuilder(org.apache.uima.fit.testing.factory.TokenBuilder) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) ArcDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcDiffAdapter) JCas(org.apache.uima.jcas.JCas) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) LinkedHashMap(java.util.LinkedHashMap) 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) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) Test(org.junit.Test)

Example 25 with NamedEntity

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

the class TcfReader method convertNamedEntities.

private void convertNamedEntities(JCas aJCas, TextCorpus aCorpusData, Map<String, Token> aTokens) {
    if (aCorpusData.getNamedEntitiesLayer() == null) {
        // No layer to read from.
        return;
    }
    for (int i = 0; i < aCorpusData.getNamedEntitiesLayer().size(); i++) {
        // get the named entity
        eu.clarin.weblicht.wlfxb.tc.api.NamedEntity entity = aCorpusData.getNamedEntitiesLayer().getEntity(i);
        eu.clarin.weblicht.wlfxb.tc.api.Token[] namedEntityTokens = aCorpusData.getNamedEntitiesLayer().getTokens(entity);
        NamedEntity outNamedEntity = new NamedEntity(aJCas);
        outNamedEntity.setBegin(getOffsets(namedEntityTokens, aTokens)[0]);
        outNamedEntity.setEnd(getOffsets(namedEntityTokens, aTokens)[1]);
        outNamedEntity.setValue(entity.getType());
        outNamedEntity.addToIndexes();
    }
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)

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