Search in sources :

Example 6 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.

the class DanglingRelationsCheck method check.

@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    boolean ok = true;
    for (AnnotationFS fs : aCas.getAnnotationIndex()) {
        Type t = fs.getType();
        Feature sourceFeat = t.getFeatureByBaseName(FEAT_REL_SOURCE);
        Feature targetFeat = t.getFeatureByBaseName(FEAT_REL_TARGET);
        // Is this a relation?
        if (!(sourceFeat != null && targetFeat != null)) {
            continue;
        }
        RelationAdapter relationAdapter = (RelationAdapter) annotationService.findAdapter(aProject, fs);
        Feature relationSourceAttachFeature = null;
        Feature relationTargetAttachFeature = null;
        if (relationAdapter.getAttachFeatureName() != null) {
            relationSourceAttachFeature = sourceFeat.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
            relationTargetAttachFeature = targetFeat.getRange().getFeatureByBaseName(relationAdapter.getAttachFeatureName());
        }
        FeatureStructure source = fs.getFeatureValue(sourceFeat);
        FeatureStructure target = fs.getFeatureValue(targetFeat);
        // Here we get the annotations that the relation is pointing to in the UI
        if (source != null && relationSourceAttachFeature != null) {
            source = (AnnotationFS) source.getFeatureValue(relationSourceAttachFeature);
        }
        if (target != null && relationTargetAttachFeature != null) {
            target = (AnnotationFS) target.getFeatureValue(relationTargetAttachFeature);
        }
        // Does it have null endpoints?
        if (source == null || target == null) {
            StringBuilder message = new StringBuilder();
            message.append("Relation [" + relationAdapter.getLayer().getName() + "] with id [" + getAddr(fs) + "] has loose ends - cannot identify attached annotations.");
            if (relationAdapter.getAttachFeatureName() != null) {
                message.append("\nRelation [" + relationAdapter.getLayer().getName() + "] attached to feature [" + relationAdapter.getAttachFeatureName() + "].");
            }
            message.append("\nSource: " + source);
            message.append("\nTarget: " + target);
            aMessages.add(new LogMessage(this, INFO, "%s", message));
            ok = false;
        }
    }
    return ok;
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) AnnotationFS(org.apache.uima.cas.text.AnnotationFS) RelationAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.RelationAdapter) Type(org.apache.uima.cas.Type) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) Feature(org.apache.uima.cas.Feature)

Example 7 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.

the class FeatureAttachedSpanAnnotationsTrulyAttachedCheck method check.

@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    boolean ok = true;
    int count = 0;
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!(SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
            continue;
        }
        Type layerType;
        Type attachType;
        try {
            layerType = getAnnotationType(aCas, layer.getName());
            attachType = getAnnotationType(aCas, layer.getAttachType().getName());
        } catch (IllegalArgumentException e) {
            // check
            continue;
        }
        for (AnnotationFS anno : select(aCas, layerType)) {
            for (AnnotationFS attach : selectCovered(attachType, anno)) {
                AnnotationFS candidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
                if (!anno.equals(candidate)) {
                    if (count < 100) {
                        aMessages.add(new LogMessage(this, LogLevel.ERROR, "Annotation should be attached to [" + layer.getAttachFeature().getName() + "] but is not.\nAnnotation: [" + anno + "]\nAttach annotation:[" + attach + "]"));
                    }
                    count++;
                    ok = false;
                }
            }
        }
    }
    if (count >= 100) {
        aMessages.add(new LogMessage(this, LogLevel.ERROR, "In total [%d] annotations were not properly attached", count));
    }
    return ok;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) CasUtil.getAnnotationType(org.apache.uima.fit.util.CasUtil.getAnnotationType) Type(org.apache.uima.cas.Type) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 8 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.

the class NoZeroSizeTokensAndSentencesCheck method check.

@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    boolean ok = true;
    for (AnnotationFS t : selectTokens(aCas)) {
        if (t.getBegin() >= t.getEnd()) {
            aMessages.add(new LogMessage(this, LogLevel.ERROR, "Token with illegal span: %s", t));
            ok = false;
        }
    }
    for (AnnotationFS s : selectSentences(aCas)) {
        if (s.getBegin() >= s.getEnd()) {
            aMessages.add(new LogMessage(this, LogLevel.ERROR, "Sentence with illegal span: %s", s));
            ok = false;
        }
    }
    return ok;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage)

Example 9 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.

the class ProjectCasDoctorPanel method createMessagesView.

private ListView<LogMessage> createMessagesView(IModel<LogMessageSet> aModel) {
    return new ListView<LogMessage>("messages", PropertyModel.of(aModel, "messages")) {

        private static final long serialVersionUID = 8957632000765128508L;

        @Override
        protected void populateItem(ListItem<LogMessage> aItem) {
            IModel<LogMessage> msg = aItem.getModel();
            aItem.add(new Label("level", PropertyModel.of(msg, "level")));
            aItem.add(new Label("source", PropertyModel.of(msg, "source")));
            aItem.add(new Label("message", PropertyModel.of(msg, "message")));
        }
    };
}
Also used : ListView(org.apache.wicket.markup.html.list.ListView) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) Label(org.apache.wicket.markup.html.basic.Label) ListItem(org.apache.wicket.markup.html.list.ListItem)

Example 10 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage in project webanno by webanno.

the class ProjectCasDoctorPanel method actionRepair.

private void actionRepair(AjaxRequestTarget aTarget, Form<?> aForm) throws IOException, UIMAException, ClassNotFoundException {
    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)) {
        // Repair INITIAL CAS
        {
            LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [INITIAL]");
            try {
                casStorageService.forceActionOnCas(sd, INITIAL_CAS_PSEUDO_USER, (doc, user) -> createOrReadInitialCasWithoutSaving(doc, messageSet), // 
                (cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
            } catch (Exception e) {
                messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing initial CAS for [" + sd.getName() + "]: " + e.getMessage()));
                LOG.error("Error repairing initial CAS for [{}]", sd.getName(), e);
            }
            noticeIfThereAreNoMessages(messageSet);
            formModel.messageSets.add(messageSet);
        }
        // Repair CORRECTION_USER CAS if necessary
        if (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.repair(project, cas, messageSet.messages), true);
            } 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);
        }
        // Repair 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.repair(project, cas, messageSet.messages), true);
            } catch (FileNotFoundException e) {
                if (asList(CURATION_IN_PROGRESS, CURATION_FINISHED).contains(sd.getState())) {
                    messageSet.messages.add(LogMessage.error(getClass(), "Curation CAS missing."));
                } else {
                    // 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 has not 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);
        }
        // Repair regular annotator CASes
        for (AnnotationDocument ad : documentService.listAnnotationDocuments(sd)) {
            if (documentService.existsAnnotationCas(ad)) {
                LogMessageSet messageSet = new LogMessageSet(sd.getName() + " [" + ad.getUser() + "]");
                try {
                    casStorageService.forceActionOnCas(sd, ad.getUser(), (doc, user) -> casStorageService.readCas(doc, user, UNMANAGED_NON_INITIALIZING_ACCESS), // 
                    (cas) -> casDoctor.repair(project, cas, messageSet.messages), true);
                } catch (Exception e) {
                    messageSet.messages.add(new LogMessage(getClass(), LogLevel.ERROR, "Error repairing annotations of user [" + ad.getUser() + "] for [" + sd.getName() + "]: " + e.getMessage()));
                    LOG.error("Error repairing 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)

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