Search in sources :

Example 11 with LogMessage

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;
}
Also used : CAS(org.apache.uima.cas.CAS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage)

Example 12 with LogMessage

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);
}
Also used : Form(org.apache.wicket.markup.html.form.Form) SpringBean(org.apache.wicket.spring.injection.annot.SpringBean) CORRECTION_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER) Safe(de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair.Safe) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) LoggerFactory(org.slf4j.LoggerFactory) CasStorageService(de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService) CAS(org.apache.uima.cas.CAS) CURATION_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CURATION_USER) UNMANAGED_NON_INITIALIZING_ACCESS(de.tudarmstadt.ukp.clarin.webanno.api.casstorage.CasAccessMode.UNMANAGED_NON_INITIALIZING_ACCESS) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) AjaxRequestTarget(org.apache.wicket.ajax.AjaxRequestTarget) CheckBoxMultipleChoice(org.apache.wicket.markup.html.form.CheckBoxMultipleChoice) Repair(de.tudarmstadt.ukp.clarin.webanno.diag.repairs.Repair) ChoiceRenderer(org.apache.wicket.markup.html.form.ChoiceRenderer) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) INITIAL_CAS_PSEUDO_USER(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.INITIAL_CAS_PSEUDO_USER) IModel(org.apache.wicket.model.IModel) ListView(org.apache.wicket.markup.html.list.ListView) UIMAException(org.apache.uima.UIMAException) Label(org.apache.wicket.markup.html.basic.Label) LabelPosition(org.apache.wicket.markup.html.form.AbstractChoice.LabelPosition) PROJECT_TYPE_CORRECTION(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.PROJECT_TYPE_CORRECTION) DocumentService(de.tudarmstadt.ukp.clarin.webanno.api.DocumentService) LogLevel(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogLevel) Logger(org.slf4j.Logger) CURATION_IN_PROGRESS(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState.CURATION_IN_PROGRESS) ListItem(org.apache.wicket.markup.html.list.ListItem) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) CurationDocumentService(de.tudarmstadt.ukp.clarin.webanno.curation.storage.CurationDocumentService) ProjectSettingsPanelBase(de.tudarmstadt.ukp.clarin.webanno.ui.core.settings.ProjectSettingsPanelBase) CURATION_FINISHED(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocumentState.CURATION_FINISHED) IOException(java.io.IOException) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) LambdaAjaxButton(de.tudarmstadt.ukp.clarin.webanno.support.lambda.LambdaAjaxButton) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) Serializable(java.io.Serializable) List(java.util.List) PropertyModel(org.apache.wicket.model.PropertyModel) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) ApplicationContextProvider(de.tudarmstadt.ukp.clarin.webanno.support.ApplicationContextProvider) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) ImportExportService(de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService) Project(de.tudarmstadt.ukp.clarin.webanno.model.Project) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) SourceDocument(de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument) FileNotFoundException(java.io.FileNotFoundException) AnnotationDocument(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument) UIMAException(org.apache.uima.UIMAException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 13 with LogMessage

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());
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) AnnotatorState(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState) TypeAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) Pair(org.apache.commons.lang3.tuple.Pair)

Example 14 with LogMessage

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;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) CAS(org.apache.uima.cas.CAS) AnnotationException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException) ArrayList(java.util.ArrayList) Type(org.apache.uima.cas.Type) WebAnnoCasUtil.selectOverlapping(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.selectOverlapping) HashSet(java.util.HashSet) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) WebAnnoConst(de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst) CasUtil.select(org.apache.uima.fit.util.CasUtil.select) CasUtil.selectAt(org.apache.uima.fit.util.CasUtil.selectAt) Collection(java.util.Collection) VComment(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VComment) ERROR(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VCommentType.ERROR) Set(java.util.Set) LayerSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.LayerSupport) Collectors(java.util.stream.Collectors) VSpan(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VSpan) List(java.util.List) Component(org.springframework.stereotype.Component) ChainLayerSupport(de.tudarmstadt.ukp.clarin.webanno.api.annotation.layer.ChainLayerSupport) OverlapMode(de.tudarmstadt.ukp.clarin.webanno.model.OverlapMode) AnnotationComparator(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.AnnotationComparator) VID(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.VID) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) VDocument(de.tudarmstadt.ukp.clarin.webanno.api.annotation.rendering.model.VDocument) IllegalPlacementException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalPlacementException) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) HashSet(java.util.HashSet) Set(java.util.Set) ArrayList(java.util.ArrayList) Pair(org.apache.commons.lang3.tuple.Pair)

Example 15 with LogMessage

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));
        }
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Aggregations

LogMessage (de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage)26 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)16 ArrayList (java.util.ArrayList)13 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)12 Type (org.apache.uima.cas.Type)11 FeatureStructure (org.apache.uima.cas.FeatureStructure)7 CAS (org.apache.uima.cas.CAS)6 Test (org.junit.Test)6 CasDoctor (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor)5 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)5 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)5 Dependency (de.tudarmstadt.ukp.dkpro.core.api.syntax.type.dependency.Dependency)4 WebAnnoConst (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CasStorageService (de.tudarmstadt.ukp.clarin.webanno.api.CasStorageService)2 DocumentService (de.tudarmstadt.ukp.clarin.webanno.api.DocumentService)2 ImportExportService (de.tudarmstadt.ukp.clarin.webanno.api.ImportExportService)2 CORRECTION_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CORRECTION_USER)2 CURATION_USER (de.tudarmstadt.ukp.clarin.webanno.api.WebAnnoConst.CURATION_USER)2