use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class TwoPairedKappaTest method testTwoUserDiffArcAnnotation.
@Test
public void testTwoUserDiffArcAnnotation() throws Exception {
Map<User, List<SourceDocument>> userDocs = new HashMap<>();
userDocs.put(user1, asList(document));
userDocs.put(user2, asList(document));
Map<User, JCas> userCases = new HashMap<>();
userCases.put(user1, kappatestCas.getJCas());
userCases.put(user2, kappaarcdiff.getJCas());
Map<SourceDocument, Map<User, JCas>> documentJCases = new HashMap<>();
documentJCases.put(document, userCases);
// Check against new impl
DiffResult diff = CasDiff2.doDiff(Dependency.class, new ArcDiffAdapter(Dependency.class, "Dependent", "Governor", "DependencyType"), LinkCompareBehavior.LINK_TARGET_AS_LABEL, convert(userCases));
AgreementResult agreement = AgreementUtils.getCohenKappaAgreement(diff, Dependency.class.getName(), "DependencyType", convert(userCases));
// Asserts
System.out.printf("Agreement: %s%n", agreement.toString());
diff.print(System.out);
assertEquals(0.86153d, agreement.getAgreement(), 0.00001d);
assertEquals(9, diff.size());
assertEquals(1, diff.getDifferingConfigurationSets().size());
assertEquals(0, diff.getIncompleteConfigurationSets().size());
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class ProjectCasDoctorPanel method actionRepair.
private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
casStorageService.disableCache();
CasDoctor casDoctor = new CasDoctor();
casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
casDoctor.setFatalChecks(false);
casDoctor.setRepairClasses(formModel.repairs);
Project project = getModelObject();
formModel.messageSets = new ArrayList<>();
for (SourceDocument sd : documentService.listSourceDocuments(project)) {
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
JCas initialCas;
if (documentService.existsInitialCas(sd)) {
initialCas = documentService.readInitialCas(sd, false);
} else {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + sd.getName() + "]"));
initialCas = documentService.createInitialCas(sd, false);
}
casDoctor.repair(project, initialCas.getCas(), messageSet.messages);
CasPersistenceUtils.writeSerializedCas(initialCas, documentService.getCasFile(sd, INITIAL_CAS_PSEUDO_USER));
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
JCas userCas = documentService.readAnnotationCas(ad, false);
casDoctor.repair(project, userCas.getCas(), messageSet.messages);
CasPersistenceUtils.writeSerializedCas(userCas, documentService.getCasFile(ad.getDocument(), ad.getUser()));
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class ProjectCasDoctorPanel method actionCheck.
private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
casStorageService.disableCache();
CasDoctor casDoctor = new CasDoctor();
casDoctor.setApplicationContext(ApplicationContextProvider.getApplicationContext());
casDoctor.setFatalChecks(false);
casDoctor.setCheckClasses(CasDoctor.scanChecks());
Project project = getModelObject();
formModel.messageSets = new ArrayList<>();
for (SourceDocument sd : documentService.listSourceDocuments(project)) {
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
JCas initialCas;
try {
if (documentService.existsInitialCas(sd)) {
initialCas = documentService.readInitialCas(sd, false);
} else {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "No initial CAS for [" + sd.getName() + "]"));
initialCas = documentService.createInitialCas(sd, false);
}
casDoctor.analyze(project, initialCas.getCas(), messageSet.messages);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error reading initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error reading initial CAS for [" + sd.getName() + "]", e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
JCas userCas = documentService.readAnnotationCas(ad, false);
casDoctor.analyze(project, userCas.getCas(), messageSet.messages);
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class ImportDocumentsPanel method actionImport.
private void actionImport(AjaxRequestTarget aTarget, Form<Void> aForm) {
aTarget.addChildren(getPage(), IFeedback.class);
List<FileUpload> uploadedFiles = fileUpload.getFileUploads();
Project project = projectModel.getObject();
if (isEmpty(uploadedFiles)) {
error("No document is selected to upload, please select a document first");
return;
}
if (isNull(project.getId())) {
error("Project not yet created, please save project details!");
return;
}
for (FileUpload documentToUpload : uploadedFiles) {
String fileName = documentToUpload.getClientFileName();
if (documentService.existsSourceDocument(project, fileName)) {
error("Document " + fileName + " already uploaded ! Delete " + "the document if you want to upload again");
continue;
}
try {
SourceDocument document = new SourceDocument();
document.setName(fileName);
document.setProject(project);
document.setFormat(importExportService.getReadableFormatId(format.getObject()));
try (InputStream is = documentToUpload.getInputStream()) {
documentService.uploadSourceDocument(is, document);
}
info("File [" + fileName + "] has been imported successfully!");
} catch (Exception e) {
error("Error while uploading document " + fileName + ": " + ExceptionUtils.getRootCauseMessage(e));
LOG.error(fileName + ": " + e.getMessage(), e);
}
}
WicketUtil.refreshPage(aTarget, getPage());
}
use of de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument in project webanno by webanno.
the class MonitoringPage method getFinishedDocumentsPerUser.
private Map<String, Integer> getFinishedDocumentsPerUser(Project aProject) {
Map<String, Integer> annotatorsProgress = new HashMap<>();
if (aProject != null) {
for (User user : projectService.listProjectUsersWithPermissions(aProject, PermissionLevel.USER)) {
for (SourceDocument document : documentService.listSourceDocuments(aProject)) {
if (documentService.isAnnotationFinished(document, user)) {
if (annotatorsProgress.get(user.getUsername()) == null) {
annotatorsProgress.put(user.getUsername(), 1);
} else {
int previousValue = annotatorsProgress.get(user.getUsername());
annotatorsProgress.put(user.getUsername(), previousValue + 1);
}
}
}
if (annotatorsProgress.get(user.getUsername()) == null) {
annotatorsProgress.put(user.getUsername(), 0);
}
}
}
return annotatorsProgress;
}
Aggregations