Search in sources :

Example 66 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer 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.diag.CasDoctor.LogMessage) ArrayList(java.util.ArrayList) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)

Example 67 with AnnotationLayer

use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer in project webanno by webanno.

the class RemoveDanglingChainLinksRepair method repair.

@Override
public void repair(Project aProject, CAS aCas, List<LogMessage> aMessages) {
    for (AnnotationLayer layer : annotationService.listAnnotationLayer(aProject)) {
        if (!WebAnnoConst.CHAIN_TYPE.equals(layer.getType())) {
            continue;
        }
        List<FeatureStructure> chains = new ArrayList<>(selectFS(aCas, getType(aCas, layer.getName() + "Chain")));
        List<AnnotationFS> links = new ArrayList<>(select(aCas, getType(aCas, layer.getName() + "Link")));
        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);
            }
        }
        // Delete those relations that pointed to deleted spans
        if (!links.isEmpty()) {
            links.forEach(aCas::removeFsFromIndexes);
            aMessages.add(new LogMessage(this, LogLevel.INFO, "Removed [%d] dangling links in layer [" + layer.getName() + "].", links.size()));
        }
    }
}
Also used : FeatureStructure(org.apache.uima.cas.FeatureStructure) 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)

Aggregations

AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)67 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)35 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)22 ArrayList (java.util.ArrayList)14 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)13 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 LogMessage (de.tudarmstadt.ukp.clarin.webanno.diag.CasDoctor.LogMessage)8 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)7 Type (org.apache.uima.cas.Type)7 JCas (org.apache.uima.jcas.JCas)6 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)5 FeatureStructure (org.apache.uima.cas.FeatureStructure)5 TypeSystemDescription (org.apache.uima.resource.metadata.TypeSystemDescription)5 Test (org.junit.Test)5 Project (de.tudarmstadt.ukp.clarin.webanno.model.Project)4 HashMap (java.util.HashMap)4 TypeSystemDescriptionFactory.createTypeSystemDescription (org.apache.uima.fit.factory.TypeSystemDescriptionFactory.createTypeSystemDescription)4 SoftAssertions (org.assertj.core.api.SoftAssertions)4 Tag (de.tudarmstadt.ukp.clarin.webanno.model.Tag)3