问题描述:

I would like to be able to get a common feature from different annotation types. Is it possible to create sub-classes of the annotations and then get them by the super-class?

This is the way I am doing it at the moment but I would like to be able to get a general super-class of annotation rather than a specific one.

TypeSystem typeSystem = jcas.getTypeSystem();

Type type = typeSystem.getType("com.example.SpecificAnnotation");

AnnotationIndex<Annotation> annotationIndex = jcas.getAnnotationIndex(type);

Annotation annotation = annotationIndex.iterator().next();

String value = annotation.getFeatureValueAsString(type.getFeatureByBaseName("value"));

网友答案:

You can create an annotation type X with the common features. Then you can create additional annotation types which inherit from your type X instead of inheriting from Annotation.

相关阅读:
Top