Search in sources :

Example 1 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.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;
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
            continue;
        }
        Type layerType;
        Type attachType;
        try {
            layerType = getType(aCas, layer.getName());
            attachType = getType(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 (candidate != anno) {
                    aMessages.add(new LogMessage(this, LogLevel.ERROR, "Annotation should be attached to [" + layer.getAttachFeature().getName() + "] but is not.\nAnnotation: [" + anno + "]\nAttach annotation:[" + attach + "]"));
                    ok = false;
                }
            }
        }
    }
    return ok;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 2 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage in project webanno by webanno.

the class NoZeroSizeTokensAndSentencesCheck method check.

@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    try {
        boolean ok = true;
        for (Token t : select(aCas.getJCas(), Token.class)) {
            if (t.getBegin() >= t.getEnd()) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR, "Token with illegal span: %s", t));
                ok = false;
            }
        }
        for (Sentence s : select(aCas.getJCas(), Sentence.class)) {
            if (s.getBegin() >= s.getEnd()) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR, "Sentence with illegal span: %s", s));
                ok = false;
            }
        }
        return ok;
    } catch (CASException e) {
        log.error("Unabled to access JCas", e);
        aMessages.add(new LogMessage(this, LogLevel.ERROR, "Unabled to access JCas", e.getMessage()));
        return false;
    }
}
Also used : LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) CASException(org.apache.uima.cas.CASException) Sentence(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)

Example 3 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage in project webanno by webanno.

the class ReattachFeatureAttachedSpanAnnotationsAndDeleteExtrasRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
            continue;
        }
        int count = 0;
        // attach -> e.g. Token
        for (AnnotationFS anno : select(aCas, getType(aCas, layer.getName()))) {
            for (AnnotationFS attach : selectCovered(getType(aCas, layer.getAttachType().getName()), anno)) {
                AnnotationFS candidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
                if (candidate == null) {
                    setFeature(attach, layer.getAttachFeature().getName(), anno);
                    count++;
                } else if (candidate != anno) {
                    aMessages.add(new LogMessage(this, LogLevel.ERROR, "Cannot attach annotation because attach feature alread non-null"));
                }
            }
        }
        if (count > 0) {
            aMessages.add(new LogMessage(this, LogLevel.INFO, "Reattached [%d] unattached spans layer [" + layer.getName() + "].", count));
        }
        // Go over the layer that is being attached to (e.g. Lemma) and ensure that if there
        // only exactly one annotation for each annotation in the layer that has the attach
        // feature (e.g. Token) - or short: ensure that there are not multiple Lemmas for a
        // single Token because such a thing is not valid in WebAnno. Layers that have an
        // attach feature cannot have stacking enabled!
        // 
        // attach     -> e.g. Token
        // candidates -> e.g. Lemma
        List<AnnotationFS> toDelete = new ArrayList<>();
        for (AnnotationFS attach : select(aCas, getType(aCas, layer.getAttachType().getName()))) {
            List<AnnotationFS> candidates = selectCovered(getType(aCas, layer.getName()), attach);
            if (!candidates.isEmpty()) {
                // One of the candidates should already be attached
                AnnotationFS attachedCandidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
                for (AnnotationFS candidate : candidates) {
                    if (candidate != attachedCandidate) {
                        toDelete.add(candidate);
                    }
                }
            }
        }
        // Delete those the extra candidates that are not properly attached
        if (!toDelete.isEmpty()) {
            toDelete.forEach(aCas::removeFsFromIndexes);
            aMessages.add(new LogMessage(this, LogLevel.INFO, "Removed [%d] unattached stacked candidates [" + layer.getName() + "].", toDelete.size()));
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 4 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage in project webanno by webanno.

the class ReattachFeatureAttachedSpanAnnotationsRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!(WebAnnoConst.SPAN_TYPE.equals(layer.getType()) && layer.getAttachFeature() != null)) {
            continue;
        }
        int count = 0;
        // attach -> e.g. Token
        for (AnnotationFS anno : select(aCas, getType(aCas, layer.getName()))) {
            for (AnnotationFS attach : selectCovered(getType(aCas, layer.getAttachType().getName()), anno)) {
                AnnotationFS candidate = getFeature(attach, layer.getAttachFeature().getName(), AnnotationFS.class);
                if (candidate == null) {
                    setFeature(attach, layer.getAttachFeature().getName(), anno);
                    count++;
                } else if (candidate != anno) {
                    aMessages.add(new LogMessage(this, LogLevel.ERROR, "Cannot attach annotation because attach feature alread non-null"));
                }
            }
        }
        if (count > 0) {
            aMessages.add(new LogMessage(this, LogLevel.INFO, "Reattached [%d] unattached spans on layer [" + layer.getName() + "].", count));
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 5 with LogMessage

use of de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.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.simpleName")));
            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.diag.CasDoctor.LogMessage) Label(org.apache.wicket.markup.html.basic.Label) ListItem(org.apache.wicket.markup.html.list.ListItem)

Aggregations

LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)17 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)11 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)8 ArrayList (java.util.ArrayList)7 Type (org.apache.uima.cas.Type)7 CasDoctor (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor)5 FeatureStructure (org.apache.uima.cas.FeatureStructure)4 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)4 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)3 JCas (org.apache.uima.jcas.JCas)3 Test (org.junit.Test)3 AnnotationDocument (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationDocument)2 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)2 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)2 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)2 CAS (org.apache.uima.cas.CAS)2 CASException (org.apache.uima.cas.CASException)2 TypeDescription (org.apache.uima.resource.metadata.TypeDescription)2 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)2 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)1