Search in sources :

Example 46 with AnnotationFeature

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;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) CAS(org.apache.uima.cas.CAS) ArrayList(java.util.ArrayList) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 47 with AnnotationFeature

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;
}
Also used : AnnotationFS(org.apache.uima.cas.text.AnnotationFS) Type(org.apache.uima.cas.Type) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) HashMap(java.util.HashMap) Token(de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token) Feature(org.apache.uima.cas.Feature) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Example 48 with AnnotationFeature

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() + ")";
    }
}
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 49 with AnnotationFeature

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;
    }
}
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 50 with AnnotationFeature

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));
}
Also used : NamedEntity(de.tudarmstadt.ukp.dkpro.core.api.ner.type.NamedEntity) TagSet(de.tudarmstadt.ukp.clarin.webanno.model.TagSet) AnnotationLayer(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer) ClassPathResource(org.springframework.core.io.ClassPathResource) AnnotationFeature(de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)

Aggregations

AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)73 AnnotationLayer (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationLayer)34 Feature (org.apache.uima.cas.Feature)20 ArrayList (java.util.ArrayList)16 Type (org.apache.uima.cas.Type)16 AnnotationFS (org.apache.uima.cas.text.AnnotationFS)15 TagSet (de.tudarmstadt.ukp.clarin.webanno.model.TagSet)12 Token (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Token)11 JCas (org.apache.uima.jcas.JCas)10 AnnotatorState (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.AnnotatorState)9 File (java.io.File)9 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)8 LinkWithRoleModel (de.tudarmstadt.ukp.clarin.webanno.api.annotation.model.LinkWithRoleModel)6 SourceDocument (de.tudarmstadt.ukp.clarin.webanno.model.SourceDocument)6 Sentence (de.tudarmstadt.ukp.dkpro.core.api.segmentation.type.Sentence)6 List (java.util.List)6 FeatureStructure (org.apache.uima.cas.FeatureStructure)6 ArcAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.ArcAdapter)5 TypeAdapter (de.tudarmstadt.ukp.clarin.webanno.api.annotation.adapter.TypeAdapter)5 FeatureSupportRegistry (de.tudarmstadt.ukp.clarin.webanno.api.annotation.feature.FeatureSupportRegistry)5