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() + ")";
}
}
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;
}
}
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);
}
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());
}
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());
}
Aggregations