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 8BCB810BF5 for ; Mon, 31 Mar 2014 19:56:59 +0000 (UTC) Received: (qmail 73898 invoked by uid 500); 31 Mar 2014 19:56:58 -0000 Delivered-To: apmail-uima-user-archive@uima.apache.org Received: (qmail 73693 invoked by uid 500); 31 Mar 2014 19:56:57 -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 73678 invoked by uid 99); 31 Mar 2014 19:56:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Mar 2014 19:56:54 +0000 X-ASF-Spam-Status: No, hits=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: local policy) Received: from [155.97.131.71] (HELO ipo3.cc.utah.edu) (155.97.131.71) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 31 Mar 2014 19:56:48 +0000 X-SBRS: None X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AqAEAJbHOVObYbVm/2dsb2JhbABWA4QYwyKBN3SCJQEBAQMBOkQLAgEINhAyJQEBBBOHcQjKM4YIF45MIxcRgxOBFASUYoNskjWDMIIr X-IPAS-Result: AqAEAJbHOVObYbVm/2dsb2JhbABWA4QYwyKBN3SCJQEBAQMBOkQLAgEINhAyJQEBBBOHcQjKM4YIF45MIxcRgxOBFASUYoNskjWDMIIr X-IronPort-AV: E=Sophos;i="4.97,767,1389769200"; d="scan'208";a="344127165" Received: from h102.umail.utah.edu (HELO X-HUB2.xds.umail.utah.edu) ([155.97.181.102]) by ipo3smtp.cc.utah.edu with ESMTP/TLS/AES128-SHA; 31 Mar 2014 13:56:24 -0600 Received: from X-MB1.xds.umail.utah.edu ([169.254.1.4]) by X-HUB2.xds.umail.utah.edu ([155.97.181.102]) with mapi id 14.03.0158.001; Mon, 31 Mar 2014 13:56:24 -0600 From: Thomas Ginter To: "user@uima.apache.org" Subject: Re: FilteredIterator is very slow Thread-Topic: FilteredIterator is very slow Thread-Index: Ac9NCVioa1j39iBuQf+mmqoaQdV18wARDwQA Date: Mon, 31 Mar 2014 19:56:23 +0000 Message-ID: <68C2DF13-2495-4714-A69A-6B6971193C99@utah.edu> References: In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [155.97.183.136] Content-Type: text/plain; charset="us-ascii" Content-ID: <47E67E2E83BED34DB331E477843DC89C@umail.utah.edu> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Virus-Checked: Checked by ClamAV on apache.org Larry, A faster way to get the list of types that you will skip would be to do the= following: FSIndex titlePersonHAIndex =3D aJCas.getAnn= otationIndex(TitlePersonHonorificAnnotation.type); Doing this for each type will yield an index that points to just the annota= tions in the CAS of each type you are interested in. From there you can ge= t an iterator reference ( titlePersonHAIndex.iterator() ) and either traver= se each one separately or else add them to a common Collection such as an A= rrayList and iterate through that. You could also take advantage of the fa= ct that the default index in UIMA sorts on ascending order on the begin ind= ex and descending order on the ending index to stop once you have traversed= the list past the ending index of the dictTerm. =20 An important design decision though would be to consider whether the dictTe= rm annotations are much more numerous than the TitlePersonHonorificAnnotati= on, MeasurementAnnotation, and ProgFactorTerm filtering annotation types. = Generally if the filter types are much more plentiful and the dictTerm type= was more rare then looking for overlapping filter types will yield fewer i= terations of your algorithm, however if there are a lot of dictTerm occurre= nces and only a few of the filter types then it may be more efficient to it= erate through the filter types and eliminate dictTerms that overlap or are = covered. =20 Thanks, Thomas Ginter 801-448-7676 thomas.ginter@utah.edu On Mar 31, 2014, at 11:47 AM, Kline, Larry wrote= : > When I use a filtered FSIterator it's an order of magnitude slower than a= non-filtered iterator. Here's my code: >=20 > Create the iterator: > private FSIterator createConstrainedIterator(JCas aJCas= ) throws CASException { > FSIterator it =3D aJCas.getAnnotationIndex().ite= rator(); > FSTypeConstraint constraint =3D aJCas.getConstraintFactory()= .createTypeConstraint(); > constraint.add((new TitlePersonHonorificAnnotation(aJCas)).g= etType()); > constraint.add((new MeasurementAnnotation(aJCas)).getType())= ; > constraint.add((new ProgFactorTerm(aJCas)).getType()); > it =3D aJCas.createFilteredIterator(it, constraint); > return it; > } > Use the iterator: > public void process(JCas aJCas) throws AnalysisEngineProcessExcepti= on { > ... > // The following is done in a loop > if (shouldSkip(dictTerm, skipIter)) > continue; > ... > } > Here's the method called: > private boolean shouldSkip(G2DictTerm dictTerm, FSIterator skipIter) throws CASException { > boolean shouldSkip =3D false; > skipIter.moveToFirst(); > while (skipIter.hasNext()) { > Annotation annotation =3D skipIter.next(); > if (UIMAUtils.annotationsOverlap(dictTerm, annotation= )) { > shouldSkip =3D true; > break; > } > } > return shouldSkip; > } >=20 > If I change the method, createConstrainedIterator(), to this (that is, no= constraints): > private FSIterator createConstrainedIterator(JCas aJCas= ) throws CASException { > FSIterator it =3D aJCas.getAnnotationIndex().ite= rator(); > return it; > } >=20 > It runs literally 10 times faster. Doing some profiling I see that all o= f the time is spent in the skipIter.moveToFirst() call. I also tried creat= ing the filtered iterator each time anew in the shouldSkip() method instead= of passing it in, but that has even slightly worse performance. >=20 > Given this performance I suppose I should probably use a non-filtered ite= rator and just check for the types I'm interested in inside the loop. >=20 > Any other suggestions welcome. >=20 > Thanks, > Larry Kline >=20 >=20