uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Richard Eckart de Castilho <richard.eck...@gmail.com>
Subject Re: Getting all Features for any Annotator
Date Sat, 13 Jul 2013 07:23:27 GMT
You'd want to change that a little to avoid having duplications.

1) Get an iterator over all annotations in the CAS.getAnnotationIndex().iterator()

2) Fetch type of the current annotation from the type system

3) iterate through the features and get their values

Depending on your type system, 3 needs to be able to handle cases where
a feature is not a primitive type, but a reference to another feature structure.
If you have such cases, you may also want/need to handle features structures
being referenced from multiple other FSes. If you have a simple type system,
you can skip this advice.

Some features you'll want to skip, e.g. the SofA.

-- Richard

Am 12.07.2013 um 23:41 schrieb Chuong Ngo <cngo.textanalytics@gmail.com>:

> 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

View raw message