Search in sources :

Example 1 with IllegalFeatureValueException

use of de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalFeatureValueException in project webanno by webanno.

the class CasMerge method copyFeatures.

private void copyFeatures(SourceDocument aDocument, String aUsername, TypeAdapter aAdapter, FeatureStructure aTargetFS, FeatureStructure aSourceFs) throws AnnotationException {
    // Cache the feature list instead of hammering the database
    List<AnnotationFeature> features = featureCache.computeIfAbsent(aAdapter.getLayer(), key -> schemaService.listSupportedFeatures(key));
    for (AnnotationFeature feature : features) {
        Type sourceFsType = aAdapter.getAnnotationType(aSourceFs.getCAS());
        Feature sourceFeature = sourceFsType.getFeatureByBaseName(feature.getName());
        if (sourceFeature == null) {
            throw new IllegalStateException("Target CAS type [" + sourceFsType.getName() + "] does not define a feature named [" + feature.getName() + "]");
        }
        if (shouldIgnoreFeatureOnMerge(aSourceFs, sourceFeature)) {
            continue;
        }
        Object value = aAdapter.getFeatureValue(feature, aSourceFs);
        try {
            aAdapter.setFeatureValue(aDocument, aUsername, aTargetFS.getCAS(), getAddr(aTargetFS), feature, value);
        } catch (IllegalArgumentException e) {
            // cannot be extended.
            throw new IllegalFeatureValueException("Cannot set value of feature [" + feature.getUiName() + "] to [" + value + "]: " + e.getMessage(), e);
        }
    }
}
Also used : Type(org.apache.uima.cas.Type) WebAnnoCasUtil.isPrimitiveType(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.isPrimitiveType) CasUtil.getType(org.apache.uima.fit.util.CasUtil.getType) IllegalFeatureValueException(de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalFeatureValueException) WebAnnoCasUtil.isBasicFeature(de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.isBasicFeature) FSUtil.getFeature(org.apache.uima.fit.util.FSUtil.getFeature) 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

IllegalFeatureValueException (de.tudarmstadt.ukp.clarin.webanno.api.annotation.exception.IllegalFeatureValueException)1 WebAnnoCasUtil.isBasicFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.isBasicFeature)1 WebAnnoCasUtil.isPrimitiveType (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.isPrimitiveType)1 WebAnnoCasUtil.setFeature (de.tudarmstadt.ukp.clarin.webanno.api.annotation.util.WebAnnoCasUtil.setFeature)1 AnnotationFeature (de.tudarmstadt.ukp.clarin.webanno.model.AnnotationFeature)1 Feature (org.apache.uima.cas.Feature)1 Type (org.apache.uima.cas.Type)1 CasUtil.getType (org.apache.uima.fit.util.CasUtil.getType)1 FSUtil.getFeature (org.apache.uima.fit.util.FSUtil.getFeature)1