Search in sources :

Example 36 with CasDiff2

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

the class MergeCasTest method simpleSpanDiffWithLabelTest.

@Test
public void simpleSpanDiffWithLabelTest() throws Exception {
    Map<String, List<JCas>> casByUser = DiffUtils.loadWebAnnoTSV(null, "mergecas/simplespan/1sentenceposlabel.tsv", "mergecas/simplespan/1sentenceposlabel2.tsv");
    List<String> entryTypes = asList(POS.class.getName());
    List<SpanDiffAdapter> diffAdapters = asList(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/simplespan/1sentenceempty.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 : POS(de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS) 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) Test(org.junit.Test)

Example 37 with CasDiff2

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

the class MergeCasTest method simpleRelGovDiffTest.

@Test
public void simpleRelGovDiffTest() throws Exception {
    Map<String, List<JCas>> casByUser = DiffUtils.loadWebAnnoTSV(null, "mergecas/rels/1sentencesamerel.tsv", "mergecas/rels/1sentencesamerel2.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/1sentencesamerel3.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 38 with CasDiff2

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

the class MergeCasTest method multiLinkMultiSpanRoleDiffTest.

@Test
public void multiLinkMultiSpanRoleDiffTest() throws Exception {
    JCas jcasA = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    Type type = jcasA.getTypeSystem().getType(DiffUtils.HOST_TYPE);
    Feature feature = type.getFeatureByBaseName("f1");
    DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasA, 0, 0, feature, "A", DiffUtils.makeLinkFS(jcasA, "slot1", 0, 0));
    JCas jcasB = JCasFactory.createJCas(DiffUtils.createMultiLinkWithRoleTestTypeSytem("f1"));
    DiffUtils.makeLinkHostMultiSPanFeatureFS(jcasB, 0, 0, feature, "A", 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);
}
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) Feature(org.apache.uima.cas.Feature) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 39 with CasDiff2

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

the class MergeCasTest method relStackedTest.

@Test
public void relStackedTest() throws Exception {
    TypeSystemDescription customeTypesSpan = DiffUtils.createCustomTypeSystem(SPAN_TYPE, "webanno.custom.Multivalspan", asList("f1", "f2"), null);
    TypeSystemDescription customeTypesRel = DiffUtils.createCustomTypeSystem(RELATION_TYPE, "webanno.custom.Multivalrel", asList("rel1", "rel2"), "webanno.custom.Multivalspan");
    List<TypeSystemDescription> customTypes = new ArrayList<>();
    customTypes.add(customeTypesSpan);
    customTypes.add(customeTypesRel);
    TypeSystemDescription customType = CasCreationUtils.mergeTypeSystems(customTypes);
    Map<String, List<JCas>> casByUser = DiffUtils.loadXMI(customType, "mergecas/multivalspanrel/stackedrel1.xmi", "mergecas/multivalspanrel/stackedrel2.xmi");
    List<String> entryTypes = asList("webanno.custom.Multivalspan", "webanno.custom.Multivalrel");
    List<? extends DiffAdapter> diffAdapters = asList(new ArcDiffAdapter("webanno.custom.Multivalrel", "Dependent", "Governor", "rel1", "rel2"), new SpanDiffAdapter("webanno.custom.Multivalspan", "f1", "f2"));
    addRandomMergeCas(casByUser);
    DiffResult result = CasDiff2.doDiff(entryTypes, diffAdapters, LinkCompareBehavior.LINK_TARGET_AS_LABEL, casByUser);
    JCas mergeCas = MergeCas.reMergeCas(result, getSingleCasByUser(casByUser));
    JCas actual = DiffUtils.readXMI("mergecas/multivalspanrel/stackedmerge.xmi", customType);
    Type relType = mergeCas.getTypeSystem().getType("webanno.custom.Multivalrel");
    int numRelMerge = CasUtil.select(mergeCas.getCas(), relType).size();
    int numRelActual = CasUtil.select(actual.getCas(), relType).size();
    Type spanType = mergeCas.getTypeSystem().getType("webanno.custom.Multivalspan");
    int numspanMerge = CasUtil.select(mergeCas.getCas(), spanType).size();
    int numspanActual = CasUtil.select(actual.getCas(), spanType).size();
    assertEquals(2, numRelMerge);
    assertEquals(2, numRelActual);
    assertEquals(4, numspanMerge);
    assertEquals(4, numspanActual);
}
Also used : TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) ArcDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcDiffAdapter) SpanDiffAdapter(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter) ArrayList(java.util.ArrayList) JCas(org.apache.uima.jcas.JCas) Type(org.apache.uima.cas.Type) 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 40 with CasDiff2

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

the class SuggestionViewPanel method calcColors.

private Map<String, Map<VID, AnnotationState>> calcColors(AnnotatorState state, SourceListView aCurationSegment, JCas annotatorCas, Map<String, JCas> jCases) {
    // get differing feature structures
    List<Type> entryTypes = SuggestionBuilder.getEntryTypes(annotatorCas, state.getAnnotationLayers(), annotationService);
    Map<String, Map<VID, AnnotationState>> annoStates = new HashMap<>();
    DiffResult diff;
    if (state.getMode().equals(Mode.CURATION)) {
        diff = CasDiff2.doDiffSingle(annotationService, state.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, aCurationSegment.getCurationBegin(), aCurationSegment.getCurationEnd());
    } else {
        diff = CasDiff2.doDiffSingle(annotationService, state.getProject(), entryTypes, LinkCompareBehavior.LINK_ROLE_AS_LABEL, jCases, aCurationSegment.getBegin(), aCurationSegment.getEnd());
    }
    Collection<ConfigurationSet> d = diff.getDifferingConfigurationSets().values();
    Collection<ConfigurationSet> i = diff.getIncompleteConfigurationSets().values();
    for (ConfigurationSet cfgSet : d) {
        if (i.contains(cfgSet)) {
            i.remove(cfgSet);
        }
    }
    addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, d, false, false);
    addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, i, true, false);
    List<ConfigurationSet> all = new ArrayList<>();
    all.addAll(diff.getConfigurationSets());
    all.removeAll(d);
    all.removeAll(i);
    addSuggestionColor(state.getProject(), state.getMode(), jCases, annoStates, all, false, true);
    return annoStates;
}
Also used : ConfigurationSet(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ConfigurationSet) Type(org.apache.uima.cas.Type) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) DiffResult(de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

DiffResult (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.DiffResult)52 List (java.util.List)52 Arrays.asList (java.util.Arrays.asList)51 Test (org.junit.Test)51 ArrayList (java.util.ArrayList)48 JCas (org.apache.uima.jcas.JCas)44 SpanDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.SpanDiffAdapter)37 LinkedHashMap (java.util.LinkedHashMap)26 AgreementResult (de.tudarmstadt.ukp.clarin.webanno.curation.agreement.AgreementUtils.AgreementResult)24 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)20 ArcDiffAdapter (de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff2.ArcDiffAdapter)12 Type (org.apache.uima.cas.Type)12 Dependency (de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency)11 HashMap (java.util.HashMap)8 Map (java.util.Map)8 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)6 User (de.tudarmstadt.ukp.clarin.webanno.security.model.User)5 FeatureStructure (org.apache.uima.cas.FeatureStructure)5 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)5 NamedEntity (de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity)4