Search in sources :

Example 21 with LogMessage

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

the class RelationOffsetsCheck method check.

@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    boolean ok = true;
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!WebAnnoConst.RELATION_TYPE.equals(layer.getType())) {
            continue;
        }
        Type type;
        try {
            type = getType(aCas, layer.getName());
        } catch (IllegalArgumentException e) {
            // can skip checking the layer because there will be no annotations anyway.
            continue;
        }
        for (AnnotationFS rel : select(aCas, type)) {
            AnnotationFS target = getFeature(rel, WebAnnoConst.FEAT_REL_TARGET, AnnotationFS.class);
            if ((rel.getBegin() != target.getBegin()) || (rel.getEnd() != target.getEnd())) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR, "Relation offsets [%d,%d] to not match target offsets [%d,%d]", rel.getBegin(), rel.getEnd(), target.getBegin(), target.getEnd()));
                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.support.logging.LogMessage) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 22 with LogMessage

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

the class LinksReachableThroughChainsCheck method check.

@Override
public boolean check(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    boolean ok = true;
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!WebAnnoConst.CHAIN_TYPE.equals(layer.getType())) {
            continue;
        }
        Type chainType;
        Type linkType;
        try {
            chainType = getType(aCas, layer.getName() + "Chain");
            linkType = getType(aCas, layer.getName() + "Link");
        } catch (IllegalArgumentException e) {
            // check
            continue;
        }
        List<FeatureStructure> chains = new ArrayList<>(selectFS(aCas, chainType));
        List<AnnotationFS> links = new ArrayList<>(select(aCas, linkType));
        for (FeatureStructure chain : chains) {
            AnnotationFS link = FSUtil.getFeature(chain, "first", AnnotationFS.class);
            while (link != null) {
                links.remove(link);
                link = FSUtil.getFeature(link, "next", AnnotationFS.class);
            }
        }
        if (!links.isEmpty()) {
            ok = false;
            aMessages.add(new LogMessage(this, LogLevel.ERROR, "CoreferenceLinks not reachable through chains: %d", links.size()));
            for (AnnotationFS link : links) {
                aMessages.add(new LogMessage(this, LogLevel.ERROR, "Unreachable CoreferenceLink [%s]", link));
            }
        }
    }
    return ok;
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) 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.support.logging.LogMessage) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 23 with LogMessage

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

the class RelationOffsetsRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    List<AnnotationFS> fixedRels = new ArrayList<>();
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!WebAnnoConst.RELATION_TYPE.equals(layer.getType())) {
            continue;
        }
        Type type;
        try {
            type = getType(aCas, layer.getName());
        } catch (IllegalArgumentException e) {
            // can skip checking the layer because there will be no annotations anyway.
            continue;
        }
        for (AnnotationFS rel : select(aCas, type)) {
            AnnotationFS target = getFeature(rel, WebAnnoConst.FEAT_REL_TARGET, AnnotationFS.class);
            if ((rel.getBegin() != target.getBegin()) || (rel.getEnd() != target.getEnd())) {
                fixedRels.add(rel);
                setFeature(rel, CAS.FEATURE_BASE_NAME_BEGIN, target.getBegin());
                setFeature(rel, CAS.FEATURE_BASE_NAME_END, target.getEnd());
            }
        }
        // Delete those relations that pointed to deleted spans
        if (!fixedRels.isEmpty()) {
            aMessages.add(new LogMessage(this, LogLevel.INFO, "Fixed the offsets of [%d] relations in layer [" + layer.getName() + "].", fixedRels.size()));
        }
    }
}
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.support.logging.LogMessage) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 24 with LogMessage

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

the class RemoveZeroSizeTokensAndSentencesRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    for (AnnotationFS s : selectSentences(aCas)) {
        if (s.getBegin() >= s.getEnd()) {
            aCas.removeFsFromIndexes(s);
            aMessages.add(new LogMessage(this, INFO, "Removed sentence with illegal span: %s", s));
        }
    }
    for (AnnotationFS t : WebAnnoCasUtil.selectTokens(aCas)) {
        if (t.getBegin() >= t.getEnd()) {
            AnnotationFS lemma = FSUtil.getFeature(t, "lemma", AnnotationFS.class);
            if (lemma != null) {
                aCas.removeFsFromIndexes(lemma);
                aMessages.add(new LogMessage(this, INFO, "Removed lemma attached to token with illegal span: %s", t));
            }
            AnnotationFS pos = FSUtil.getFeature(t, "pos", AnnotationFS.class);
            if (pos != null) {
                aCas.removeFsFromIndexes(pos);
                aMessages.add(new LogMessage(this, INFO, "Removed POS attached to token with illegal span: %s", t));
            }
            AnnotationFS stem = FSUtil.getFeature(t, "stem", AnnotationFS.class);
            if (stem != null) {
                aCas.removeFsFromIndexes(stem);
                aMessages.add(new LogMessage(this, INFO, "Removed stem attached to token with illegal span: %s", t));
            }
            aCas.removeFsFromIndexes(t);
            aMessages.add(new LogMessage(this, INFO, "Removed token with illegal span: %s", t));
        }
    }
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage)

Example 25 with LogMessage

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

the class AllAnnotationsIndexedCheckTest method testFail.

@Test
public void testFail() throws Exception {
    TypeSystemDescription tsd = UIMAFramework.getResourceSpecifierFactory().createTypeSystemDescription();
    String refTypeName = "RefType";
    TypeDescription refTypeDesc = tsd.addType(refTypeName, null, CAS.TYPE_NAME_ANNOTATION);
    refTypeDesc.addFeature("ref", null, CAS.TYPE_NAME_ANNOTATION);
    CAS cas = CasCreationUtils.createCas(tsd, null, null);
    Type refType = cas.getTypeSystem().getType(refTypeName);
    // A regular index annotation
    AnnotationFS anno1 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
    cas.addFsToIndexes(anno1);
    // A non-index annotation but reachable through an indexe one (below)
    AnnotationFS anno2 = cas.createAnnotation(cas.getAnnotationType(), 0, 1);
    // An indexed annotation that references the non-indexed annotation above
    AnnotationFS anno3 = cas.createAnnotation(refType, 0, 1);
    anno3.setFeatureValue(refType.getFeatureByBaseName("ref"), anno2);
    cas.addFsToIndexes(anno3);
    List<LogMessage> messages = new ArrayList<>();
    CasDoctor cd = new CasDoctor(AllFeatureStructuresIndexedCheck.class);
    // A project is not required for this check
    boolean result = cd.analyze(null, cas, messages);
    messages.forEach(System.out::println);
    assertFalse(result);
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) TypeSystemDescription(org.apache.uima.resource.metadata.TypeSystemDescription) CAS(org.apache.uima.cas.CAS) LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) ArrayList(java.util.ArrayList) CasDoctor(de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor) TypeDescription(org.apache.uima.resource.metadata.TypeDescription) Test(org.junit.Test)

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