use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult 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());
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.
the class CasDiffTest method singleNoDifferencesTest.
@Test
public void singleNoDifferencesTest() throws Exception {
Map<String, List<CAS>> casByUser = load("casdiff/singleSpanNoDifference/data.conll", "casdiff/singleSpanNoDifference/data.conll");
List<? extends DiffAdapter> diffAdapters = asList(new SpanDiffAdapter(POS.class.getName(), "PosValue"));
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 = getCohenKappaAgreement(diff, entryTypes.get(0),
// "PosValue", casByUser);
// assertEquals(NaN, agreement.getAgreement(), 0.000001d);
// assertEquals(0, agreement.getIncompleteSetsByPosition().size());
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.
the class CasDiffTest method noDifferencesPosDependencyTest.
@Test
public void noDifferencesPosDependencyTest() throws Exception {
Map<String, List<CAS>> casByUser = load("casdiff/noDifferences/data.conll", "casdiff/noDifferences/data.conll");
List<? extends DiffAdapter> diffAdapters = asList(POS_DIFF_ADAPTER, DEPENDENCY_DIFF_ADAPTER);
CasDiff diff = doDiff(diffAdapters, LINK_TARGET_AS_LABEL, casByUser);
DiffResult result = diff.toResult();
// result.print(System.out);
assertEquals(52, result.size());
assertEquals(26, result.size(POS.class.getName()));
assertEquals(26, result.size(Dependency.class.getName()));
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,
// entryTypes.get(0), "PosValue", casByUser);
// assertEquals(1.0d, agreement.getAgreement(), 0.000001d);
// assertEquals(0, agreement.getIncompleteSetsByPosition().size());
}
use of de.tudarmstadt.ukp.clarin.webanno.curation.casdiff.CasDiff.DiffResult in project webanno by webanno.
the class SuggestionBuilder method buildCurationContainer.
public CurationContainer buildCurationContainer(AnnotatorState aState) throws UIMAException, ClassNotFoundException, IOException, AnnotationException {
CurationContainer curationContainer = new CurationContainer();
// initialize Variables
SourceDocument sourceDocument = aState.getDocument();
Map<Integer, Integer> segmentBeginEnd = new HashMap<>();
Map<Integer, Integer> segmentNumber = new HashMap<>();
Map<String, Map<Integer, Integer>> segmentAdress = new HashMap<>();
// get annotation documents
List<AnnotationDocument> finishedAnnotationDocuments = new ArrayList<>();
for (AnnotationDocument annotationDocument : documentService.listAnnotationDocuments(aState.getDocument())) {
if (annotationDocument.getState().equals(AnnotationDocumentState.FINISHED)) {
finishedAnnotationDocuments.add(annotationDocument);
}
}
Map<String, CAS> casses = new HashMap<>();
AnnotationDocument randomAnnotationDocument = null;
CAS mergeCas;
// get the correction/automation CAS for the logged in user
if (aState.getMode().equals(AUTOMATION) || aState.getMode().equals(CORRECTION)) {
casses = listCasesforCorrection(randomAnnotationDocument, sourceDocument, aState.getMode());
mergeCas = getMergeCas(aState, sourceDocument, casses, randomAnnotationDocument, false, false, false);
String username = casses.keySet().iterator().next();
updateSegment(aState, segmentBeginEnd, segmentNumber, segmentAdress, casses.get(username), username, aState.getWindowBeginOffset(), aState.getWindowEndOffset());
} else {
casses = listCassesforCuration(finishedAnnotationDocuments, aState.getMode());
mergeCas = getMergeCas(aState, sourceDocument, casses, randomAnnotationDocument, false, false, false);
updateSegment(aState, segmentBeginEnd, segmentNumber, segmentAdress, mergeCas, CURATION_USER, getFirstSentence(mergeCas).getBegin(), mergeCas.getDocumentText().length());
}
segmentAdress.put(CURATION_USER, new HashMap<>());
Type sentenceType = getType(mergeCas, Sentence.class);
for (AnnotationFS s : selectCovered(mergeCas, sentenceType, diffRangeBegin, diffRangeEnd)) {
segmentAdress.get(CURATION_USER).put(s.getBegin(), getAddr(s));
}
List<DiffAdapter> adapters = getDiffAdapters(schemaService, aState.getAnnotationLayers());
long diffStart = System.currentTimeMillis();
log.debug("Calculating differences...");
int count = 0;
for (Integer begin : segmentBeginEnd.keySet()) {
Integer end = segmentBeginEnd.get(begin);
count++;
if (count % 100 == 0) {
log.debug("Processing differences: {} of {} sentences...", count, segmentBeginEnd.size());
}
DiffResult diff = doDiffSingle(adapters, LINK_ROLE_AS_LABEL, casses, begin, end).toResult();
SourceListView curationSegment = new SourceListView();
curationSegment.setBegin(begin);
curationSegment.setEnd(end);
curationSegment.setSentenceNumber(segmentNumber.get(begin));
if (diff.hasDifferences() || !diff.getIncompleteConfigurationSets().isEmpty()) {
// Is this confSet a diff due to stacked annotations (with same configuration)?
boolean stackedDiff = false;
stackedDiffSet: for (ConfigurationSet d : diff.getDifferingConfigurationSets().values()) {
for (Configuration c : d.getConfigurations()) {
if (c.getCasGroupIds().size() != d.getCasGroupIds().size()) {
stackedDiff = true;
break stackedDiffSet;
}
}
}
if (stackedDiff) {
curationSegment.setSentenceState(DISAGREE);
} else if (!diff.getIncompleteConfigurationSets().isEmpty()) {
curationSegment.setSentenceState(DISAGREE);
} else {
curationSegment.setSentenceState(AGREE);
}
} else {
curationSegment.setSentenceState(AGREE);
}
for (String username : segmentAdress.keySet()) {
curationSegment.getSentenceAddress().put(username, segmentAdress.get(username).get(begin));
}
curationContainer.getCurationViewByBegin().put(begin, curationSegment);
}
log.debug("Difference calculation completed in {}ms", (System.currentTimeMillis() - diffStart));
return curationContainer;
}
Aggregations