use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.
the class CasDiffTest method multiLinkWithRoleNoDifferenceTest.
@Test
public void multiLinkWithRoleNoDifferenceTest() throws Exception {
JCas jcasA = createJCas(createMultiLinkWithRoleTestTypeSystem());
makeLinkHostFS(jcasA, 0, 0, makeLinkFS(jcasA, "slot1", 0, 0));
makeLinkHostFS(jcasA, 10, 10, makeLinkFS(jcasA, "slot1", 10, 10));
JCas jcasB = createJCas(createMultiLinkWithRoleTestTypeSystem());
makeLinkHostFS(jcasB, 0, 0, makeLinkFS(jcasB, "slot1", 0, 0));
makeLinkHostFS(jcasB, 10, 10, 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);
CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
DiffResult result = diff.toResult();
// result.print(System.out);
assertEquals(4, 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 = getCohenKappaAgreement(diff, HOST_TYPE, "links",
// casByUser);
//
// // Asserts
// System.out.printf("Agreement: %s%n", agreement.toString());
// AgreementUtils.dumpAgreementStudy(System.out, agreement);
//
// assertEquals(1.0d, agreement.getAgreement(), 0.00001d);
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.
the class CasDiffTest method multiLinkWithRoleLabelDifferenceTest2.
@Test
public void multiLinkWithRoleLabelDifferenceTest2() throws Exception {
JCas jcasA = createJCas(createMultiLinkWithRoleTestTypeSystem());
makeLinkHostFS(jcasA, 0, 0, makeLinkFS(jcasA, "slot1", 0, 0));
JCas jcasB = createJCas(createMultiLinkWithRoleTestTypeSystem());
makeLinkHostFS(jcasB, 0, 0, makeLinkFS(jcasB, "slot2", 0, 0));
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);
CasDiff diff = doDiff(diffAdapters, LINK_ROLE_AS_LABEL, casByUser);
DiffResult result = diff.toResult();
// result.print(System.out);
assertEquals(2, result.size());
assertEquals(1, 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, HOST_TYPE,
// "links", casByUser);
//
// // Asserts
// System.out.printf("Agreement: %s%n", agreement.toString());
// AgreementUtils.dumpAgreementStudy(System.out, agreement);
//
// assertEquals(0.0d, agreement.getAgreement(), 0.00001d);
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.
the class CasDiffTest method singleDifferencesTest.
@Test
public void singleDifferencesTest() throws Exception {
Map<String, List<CAS>> casByUser = load("casdiff/singleSpanDifference/user1.conll", "casdiff/singleSpanDifference/user2.conll");
List<SpanDiffAdapter> diffAdapters = asList(SpanDiffAdapter.POS_DIFF_ADAPTER);
CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
DiffResult result = diff.toResult();
// result.print(System.out);
assertEquals(1, result.size());
assertEquals(1, 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,
// entryTypes.get(0), "PosValue", casByUser);
// assertEquals(0.0d, agreement.getAgreement(), 0.000001d);
// assertEquals(0, agreement.getIncompleteSetsByPosition().size());
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.
the class CasMergeTestBase method setup.
@Before
public void setup() throws Exception {
initMocks(this);
SpanDiffAdapter slotHostDiffAdapter = new SpanDiffAdapter(HOST_TYPE);
slotHostDiffAdapter.addLinkFeature("links", "role", "target");
diffAdapters = new ArrayList<>();
diffAdapters.add(TOKEN_DIFF_ADAPTER);
diffAdapters.add(SENTENCE_DIFF_ADAPTER);
diffAdapters.add(POS_DIFF_ADAPTER);
diffAdapters.add(NER_DIFF_ADAPTER);
diffAdapters.add(DEPENDENCY_DIFF_ADAPTER);
diffAdapters.add(MULTIVALREL_DIFF_ADAPTER);
diffAdapters.add(MULTIVALSPAN_DIFF_ADAPTER);
diffAdapters.add(slotHostDiffAdapter);
project = new Project();
document = new SourceDocument();
document.setProject(project);
document.setName("document");
sentenceLayer = new AnnotationLayer(Sentence.class.getName(), "Sentence", SPAN_TYPE, null, true, CHARACTERS, NO_OVERLAP);
tokenLayer = new AnnotationLayer(Token.class.getName(), "Token", SPAN_TYPE, null, true, CHARACTERS, NO_OVERLAP);
tokenPosFeature = new AnnotationFeature();
tokenPosFeature.setName("pos");
tokenPosFeature.setEnabled(true);
tokenPosFeature.setType(POS.class.getName());
tokenPosFeature.setUiName("pos");
tokenPosFeature.setLayer(tokenLayer);
tokenPosFeature.setProject(project);
tokenPosFeature.setVisible(true);
posLayer = new AnnotationLayer(POS.class.getName(), "POS", SPAN_TYPE, project, true, SINGLE_TOKEN, NO_OVERLAP);
posLayer.setAttachType(tokenLayer);
posLayer.setAttachFeature(tokenPosFeature);
posFeature = new AnnotationFeature();
posFeature.setName("PosValue");
posFeature.setEnabled(true);
posFeature.setType(CAS.TYPE_NAME_STRING);
posFeature.setUiName("PosValue");
posFeature.setLayer(posLayer);
posFeature.setProject(project);
posFeature.setVisible(true);
posCoarseFeature = new AnnotationFeature();
posCoarseFeature.setName("coarseValue");
posCoarseFeature.setEnabled(true);
posCoarseFeature.setType(CAS.TYPE_NAME_STRING);
posCoarseFeature.setUiName("coarseValue");
posCoarseFeature.setLayer(posLayer);
posCoarseFeature.setProject(project);
posCoarseFeature.setVisible(true);
neLayer = new AnnotationLayer(NamedEntity.class.getName(), "Named Entity", SPAN_TYPE, project, true, TOKENS, OVERLAP_ONLY);
neFeature = new AnnotationFeature();
neFeature.setName("value");
neFeature.setEnabled(true);
neFeature.setType(CAS.TYPE_NAME_STRING);
neFeature.setUiName("value");
neFeature.setLayer(neLayer);
neFeature.setProject(project);
neFeature.setVisible(true);
neIdentifierFeature = new AnnotationFeature();
neIdentifierFeature.setName("identifier");
neIdentifierFeature.setEnabled(true);
neIdentifierFeature.setType(CAS.TYPE_NAME_STRING);
neIdentifierFeature.setUiName("identifier");
neIdentifierFeature.setLayer(neLayer);
neIdentifierFeature.setProject(project);
neIdentifierFeature.setVisible(true);
depLayer = new AnnotationLayer(Dependency.class.getName(), "Dependency", RELATION_TYPE, project, true, SINGLE_TOKEN, OVERLAP_ONLY);
depLayer.setAttachType(tokenLayer);
depLayer.setAttachFeature(tokenPosFeature);
depFeature = new AnnotationFeature();
depFeature.setName("DependencyType");
depFeature.setEnabled(true);
depFeature.setType(CAS.TYPE_NAME_STRING);
depFeature.setUiName("Relation");
depFeature.setLayer(depLayer);
depFeature.setProject(project);
depFeature.setVisible(true);
depFlavorFeature = new AnnotationFeature();
depFlavorFeature.setName("flavor");
depFlavorFeature.setEnabled(true);
depFlavorFeature.setType(CAS.TYPE_NAME_STRING);
depFlavorFeature.setUiName("flavor");
depFlavorFeature.setLayer(depLayer);
depFlavorFeature.setProject(project);
depFlavorFeature.setVisible(true);
slotLayer = new AnnotationLayer(HOST_TYPE, HOST_TYPE, SPAN_TYPE, project, false, SINGLE_TOKEN, NO_OVERLAP);
slotFeature = new AnnotationFeature();
slotFeature.setName("links");
slotFeature.setEnabled(true);
slotFeature.setType(Token.class.getName());
slotFeature.setMode(MultiValueMode.ARRAY);
slotFeature.setLinkMode(LinkMode.WITH_ROLE);
slotFeature.setLinkTypeName(CurationTestUtils.LINK_TYPE);
slotFeature.setLinkTypeRoleFeatureName("role");
slotFeature.setLinkTypeTargetFeatureName("target");
slotFeature.setUiName("links");
slotFeature.setLayer(slotLayer);
slotFeature.setProject(project);
slotFeature.setVisible(true);
stringFeature = new AnnotationFeature();
stringFeature.setName("f1");
stringFeature.setEnabled(true);
stringFeature.setType(CAS.TYPE_NAME_STRING);
stringFeature.setUiName("f1");
stringFeature.setLayer(slotLayer);
stringFeature.setProject(project);
stringFeature.setVisible(true);
multiValSpan = new AnnotationLayer("webanno.custom.Multivalspan", "Multivalspan", SPAN_TYPE, project, true, TOKENS, OVERLAP_ONLY);
multiValSpanF1 = new AnnotationFeature();
multiValSpanF1.setName("f1");
multiValSpanF1.setEnabled(true);
multiValSpanF1.setType(CAS.TYPE_NAME_STRING);
multiValSpanF1.setUiName("f1");
multiValSpanF1.setLayer(multiValSpan);
multiValSpanF1.setProject(project);
multiValSpanF1.setVisible(true);
multiValSpanF2 = new AnnotationFeature();
multiValSpanF2.setName("f2");
multiValSpanF2.setEnabled(true);
multiValSpanF2.setType(CAS.TYPE_NAME_STRING);
multiValSpanF2.setUiName("f2");
multiValSpanF2.setLayer(multiValSpan);
multiValSpanF2.setProject(project);
multiValSpanF2.setVisible(true);
multiValRel = new AnnotationLayer("webanno.custom.Multivalrel", "Multivalrel", RELATION_TYPE, project, true, SINGLE_TOKEN, OVERLAP_ONLY);
multiValRel.setAttachType(multiValSpan);
multiValRelRel1 = new AnnotationFeature();
multiValRelRel1.setName("rel1");
multiValRelRel1.setEnabled(true);
multiValRelRel1.setType(CAS.TYPE_NAME_STRING);
multiValRelRel1.setUiName("rel1");
multiValRelRel1.setLayer(multiValSpan);
multiValRelRel1.setProject(project);
multiValRelRel1.setVisible(true);
multiValRelRel2 = new AnnotationFeature();
multiValRelRel2.setName("rel2");
multiValRelRel2.setEnabled(true);
multiValRelRel2.setType(CAS.TYPE_NAME_STRING);
multiValRelRel2.setUiName("rel2");
multiValRelRel2.setLayer(multiValSpan);
multiValRelRel2.setProject(project);
multiValRelRel2.setVisible(true);
when(schemaService.findLayer(any(Project.class), any(String.class))).thenAnswer(call -> {
String type = call.getArgument(1, String.class);
if (type.equals(Sentence.class.getName())) {
return sentenceLayer;
}
if (type.equals(Token.class.getName())) {
return tokenLayer;
}
if (type.equals(Dependency.class.getName())) {
return depLayer;
}
if (type.equals(POS.class.getName())) {
return posLayer;
}
if (type.equals(NamedEntity.class.getName())) {
return neLayer;
}
if (type.equals(CurationTestUtils.HOST_TYPE)) {
return slotLayer;
}
if (type.equals("webanno.custom.Multivalrel")) {
return multiValRel;
}
if (type.equals("webanno.custom.Multivalspan")) {
return multiValSpan;
}
throw new IllegalStateException("Unknown layer type: " + type);
});
when(schemaService.listSupportedFeatures((any(AnnotationLayer.class)))).thenAnswer(call -> schemaService.listAnnotationFeature(call.getArgument(0, AnnotationLayer.class)));
when(schemaService.listAnnotationFeature(any(AnnotationLayer.class))).thenAnswer(call -> {
AnnotationLayer type = call.getArgument(0, AnnotationLayer.class);
if (type.getName().equals(Sentence.class.getName())) {
return asList();
}
if (type.getName().equals(Token.class.getName())) {
return asList();
}
if (type.getName().equals(Dependency.class.getName())) {
return asList(depFeature, depFlavorFeature);
}
if (type.getName().equals(POS.class.getName())) {
return asList(posFeature, posCoarseFeature);
}
if (type.getName().equals(NamedEntity.class.getName())) {
return asList(neFeature, neIdentifierFeature);
}
if (type.getName().equals(HOST_TYPE)) {
return asList(slotFeature, stringFeature);
}
if (type.getName().equals("webanno.custom.Multivalrel")) {
return asList(multiValRelRel1, multiValRelRel2);
}
if (type.getName().equals("webanno.custom.Multivalspan")) {
return asList(multiValSpanF1, multiValSpanF2);
}
throw new IllegalStateException("Unknown layer type: " + type.getName());
});
when(schemaService.getAdapter(any(AnnotationLayer.class))).thenAnswer(call -> {
AnnotationLayer type = call.getArgument(0, AnnotationLayer.class);
return layerSupportRegistry.getLayerSupport(type).createAdapter(type, () -> schemaService.listAnnotationFeature(type));
});
featureSupportRegistry = new FeatureSupportRegistryImpl(asList(new StringFeatureSupport(), new BooleanFeatureSupport(), new NumberFeatureSupport(), new SlotFeatureSupport(schemaService)));
featureSupportRegistry.init();
LayerBehaviorRegistryImpl layerBehaviorRegistry = new LayerBehaviorRegistryImpl(asList());
layerBehaviorRegistry.init();
layerSupportRegistry = new LayerSupportRegistryImpl(asList(new SpanLayerSupport(featureSupportRegistry, null, layerBehaviorRegistry), new RelationLayerSupport(featureSupportRegistry, null, layerBehaviorRegistry), new ChainLayerSupport(featureSupportRegistry, null, layerBehaviorRegistry)));
layerSupportRegistry.init();
sut = new CasMerge(schemaService);
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.span.SpanDiffAdapter in project webanno by webanno.
the class CasDiffTest method multiLinkWithRoleTargetDifferenceTest.
@Test
public void multiLinkWithRoleTargetDifferenceTest() throws Exception {
JCas jcasA = createJCas(createMultiLinkWithRoleTestTypeSystem());
makeLinkHostFS(jcasA, 0, 0, makeLinkFS(jcasA, "slot1", 0, 0));
JCas jcasB = 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);
CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
DiffResult result = diff.toResult();
// result.print(System.out);
assertEquals(2, result.size());
assertEquals(1, result.getDifferingConfigurationSets().size());
assertEquals(0, result.getIncompleteConfigurationSets().size());
// Todo: Agreement has moved to separate project - should create agreement test there
// CodingAgreementResult agreement = 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);
}
Aggregations