use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class SpanAdapter method getAnnotation.
@Override
public List<String> getAnnotation(Sentence aSentence, AnnotationFeature aFeature) {
CAS cas = aSentence.getCAS();
Type type = getType(cas, getAnnotationTypeName());
List<String> annotations = new ArrayList<>();
for (Token token : selectCovered(Token.class, aSentence)) {
List<AnnotationFS> tokenLevelAnnotations = selectCovered(type, token);
if (tokenLevelAnnotations.size() > 0) {
AnnotationFS anno = tokenLevelAnnotations.get(0);
Feature labelFeature = anno.getType().getFeatureByBaseName(aFeature.getName());
annotations.add(anno.getFeatureValueAsString(labelFeature));
} else {
annotations.add(NILL);
}
}
return annotations;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class SpanAdapter method getMultipleAnnotation.
public Map<Integer, String> getMultipleAnnotation(Sentence sentence, AnnotationFeature aFeature) throws CASException {
Map<Integer, String> multAnno = new HashMap<>();
Type type = getType(sentence.getCAS(), getAnnotationTypeName());
for (AnnotationFS fs : selectCovered(type, sentence)) {
boolean isBegin = true;
Feature labelFeature = fs.getType().getFeatureByBaseName(aFeature.getName());
for (Token token : selectCovered(Token.class, fs)) {
if (multAnno.get(getAddr(token)) == null) {
if (isBegin) {
multAnno.put(getAddr(token), "B-" + fs.getFeatureValueAsString(labelFeature));
isBegin = false;
} else {
multAnno.put(getAddr(token), "I-" + fs.getFeatureValueAsString(labelFeature));
}
}
}
}
return multAnno;
}
use of de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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 de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature 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 de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature in project webanno by webanno.
the class NamedEntityLayerInitializer method configure.
@Override
public void configure(Project aProject) throws IOException {
TagSet nerTagSet = JsonImportUtil.importTagSetFromJson(aProject, new ClassPathResource("/tagsets/de-ne-webanno.json").getInputStream(), annotationSchemaService);
AnnotationLayer neLayer = new AnnotationLayer(NamedEntity.class.getName(), "Named entity", SPAN_TYPE, aProject, true);
neLayer.setAllowStacking(true);
neLayer.setMultipleTokens(true);
neLayer.setLockToTokenOffset(false);
annotationSchemaService.createLayer(neLayer);
annotationSchemaService.createFeature(new AnnotationFeature(aProject, neLayer, "value", "value", CAS.TYPE_NAME_STRING, "Named entity type", nerTagSet));
}
Aggregations