uima-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marshall Schor <...@schor.com>
Subject Re: How to override hashCode for a feature structure ?
Date Mon, 04 Apr 2011 21:40:44 GMT
I think the framework may be making more assumptions about feature structure
hashcodes and equals.

It might be better to use some kind of aggregation in your annotator, instead of
subclassing.  The idea would be to create a new Java class which contained a
reference to the feature structure instance, but implemented whatever you needed
for hashcode and equals.  This would then be outside of any object that the UIMA
Framework would know about, so you couldn't break anything...

This would cost an extra Java object per feature structure, however, unless your
application already was making use of a similar kind of object for other reasons...


On 4/4/2011 7:42 AM, Philippe Vanden Bossche wrote:
> Hello everyone,
> I'm pretty new to UIMA and I'm currently developping a statistical annotator
> that has to use a hashtable for efficiency purposes (I need to store all
> annotations based on several feature values and to be able to retrieve
> efficiently one of them knowing these feature values).
> I then wanted to implement a specific hash function (hashCode) and equals
> method to map two different feature structures (but considered equal) into
> the same hashCode value. So I have tried to override the hashCode method of
> my feature structure class.
> However after that, the UIMA CAS Visual Debugger crashed completely.
> After a little analysis of the stacktrace and the source code, it seems that
> it comes from the class FSTreeModel at line 80: we use "fs.hashCode()"
> (making the assumption that this returns an address).
> So my question is : is there another known way of doing what I want (without
> too performance costs) or is it necessary to change this "fs.hashCode()"
> into something like "((TOP) fs).getAddress()" ?
> For further informations, here is a part of the stack trace and the hashCode
> method that caused it (contained in a class extending AnnotationBase):
> Exception in thread "AWT-EventQueue-0"
> java.lang.ArrayIndexOutOfBoundsException: 3347558
>  at org.apache.uima.cas.impl.CASImpl.getHeapValue(CASImpl.java:1957)
>  at org.apache.uima.tools.cvd.FSNode.getType(FSNode.java:331)
>  at org.apache.uima.tools.cvd.FSNode.initChildren(FSNode.java:107)
>  at org.apache.uima.tools.cvd.FSTreeNode.getChildCount(FSTreeNode.java:55)
>  at
> org.apache.uima.tools.cvd.FSTreeModel.getChildCount(FSTreeModel.java:180)
>  at org.apache.uima.tools.cvd.FSTreeModel.isLeaf(FSTreeModel.java:187)
> public int hashCode() {
>  int hashCode = 1;
>  for(int i = 0; i < this.getLemmas().size(); i++)
>  {
>  String lemma = this.getLemmas().get(i);
>  hashCode = 31 * hashCode + (lemma == null ? 0 : lemma.hashCode());
>  }
>  return hashCode;
> }

View raw message