Alright, so if I understand correctly, what I need to do is something along
the following:
1) Get the TypeSystem from the cas:
TypeSystem typeSystem = cas.getTypeSystem
2) Get an iterator and iterate over the TypeSystem:
Iterator<Type> itr = ts.getTypeIterator();
while(itr.hasNext()) {
Type type = itr.next();
...
3) For each type, retrieve the qualified name of the type and use it to
retrieve all annotations of that type. Also grab the list of features for
the type:
List<Feature> featureList = type.getFeatures();
AnnotationIndex<AnnotationFS> indexAnn = cas.getAnnotationIndex(type);
Iterator<AnnotationFS> itrAnn = indexAnn.iterator();
while(itr.hasNext()) {
FeatureStructure fs = (FeatureStructure) itrAnn.next();
...
4) Iterate though the list of freatures extracted and pull out the feature
name and values:
for(Feature feature : featureList) {
String featureName = feature.getShortName();
String featureValue = fs.getFeatureValueAsString(feature);
...
On Fri, Jul 12, 2013 at 2:58 PM, Richard Eckart de Castilho <
richard.eckart@gmail.com> wrote:
> People tend to fall back to using Java Reflections on the JCas wrappers,
> before using the lower-level UIMA interfaces (CAS and AnnotationFS/
> FeatureStructure).
>
> Every UIMA annotation implements the interface FeatureStructure. This
> interface in conjunction with the type system information you can obtain
> from the CAS, provides all you need to extract all information.
>
> There is no need to resort to reflection.
>
> You may want to have a look at the source code of the CasCopier class too.
>
> -- Richard
>
> Am 12.07.2013 um 20:16 schrieb Chuong Ngo <cngo.textanalytics@gmail.com>:
>
> > Is there a way to get all the features for an annotator, no matter which
> > one it is?
> >
> > For example, I want to convert all annotators I get back into a JSON
> > respresenting that annotator. My annotators have different number and
> > types of features. For example, a person may have firstName, lastName
> > while an organization may have type, health, etc... Is there another way
> > to do that besides casting each one to a predetermined type and then
> using
> > the getters to extract the feature values? Thanks in advance.
> >
> > Chuong Ngo
>
>
|