uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thomas Ginter <thomas.gin...@utah.edu>
Subject Re: HashMap as type feature
Date Wed, 16 Oct 2013 16:53:10 GMT

Our team does this with an annotation type designed to store feature vectors for Machine Learning
applications.  In this case we use a StringArray feature for the keys and a StringArray feature
for the values.  The StringArrays are pulled from a HashMap<String, String> vector variable
and inserted into the features with the following code:

int size = vector.size();
StringArray keys = new StringArray(jcas, size);
StringArray values = new StringArray(jcas, size);
keys.copyFromArray(vector.keySet().toArray(new String[size]), 0, 0, size);
values.copyFromArray(vector.values().toArray(new String[size]), 0, 0, size);

Retrieving the values is fairly straightforward.  If you are using a static annotation type
it can be as simple as:

StringArray keys = vector.getKeysArray();

If you parameterize our annotation type in the annotator you can use the name of the feature
to get a Feature object reference then pull the StringArrays like so:

Type annotationTypeObj = aJCas.getRequiredType("com.my.Annotation"); //parameter is the canonized
name of the Annotation type
Feature keyFeature = annotationTypeObj.getFeatureByBaseName("keyFeatureName"); //the actual
name of the feature storing the key StringArray reference
Feature valuesFeature = annotationTypeObj.getFeatureByBaseName("valuesFeatureName"); //the
name of the values feature

//Get a list of the annotation objects in the CAS then iterate through the list, for each
annotation 'a' do the following to retrieve the keys and values

StringArray keys = (StringArray) vector.getFeatureValue(keysFeature);
StringArray values = (StringArray) vector.getFeatureValue(valuesFeature);

If necessary you can retrieve a String[] from the StringArray FeatureStructure by calling
the .toArray() method such as:

String[] keysArray = keys.toArray();

Let me know if you have any questions.


Thomas Ginter

On Oct 16, 2013, at 9:55 AM, Dr. Armin Wegner <arminwegner@googlemail.com<mailto:arminwegner@googlemail.com>>


I'd like to have a type feature that is a list of key-value pairs. The
number of pairs is unknown. What's best for this? Is it even possible?


  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message