AW: HashMap as type feature
Dear Richard, to use StringStringMapEntry, needn't it subclass TOP or FeatureStructure? Is it possible to store an arbitray object into a CAS? Cheers, Armin -Ursprüngliche Nachricht- Von: Richard Eckart de Castilho [mailto:r...@apache.org] Gesendet: Mittwoch, 16. Oktober 2013 18:02 An: user@uima.apache.org Betreff: Re: HashMap as type feature 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 pgpcDYaCZ7IWB.pgp Description: PGP signature
Re: HashMap as type feature
TOP or AnnotationBase (which contains view-related code) would be the appropriate types, I believe. It is not possible to store arbitrary objects in the CAS. -- Richard On 17.10.2013, at 16:33, armin.weg...@bka.bund.de wrote: Dear Richard, to use StringStringMapEntry, needn't it subclass TOP or FeatureStructure? Is it possible to store an arbitray object into a CAS? Cheers, Armin -Ursprüngliche Nachricht- Von: Richard Eckart de Castilho [mailto:r...@apache.org] Gesendet: Mittwoch, 16. Oktober 2013 18:02 An: user@uima.apache.org Betreff: Re: HashMap as type feature 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
AW: HashMap as type feature
Hi Thomas, thanks for your answer. Using HashMap, does the n-th element of keySet() always corresponds to the n-th element of values()? Is this a defined behavior in Java? Cheers, Armin -Ursprüngliche Nachricht- Von: Thomas Ginter [mailto:thomas.gin...@utah.edu] Gesendet: Mittwoch, 16. Oktober 2013 18:53 An: user@uima.apache.org Betreff: Re: HashMap as type feature 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 pgpVY4M54krci.pgp Description: PGP signature
Re: HashMap as type feature
Armin, Yes. Extracting the key set results in an array wherein the n-th element of the key array corresponds to the n-th element of the values array. That is part of how the hash map is handled in Java. Even if you implemented your own sorting algorithm for insertion the value would get inserted with the key and the corresponding key and values arrays would still match. The only caveat would be if you decided to manipulate the keys array independently after getting it from the HashMap. Thanks, Thomas Ginter 801-448-7676 thomas.gin...@utah.edu On Oct 17, 2013, at 8:43 AM, armin.weg...@bka.bund.de wrote: Hi Thomas, thanks for your answer. Using HashMap, does the n-th element of keySet() always corresponds to the n-th element of values()? Is this a defined behavior in Java? Cheers, Armin -Ursprüngliche Nachricht- Von: Thomas Ginter [mailto:thomas.gin...@utah.edu] Gesendet: Mittwoch, 16. Oktober 2013 18:53 An: user@uima.apache.org Betreff: Re: HashMap as type feature 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
XmiCasSerializer error in UIMA-AS
Hi all, I have an AE that produces the error below when deployed as a UIMA-AS 2.4.0 service. The same AE as part of a UIMA 2.4.2 CPE or a uimafit 2.* pipeline does not produce any errors and works as expected. Among other things, this AE uses ruta rules to process the CAS. When the rules are not used, the AE works as expected in both UIMA and UIMA-AS. I have tried to log all annotations generated by the AE when the rules are used and just before the AE processing is finished. The annotations seem the same in both the UIMA and the UIMA-AS processing scenarios. Does anyone have hints on what the cause of this might be or how I should proceed in debugging? Many thanks in advance, Prokopis WARNING: java.lang.ArrayIndexOutOfBoundsException at org.apache.uima.internal.util.IntVector.remove(IntVector.java:207) at org.apache.uima.internal.util.IntSet.remove(IntSet.java:77) at org.apache.uima.cas.impl.FSIndexRepositoryImpl.processIndexUpdates(FSIndexRepositoryImpl.java:1756) at org.apache.uima.cas.impl.FSIndexRepositoryImpl.isModified(FSIndexRepositoryImpl.java:1800) at org.apache.uima.cas.impl.XmiCasSerializer$XmiCasDocSerializer.serialize(XmiCasSerializer.java:256) at org.apache.uima.cas.impl.XmiCasSerializer$XmiCasDocSerializer.access$700(XmiCasSerializer.java:108) at org.apache.uima.cas.impl.XmiCasSerializer.serialize(XmiCasSerializer.java:1566) at org.apache.uima.aae.UimaSerializer.serializeCasToXmi(UimaSerializer.java:160) at org.apache.uima.adapter.jms.activemq.JmsOutputChannel.serializeCAS(JmsOutputChannel.java:237) at org.apache.uima.adapter.jms.activemq.JmsOutputChannel.getSerializedCas(JmsOutputChannel.java:1223) at org.apache.uima.adapter.jms.activemq.JmsOutputChannel.sendReply(JmsOutputChannel.java:786) at org.apache.uima.aae.controller.PrimitiveAnalysisEngineController_impl.process(PrimitiveAnalysisEngineController_impl.java:1036) at org.apache.uima.aae.handler.HandlerBase.invokeProcess(HandlerBase.java:121) at org.apache.uima.aae.handler.input.ProcessRequestHandler_impl.handleProcessRequestFromRemoteClient(ProcessRequestHandler_impl.java:542) at org.apache.uima.aae.handler.input.ProcessRequestHandler_impl.handle(ProcessRequestHandler_impl.java:1041) at org.apache.uima.aae.handler.input.MetadataRequestHandler_impl.handle(MetadataRequestHandler_impl.java:78) at org.apache.uima.adapter.jms.activemq.JmsInputChannel.onMessage(JmsInputChannel.java:706) at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:535) at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:495) at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:467) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1058) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:952) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at org.apache.uima.aae.UimaAsThreadFactory$1.run(UimaAsThreadFactory.java:118) at java.lang.Thread.run(Thread.java:724)
Re: HashMap as type feature
You could also use the entrySet which gives you all the key/value pairs. -- Richard On 17.10.2013, at 16:43, armin.weg...@bka.bund.de wrote: Hi Thomas, thanks for your answer. Using HashMap, does the n-th element of keySet() always corresponds to the n-th element of values()? Is this a defined behavior in Java? Cheers, Armin
Re: HashMap as type feature
Looks good, I will try it. Thank you, Armin On 10/17/13, Richard Eckart de Castilho r...@apache.org wrote: You could also use the entrySet which gives you all the key/value pairs. -- Richard On 17.10.2013, at 16:43, armin.weg...@bka.bund.de wrote: Hi Thomas, thanks for your answer. Using HashMap, does the n-th element of keySet() always corresponds to the n-th element of values()? Is this a defined behavior in Java? Cheers, Armin