HashMap as type feature

2013-10-16 Thread Dr. Armin Wegner
Hi,

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?

Thanks,
Armin


Re: HashMap as type feature

2013-10-16 Thread Richard Eckart de Castilho
Hi,

you could define a feature structure e.g.

StringStringMapEntry {
  String key
  String value
}

and store these in an FSList. Then, write additional convenience code around 
that
which transforms this to/from a MapString, String.

-- Richard

On 16.10.2013, at 17:55, Dr. Armin Wegner arminweg...@googlemail.com wrote:

 Hi,
 
 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?
 
 Thanks,
 Armin



Re: HashMap as type feature

2013-10-16 Thread Dr. Armin Wegner
Hi Richard,

thanks for the quick reply. But the answer is a little too short for
me. Can you point me to an example or a documentation, please? I
couldn't find it in the UIMA Tutorial and Developers' Guides. Did I
miss it?

Best,
Armin

On 10/16/13, Richard Eckart de Castilho r...@apache.org wrote:
 Hi,

 you could define a feature structure e.g.

 StringStringMapEntry {
   String key
   String value
 }

 and store these in an FSList. Then, write additional convenience code around
 that
 which transforms this to/from a MapString, String.

 -- Richard

 On 16.10.2013, at 17:55, Dr. Armin Wegner arminweg...@googlemail.com
 wrote:

 Hi,

 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?

 Thanks,
 Armin




Re: HashMap as type feature

2013-10-16 Thread Thomas Ginter
Armin,

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 HashMapString, 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.

Thanks,

Thomas Ginter
801-448-7676
thomas.gin...@utah.edumailto:thomas.gin...@utah.edu




On Oct 16, 2013, at 9:55 AM, Dr. Armin Wegner 
arminweg...@googlemail.commailto:arminweg...@googlemail.com wrote:

Hi,

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?

Thanks,
Armin