Search in sources :

Example 51 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class TypeUtil method getUiLabelText.

/**
 * Construct the label text used in the brat user interface.
 *
 * @param aAdapter the adapter.
 * @param aFs the annotation.
 * @param aFeatures the features.
 * @return the label.
 */
public static String getUiLabelText(TypeAdapter aAdapter, AnnotationFS aFs, List<AnnotationFeature> aFeatures) {
    StringBuilder bratLabelText = new StringBuilder();
    for (AnnotationFeature feature : aFeatures) {
        if (!feature.isEnabled() || !feature.isVisible() || !MultiValueMode.NONE.equals(feature.getMultiValueMode())) {
            continue;
        }
        Feature labelFeature = aFs.getType().getFeatureByBaseName(feature.getName());
        String label = StringUtils.defaultString(aFs.getFeatureValueAsString(labelFeature));
        if (bratLabelText.length() > 0 && label.length() > 0) {
            bratLabelText.append(TypeAdapter.FEATURE_SEPARATOR);
        }
        bratLabelText.append(label);
    }
    if (bratLabelText.length() > 0) {
        return bratLabelText.toString();
    } else {
        // If there are no label features at all, then use the layer UI name
        return "(" + aAdapter.getLayer().getUiName() + ")";
    }
}
Also used : AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 52 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class TypeUtil method getUiHoverText.

/**
 * Construct the hover text used in the brat user interface.
 *
 * @param aAdapter the adapter.
 * @param aFs the annotation.
 * @param aFeatures the features.
 * @return the hover text.
 */
public static String getUiHoverText(TypeAdapter aAdapter, AnnotationFS aFs, List<AnnotationFeature> aFeatures) {
    StringBuilder bratHoverText = new StringBuilder();
    for (AnnotationFeature feature : aFeatures) {
        if (!feature.isEnabled() || !feature.isIncludeInHover() || !MultiValueMode.NONE.equals(feature.getMultiValueMode())) {
            continue;
        }
        Feature labelFeature = aFs.getType().getFeatureByBaseName(feature.getName());
        String text = StringUtils.defaultString(aFs.getFeatureValueAsString(labelFeature));
        if (bratHoverText.length() > 0 && text.length() > 0) {
            bratHoverText.append(TypeAdapter.FEATURE_SEPARATOR);
        }
        bratHoverText.append(text);
    }
    if (bratHoverText.length() > 0) {
        if (aAdapter.getLayer().isShowTextInHover()) {
            return String.format("\"%s\" %s", aFs.getCoveredText(), bratHoverText.toString());
        }
        return bratHoverText.toString();
    } else {
        // is the default if no hover text is provided
        return null;
    }
}
Also used : AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 53 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class WebAnnoCasUtil method setFeatureFS.

/**
 * Set a feature value.
 *
 * @param aFS
 *            the feature structure.
 * @param aFeatureName
 *            the feature within the annotation whose value to set.
 * @param aValue
 *            the feature value.
 */
public static void setFeatureFS(FeatureStructure aFS, String aFeatureName, FeatureStructure aValue) {
    Feature labelFeature = aFS.getType().getFeatureByBaseName(aFeatureName);
    aFS.setFeatureValue(labelFeature, aValue);
}
Also used : Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 54 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class PrimitiveUimaFeatureSupport method getFeatureValue.

@Override
public <T> T getFeatureValue(AnnotationFeature aFeature, FeatureStructure aFS) {
    Feature feature = aFS.getType().getFeatureByBaseName(aFeature.getName());
    final String effectiveType = aFeature.getType();
    // Sanity check
    if (!Objects.equals(effectiveType, feature.getRange().getName())) {
        throw new IllegalArgumentException("Actual feature type [" + feature.getRange().getName() + "] does not match expected feature type [" + effectiveType + "].");
    }
    return WebAnnoCasUtil.getFeature(aFS, aFeature.getName());
}
Also used : Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 55 with Feature

use of org.apache.uima.cas.Feature in project webanno by webanno.

the class AnnotationDetailEditorPanel method deleteAnnotation.

private void deleteAnnotation(JCas jCas, AnnotatorState state, AnnotationFS fs, AnnotationLayer layer, TypeAdapter adapter) {
    // is no longer set after UNATTACH SPANS!
    if (adapter instanceof SpanAdapter) {
        for (AnnotationFS attachedFs : getAttachedRels(fs, layer)) {
            jCas.getCas().removeFsFromIndexes(attachedFs);
            info("The attached annotation for relation type [" + annotationService.getLayer(attachedFs.getType().getName(), state.getProject()).getUiName() + "] is deleted");
        }
    }
    // to look at span annotations that have the same offsets as the FS to be deleted.
    if (adapter instanceof SpanAdapter && layer.getAttachType() != null && layer.getAttachFeature() != null) {
        Type spanType = CasUtil.getType(jCas.getCas(), layer.getAttachType().getName());
        Feature attachFeature = spanType.getFeatureByBaseName(layer.getAttachFeature().getName());
        for (AnnotationFS attachedFs : getAttachedSpans(fs, layer)) {
            attachedFs.setFeatureValue(attachFeature, null);
            LOG.debug("Unattached [" + attachFeature.getShortName() + "] on annotation [" + getAddr(attachedFs) + "]");
        }
    }
    // to be deleted: the link feature must be the type of the FS or it must be generic.
    if (adapter instanceof SpanAdapter) {
        for (AnnotationFeature linkFeature : annotationService.listAttachedLinkFeatures(layer)) {
            Type linkType = CasUtil.getType(jCas.getCas(), linkFeature.getLayer().getName());
            for (AnnotationFS linkFS : CasUtil.select(jCas.getCas(), linkType)) {
                List<LinkWithRoleModel> links = adapter.getFeatureValue(linkFeature, linkFS);
                Iterator<LinkWithRoleModel> i = links.iterator();
                boolean modified = false;
                while (i.hasNext()) {
                    LinkWithRoleModel link = i.next();
                    if (link.targetAddr == getAddr(fs)) {
                        i.remove();
                        LOG.debug("Cleared slot [" + link.role + "] in feature [" + linkFeature.getName() + "] on annotation [" + getAddr(linkFS) + "]");
                        modified = true;
                    }
                }
                if (modified) {
                    setFeature(linkFS, linkFeature, links);
                }
            }
        }
    }
    // relation.
    if (adapter instanceof ArcAdapter) {
    // Do nothing ;)
    }
    // Actually delete annotation
    adapter.delete(state, jCas, state.getSelection().getAnnotation());
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) LinkWithRoleModel(de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel) ArcAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter) SpanAdapter(de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.SpanAdapter) Feature(org.apache.uima.cas.Feature) WebAnnoCasUtil.setFeature(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

Feature (org.apache.uima.cas.Feature)84 Type (org.apache.uima.cas.Type)62 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)50 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)48 ArrayList (java.util.ArrayList)23 FeatureStructure (org.apache.uima.cas.FeatureStructure)18 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)18 JCas (org.apache.uima.jcas.JCas)18 List (java.util.List)15 Test (org.junit.Test)14 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)13 WebAnnoCasUtil.setFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature)12 POS (de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS)12 CAS (org.apache.uima.cas.CAS)10 HashSet (java.util.HashSet)8 LinkedHashMap (java.util.LinkedHashMap)8 Map (java.util.Map)8 HashMap (java.util.HashMap)7 TypeSystem (org.apache.uima.cas.TypeSystem)7 AnnotationException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.AnnotationException)6