Return-Path: X-Original-To: apmail-uima-user-archive@www.apache.org Delivered-To: apmail-uima-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 3007F96C7 for ; Wed, 18 Apr 2012 23:08:10 +0000 (UTC) Received: (qmail 36427 invoked by uid 500); 18 Apr 2012 23:08:09 -0000 Delivered-To: apmail-uima-user-archive@uima.apache.org Received: (qmail 36397 invoked by uid 500); 18 Apr 2012 23:08:08 -0000 Mailing-List: contact user-help@uima.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@uima.apache.org Delivered-To: mailing list user@uima.apache.org Received: (qmail 36388 invoked by uid 99); 18 Apr 2012 23:08:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Apr 2012 23:08:08 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of msa@schor.com designates 67.18.44.25 as permitted sender) Received: from [67.18.44.25] (HELO gateway11.websitewelcome.com) (67.18.44.25) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 18 Apr 2012 23:08:00 +0000 Received: by gateway11.websitewelcome.com (Postfix, from userid 5011) id 4F07F37FB526C; Wed, 18 Apr 2012 18:07:39 -0500 (CDT) Received: from gator74.hostgator.com (gator74.hostgator.com [184.173.199.208]) by gateway11.websitewelcome.com (Postfix) with ESMTP id 400E937FB5246 for ; Wed, 18 Apr 2012 18:07:39 -0500 (CDT) Received: from [129.34.20.19] (port=23698 helo=[9.2.34.182]) by gator74.hostgator.com with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.69) (envelope-from ) id 1SKdyN-0002gG-0B for user@uima.apache.org; Wed, 18 Apr 2012 18:07:39 -0500 Message-ID: <4F8F4938.5070409@schor.com> Date: Wed, 18 Apr 2012 19:07:36 -0400 From: Marshall Schor User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 MIME-Version: 1.0 To: user@uima.apache.org Subject: Re: annotation type References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator74.hostgator.com X-AntiAbuse: Original Domain - uima.apache.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - schor.com X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: yktgi01e0-s5.watson.ibm.com ([9.2.34.182]) [129.34.20.19]:23698 X-Source-Auth: msa+schor.com X-Email-Count: 1 X-Source-Cap: bWlzY2hvcjttaXNjaG9yO2dhdG9yNzQuaG9zdGdhdG9yLmNvbQ== X-Virus-Checked: Checked by ClamAV on apache.org You've tripped over a bit of Java arcania... The fix is to change the line: Iterator itr = jcas.getJFSIndexRepository().getAnnotationIndex(ann.type).iterator(); to Iterator itr = jcas.getJFSIndexRepository().getAnnotationIndex(ann.getTypeIndexID()).iterator(); The reason is that we make the size of JCas java objects as small as possible. One way we do that is to take fields which are the same for every instance of a particular JCas class, and move them into the class, as class-level fields, so they are not present in each instance. Java, when you write Annotator a = ... ; a.type computes type as a class field reference to the value in the class "Annotator" which you declared "a" to be. What you wanted was for Java to look at the class for the instance of a, and use that class's "type" field value, but that's not how Java is designed. To get around this, we've put in a method, getTypeIndexID(), which gets the field value from the class of the actual instance the method is called on. If there is some documentation page somewhere that led you to use .type instead of .getTypeIndexID(), please reply so we can improve the documentation. -Marshall On 4/10/2012 11:10 PM, vinod wrote: > Hello, > I have a very basic question on Annotation type and > would appreciate any pointers. > > I am using reflection to create an instance of an annotation, > before I add it to the cas, I want to check to > see if there is an instance of that type in the cas. However, the line > 'jcas.getJFSIndexRepository().getAnnotationIndex(ann.type).iterator();' > below returns a non-zero set > containing DocumentAnnotation! > >
>    Class uimaTypeClass = Class.forName(objectName);
>    Class[] constructorArgs = {JCas.class};
>    Object[] constructorArgVals = {jcas};
> 		
>    Constructor constructor = uimaTypeClass.getConstructor(constructorArgs);
>    Annotation ann = (Annotation)constructor.newInstance(constructorArgVals);
> 		
>    Iterator itr = jcas.getJFSIndexRepository().getAnnotationIndex(ann.type).iterator();
> 			
>    if(itr.hasNext()){
> 	ann = (Annotation)itr.next();
>    }
> 
> > Thanks. > >