Search in sources :

Example 11 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffAdapter in project webanno by webanno.

the class MergeCasTest method multiLinkMultiHostTest.

@Test
public void multiLinkMultiHostTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot1", 0, 0));
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));
    casByUser.put(CURATION_USER, asList(jcasB));
    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
    SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);
    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    result.print(System.out);
    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
    Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();
    assertEquals(0, numHost);
}
Also used : Type(org.apache.uima.cas.Type) SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter) JCas(org.apache.uima.jcas.JCas) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 12 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffAdapter in project webanno by webanno.

the class MergeCasTest method simpleRelTypeDiffTest.

@Test
public void simpleRelTypeDiffTest() throws Exception {
    Map<String, List<JCas>> casByUser = DiffUtils.loadWebAnnoTSV(null, "mergecas/rels/1sentencesamerel.tsv", "mergecas/rels/1sentencesamerel4.tsv");
    List<String> entryTypes = asList(Dependency.class.getName(), POS.class.getName());
    List<? extends DiffAdapter> diffAdapters = asList(new ArcDiffAdapter(Dependency.class.getName(), "Dependent", "Governor", "DependencyType"), SpanDiffAdapter.POS);
    addRandomMergeCas(casByUser);
    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
    casByUser = new HashMap<>();
    JCas actual = DiffUtils.readWebAnnoTSV("mergecas/rels/1sentencesamerel5.tsv", null);
    casByUser.put("actual", asList(actual));
    casByUser.put("merge", asList(mergeCas));
    result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    assertEquals(0, result.getDifferingConfigurationSets().size());
    assertEquals(0, result.getIncompleteConfigurationSets().size());
}
Also used : ArcDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcDiffAdapter) POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) JCas(org.apache.uima.jcas.JCas) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Dependency(de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Test(org.junit.Test)

Example 13 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffAdapter in project webanno by webanno.

the class MergeCasTest method multiLinkWithRoleTargetDifferenceTest.

@Test
public void multiLinkWithRoleTargetDifferenceTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot1", 10, 10));
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));
    casByUser.put(CURATION_USER, asList(jcasA));
    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
    SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);
    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    result.print(System.out);
    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
    Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();
    assertEquals(1, numHost);
    for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
        ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
        assertEquals(0, linkFss.toArray().length);
    }
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter) JCas(org.apache.uima.jcas.JCas) LinkedHashMap(java.util.LinkedHashMap) FeatureStructure(org.apache.uima.cas.FeatureStructure) Type(org.apache.uima.cas.Type) ArrayFS(org.apache.uima.cas.ArrayFS) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Test(org.junit.Test)

Example 14 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffAdapter in project webanno by webanno.

the class MergeCasTest method multiLinkWithRoleLabelDifferenceTest.

@Test
public void multiLinkWithRoleLabelDifferenceTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasA, 0, 0, DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem());
    DiffUtils.makeLinkHostFS(jcasB, 0, 0, DiffUtils.makeLinkFS(jcasB, "slot2", 0, 0));
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(jcasA));
    casByUser.put("user2", asList(jcasB));
    casByUser.put(CURATION_USER, asList(jcasA));
    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
    SpanDiffAdapter adapter = new SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends DiffAdapter> diffAdapters = asList(adapter);
    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    result.print(System.out);
    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
    Type hostType = mergeCas.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    int numHost = CasUtil.select(mergeCas.getCas(), hostType).size();
    assertEquals(1, numHost);
    for (FeatureStructure host : CasUtil.select(mergeCas.getCas(), hostType)) {
        ArrayFS linkFss = (ArrayFS) WebAnnoCasUtil.getFeatureFS(host, "links");
        assertEquals(0, linkFss.toArray().length);
    }
}
Also used : SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter) JCas(org.apache.uima.jcas.JCas) LinkedHashMap(java.util.LinkedHashMap) FeatureStructure(org.apache.uima.cas.FeatureStructure) Type(org.apache.uima.cas.Type) ArrayFS(org.apache.uima.cas.ArrayFS) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Test(org.junit.Test)

Example 15 with DiffAdapter

use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffAdapter in project webanno by webanno.

the class CopyAnnotationTest method copyLinkToEmptyTest.

@Test
public void copyLinkToEmptyTest() throws Exception {
    JCas mergeCAs = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    Type type = mergeCAs.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");
    AnnotationFS mergeFs = DiffUtils.makeLinkHostMultiSPanFeatureFS(mergeCAs, 0, 0, feature, "A");
    FeatureStructure copyFS = DiffUtils.makeLinkFS(mergeCAs, "slot1", 0, 0);
    List<FeatureStructure> linkFs = new ArrayList<>();
    linkFs.add(copyFS);
    WebAnnoCasUtil.setLinkFeatureValue(mergeFs, type.getFeatureByBaseName("links"), linkFs);
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    Map<String, List<JCas>> casByUser = new LinkedHashMap<>();
    casByUser.put("user1", asList(mergeCAs));
    casByUser.put("user2", asList(jcasA));
    List<String> entryTypes = asList(DiffUtils.HOST_TYPE);
    CasDiff2.SpanDiffAdapter adapter = new CasDiff2.SpanDiffAdapter(DiffUtils.HOST_TYPE);
    adapter.addLinkFeature("links", "role", "target");
    List<? extends CasDiff2.DiffAdapter> diffAdapters = asList(adapter);
    CasDiff2.DiffResult diff = CasDiff2.doDiff(entryTypes, diffAdapters, CasDiff2.LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    assertEquals(0, diff.getDifferingConfigurationSets().size());
    assertEquals(0, diff.getIncompleteConfigurationSets().size());
}
Also used : CasDiff2(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) LinkedHashMap(java.util.LinkedHashMap) FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)27 Arrays.asList (java.util.Arrays.asList)27 List (java.util.List)27 Test (org.junit.Test)27 DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult)25 JCas (org.apache.uima.jcas.JCas)20 SpanDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter)16 LinkedHashMap (java.util.LinkedHashMap)15 AgreementResult (de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult)11 ArcDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcDiffAdapter)10 Dependency (de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency)8 Type (org.apache.uima.cas.Type)8 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)6 FeatureStructure (org.apache.uima.cas.FeatureStructure)4 Feature (org.apache.uima.cas.Feature)3 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)3 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)3 CasDiff2 (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2)2 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)2 ArrayFS (org.apache.uima.cas.ArrayFS)2