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 HashMap 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.edu




On Oct 16, 2013, at 9:55 AM, Dr. Armin Wegner 
mailto: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  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 Map.
>
> -- Richard
>
> On 16.10.2013, at 17:55, Dr. Armin Wegner 
> 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 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 Map.

-- Richard

On 16.10.2013, at 17:55, Dr. Armin Wegner  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



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: Collection Reader Progress

2013-10-16 Thread Dr. Armin Wegner
Good afternoon,

I've used this.

public Progress[] getProgress() {
  return new Progress[] { new
ProgressImpl(number_of_completed_artifacts, -1, Progress.ENTITIES,
true) };
}

At least it does compile and run. Is it semantically correct, too?

Cheers,
Armin

On 10/8/13, Burn Lewis  wrote:
> Yes, is optional, but applications that use the information typically treat
> -1 as "unknown"
>
> ~Burn
>
>
> On Mon, Oct 7, 2013 at 9:15 AM, Renaud Richardet
> wrote:
>
>> Hi Armin,
>> Just return null. I rarely implement that method...
>> Best, Renaud
>>
>>
>> On Sat, Oct 5, 2013 at 11:44 AM, Dr. Armin Wegner <
>> arminweg...@googlemail.com> wrote:
>>
>> > What to return from method Progress of CasCollectionReader_ImplBase
>> > when I do not know the total number of artifacts?
>> >
>>
>