use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class ProjectCasDoctorPanel method createOrReadInitialCasWithoutSaving.
private CAS createOrReadInitialCasWithoutSaving(SourceDocument aDocument, LogMessageSet aMessageSet) throws IOException, UIMAException {
CAS cas;
if (casStorageService.existsCas(aDocument, INITIAL_CAS_PSEUDO_USER)) {
cas = casStorageService.readCas(aDocument, INITIAL_CAS_PSEUDO_USER, UNMANAGED_NON_INITIALIZING_ACCESS);
} else {
cas = importExportService.importCasFromFile(documentService.getSourceDocumentFile(aDocument), aDocument.getProject(), aDocument.getFormat());
aMessageSet.messages.add(new LogMessage(getClass(), LogLevel.INFO, "Created initial CAS for [" + aDocument.getName() + "]"));
}
return cas;
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class ProjectCasDoctorPanel method actionCheck.
private void actionCheck(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
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)) {
// Check INITIAL CAS
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
try {
casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER, (doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet), //
(cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking initial CAS for [{}]", sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Check CORRECTION_USER CAS if necessary
if (WebAnnoConst.PROJECT_TYPE_CORRECTION.equals(project.getMode())) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CORRECTION_USER + "]");
try {
casStorageService.forceActionOnCas(sd, CORRECTION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
} catch (FileNotFoundException e) {
// If there is no CAS for the correction user, then correction has not started
// yet. This is not a problem, so we can ignore it. (REC: I wonder if this
// assumption is correct in curation mode...)
messageSet.messages.add(LogMessage.info(getClass(), "Correction seems to have not yet started."));
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CORRECTION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking annotations for [{}] for [{}]", CORRECTION_USER, sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Check CURATION_USER CAS
{
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + CURATION_USER + "]");
try {
casStorageService.forceActionOnCas(sd, CURATION_USER, (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
} catch (FileNotFoundException e) {
// If there is no CAS for the curation user, then curation has not started yet.
// This is not a problem, so we can ignore it.
messageSet.messages.add(LogMessage.info(getClass(), "Curation seems to have not yet started."));
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations for [" + CURATION_USER + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking annotations for [{}] for [{}]", CURATION_USER, sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
// Check regular annotator CASes
for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
if (documentService.existsAnnotationCas(ad)) {
LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
try {
casStorageService.forceActionOnCas(ad.getDocument(), ad.getUser(), (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), //
(cas) -> casDoctor.analyze(project, cas, messageSet.messages), false);
} catch (Exception e) {
messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error checking annotations of user [" + ad.getUser() + "] for [" + sd.getName() + "]: " + e.getMessage()));
LOG.error("Error checking annotations of user [{}] for [{}]", ad.getUser(), sd.getName(), e);
}
noticeIfThereAreNoMessages(messageSet);
formModel.messageSets.add(messageSet);
}
}
}
aTarget.add(this);
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class AnnotationPageBase method actionValidateDocument.
public void actionValidateDocument(AjaxRequestTarget aTarget, CAS aCas) {
AnnotatorState state = getModelObject();
for (AnnotationLayer layer : annotationService.listAnnotationLayer(state.getProject())) {
if (!layer.isEnabled()) {
// about fixing annotations on disabled layers.
continue;
}
if (ValidationMode.NEVER.equals(layer.getValidationMode())) {
// If validation is disabled, then skip it
continue;
}
TypeAdapter adapter = annotationService.getAdapter(layer);
validateRequiredFeatures(aTarget, aCas, adapter);
List<Pair<LogMessage, AnnotationFS>> messages = adapter.validate(aCas);
if (!messages.isEmpty()) {
LogMessage message = messages.get(0).getLeft();
AnnotationFS fs = messages.get(0).getRight();
// Find the sentence that contains the annotation with the missing
// required feature value and put this sentence into the focus
AnnotationFS s = WebAnnoCasUtil.selectSentenceCovering(aCas, fs.getBegin());
state.setFirstVisibleUnit(s);
actionRefreshDocument(aTarget);
// Inform the user
throw new IllegalStateException("Document cannot be marked as finished. Annotation with ID [" + WebAnnoCasUtil.getAddr(fs) + "] on layer [" + layer.getUiName() + "] is invalid: " + message.getMessage());
}
}
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class SpanOverlapBehavior method onValidate.
@Override
public List<Pair<LogMessage, AnnotationFS>> onValidate(TypeAdapter aAdapter, CAS aCas) {
Type type = getType(aCas, aAdapter.getAnnotationTypeName());
List<Pair<LogMessage, AnnotationFS>> messages = new ArrayList<>();
switch(aAdapter.getLayer().getOverlapMode()) {
case ANY_OVERLAP:
// Nothing to check
break;
case NO_OVERLAP:
{
Set<AnnotationFS> overlapping = new HashSet<>();
Set<AnnotationFS> stacking = new HashSet<>();
overlappingOrStackingSpans(select(aCas, type), stacking, overlapping);
overlapping.forEach(fs -> Pair.of(LogMessage.error(this, "Overlapping annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs));
stacking.forEach(fs -> messages.add(Pair.of(LogMessage.error(this, "Stacked annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs)));
break;
}
case STACKING_ONLY:
// Here, we must find all overlapping relations because they are not permitted
overlappingNonStackingSpans(select(aCas, type)).forEach(fs -> Pair.of(LogMessage.error(this, "Overlapping annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs));
break;
case OVERLAP_ONLY:
stackingSpans(select(aCas, type)).forEach(fs -> messages.add(Pair.of(LogMessage.error(this, "Stacked annotation at [%d-%d]", fs.getBegin(), fs.getEnd()), fs)));
break;
}
return messages;
}
use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.
the class ReindexFeatureAttachedSpanAnnotationsRepair method repair.
@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
Map<FeatureStructure, FeatureStructure> nonIndexed = getNonIndexedFSesWithOwner(aCas);
for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
continue;
}
int count = 0;
// anno -> e.g. Lemma
for (AnnotationFS attach : select(aCas, getType(aCas, layer.getAttachType().getName()))) {
AnnotationFS anno = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
if (anno != null && nonIndexed.containsKey(anno)) {
aCas.addFsToIndexes(anno);
count++;
}
}
if (count > 0) {
aMessages.add(new LogMessage(this, LogLevel.INFO, "Reindexed [%d] unindexed spans in layer [" + layer.getName() + "].", count));
}
}
}
Aggregations