Search in sources :

Example 6 with JCasFactory.createJCas

use of org.apache.uima.fit.factory.JCasFactory.createJCas in project webanno by webanno.

the class CasDiffTest 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<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA.getCas()));
    casByUser.put("user2", asList(jcasB.getCas()));
    List<? extends DiffAdapter> diffAdapters = asList(new RelationDiffAdapter("webanno.custom.Relation", WebAnnoConst.FEAT_REL_TARGET, WebAnnoConst.FEAT_REL_SOURCE, "value"));
    CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
    DiffResult result = diff.toResult();
    // result.print(System.out);
    assertEquals(1, result.size());
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
// Todo: Agreement has moved to separate project - should create agreement test there
// CodingAgreementResult 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 : TokenBuilder(org.apache.uima.fit.testing.factory.TokenBuilder) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) 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) RelationDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.relation.RelationDiffAdapter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence) Test(org.junit.Test)

Example 7 with JCasFactory.createJCas

use of org.apache.uima.fit.factory.JCasFactory.createJCas in project webanno by webanno.

the class CasDiffTest method multiLinkWithRoleMultiTargetDifferenceTest.

@Test
public void multiLinkWithRoleMultiTargetDifferenceTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(createMultiLinkWithRoleTestTypeSystem());
    makeLinkHostFS(jcasA, 0, 0, makeLinkFS(jcasA, "slot1", 0, 0), makeLinkFS(jcasA, "slot1", 10, 10));
    JCas jcasB = JCasFactory.createJCas(createMultiLinkWithRoleTestTypeSystem());
    makeLinkHostFS(jcasB, 0, 0, makeLinkFS(jcasB, "slot1", 10, 10));
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA.getCas()));
    casByUser.put("user2", asList(jcasB.getCas()));
    SpanDiffAdapter adapter = new SpanDiffAdapter(HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);
    DiffResult diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    // diff.print(System.out);
    assertEquals(2, diff.size());
    assertEquals(1, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
// // Check against new impl
// AgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff, HOST_TYPE,
// "links",
// casByUser);
// 
// // Asserts
// System.out.printf("Agreement: %s%n", agreement.toString());
// AgreementUtils.dumpAgreementStudy(System.out, agreement);
// 
// assertEquals(0.0, agreement.getAgreement(), 0.00001d);
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter) JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 8 with JCasFactory.createJCas

use of org.apache.uima.fit.factory.JCasFactory.createJCas in project webanno by webanno.

the class CasMergeTest method copyLinkToExistingButDiffLinkTest.

@Test
public void copyLinkToExistingButDiffLinkTest() throws Exception {
    JCas mergeCas = JCasFactory.createJCas(createMultiLinkWithRoleTestTypeSystem("f1"));
    Type type = mergeCas.getTypeSystem().getType(CurationTestUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");
    AnnotationFS mergeFs = makeLinkHostMultiSPanFeatureFS(mergeCas, 0, 0, feature, "A", makeLinkFS(mergeCas, "slot1", 0, 0));
    FeatureStructure copyFS = makeLinkFS(mergeCas, "slot2", 0, 0);
    List<FeatureStructure> linkFs = new ArrayList<>();
    linkFs.add(copyFS);
    WebAnnoCasUtil.setLinkFeatureValue(mergeFs, type.getFeatureByBaseName("links"), linkFs);
    JCas jcasA = createJCas(CurationTestUtils.createMultiLinkWithRoleTestTypeSystem("f1"));
    makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", makeLinkFS(jcasA, "slot1", 0, 0));
    Map<String, List<CAS>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(mergeCas.getCas()));
    casByUser.put("user2", asList(jcasA.getCas()));
    DiffResult diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser).toResult();
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(2, diff.getIncompleteConfigurationSets().size());
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) JCasFactory.createJCas(org.apache.uima.fit.factory.JCasFactory.createJCas) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ArrayList(java.util.ArrayList) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult) FSUtil.getFeature(org.apache.uima.fit.util.FSUtil.getFeature) Feature(org.apache.uima.cas.Feature) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

JCasFactory.createJCas (org.apache.uima.fit.factory.JCasFactory.createJCas)8 JCas (org.apache.uima.jcas.JCas)8 ArrayList (java.util.ArrayList)6 Arrays.asList (java.util.Arrays.asList)6 LinkedHashMap (java.util.LinkedHashMap)6 List (java.util.List)6 Test (org.junit.Test)6 DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult)4 Type (org.apache.uima.cas.Type)4 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)4 Feature (org.apache.uima.cas.Feature)3 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)3 FSUtil.getFeature (org.apache.uima.fit.util.FSUtil.getFeature)3 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)3 SpanDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter)2 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)2 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)2 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)2 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)1 AnnotatorStateImpl (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorStateImpl)1