Hi Mario,
Have you defined the TypePriority[0] for your /SubType/ Annotation?

As per the /AnnotationIndex/ documentation[1] this property impacts the ordering of different annotation types with an equal span coverage:

 * Annotations whose start offsets are equal and whose end offsets are
   equal are sorted based on|TypePriorities|
   
<https://uima.apache.org/d/uimaj-current/apidocs/org/apache/uima/resource/metadata/TypePriorities.html>if
   type priorities are specified. Type Priorities specification is an
   optional element of the component descriptor). When type priorities
   are in use, if|a.start = b.start|,|a.end = b.end|, and the type
   of|a|is defined before the type of|b|in the type priorities, then|a
   < b|.
 * If none of the above rules apply, then the ordering is arbitrary.
   This will occur if you have two annotations of the exact same type
   that also have the same span. It will also occur if you have not
   defined any type priority between two annotations that have the same
   span.


Hope this helps.

Bye,
/Raf/


[0] https://uima.apache.org/d/uimaj-current/apidocs/org/apache/uima/resource/metadata/TypePriorities.html

[1] https://uima.apache.org/d/uimaj-current/apidocs/org/apache/uima/cas/text/AnnotationIndex.html


On 02/11/20 22:16, Mario Juric wrote:
Hi,

I am migrating some code to the new UIMA v3 select API, and I am seeing some 
odd behaviour. My reference implementation is the good old 
JCasUtil.selectCovered, which I am trying to replace first, and I thought the 
following line should do it:

jCas.select(annotationType).coveredBy(annotation)

This works fine as long annotation is of annotationType, but I am seeing some strange 
different output when annotation is of a different Annotation subtype. More 
specifically I have a unit test (see bottom) where annotationType is the Annotation 
class and annotation is an instance of some direct subtype of Annotation, which was 
added to the CAS index prior to the call. In this case all annotations that have the 
exact same bounds as annotation are not selected, only those that are completely 
enclosed get selected (begin > annotation.getBegin() and end < 
annotation.getEnd()). The JCasUtil includes the missing annotations.

None of the available select configurations seem to address this, and 
superficially stepping through the code didn’t help me much, since it’s not 
trivial to get into the details of the underlying API, so I thought that I 
maybe get a faster answer here.

Cheers
Mario


@Test
public void verify_selectCovered() throws CASException, 
ResourceInitializationException {
     JCas jCas = JCasFactory.createJCas();
     Annotation[] fixture = new Annotation[] {
             new Annotation(jCas, 5, 10),
             new Annotation(jCas, 5, 15),
             new Annotation(jCas, 0, 10),
             new Annotation(jCas, 0, 15),
             new Annotation(jCas, 5, 7),
             new Annotation(jCas, 8, 10),
             new Annotation(jCas, 6, 9),
             new Annotation(jCas, 5, 10)
     };
     Stream.of(fixture).forEach(Annotation::addToIndexes);

     assertEquals(4, JCasUtil.selectCovered(jCas, Annotation.class, 
fixture[0]).size());

     List<Annotation> selection1 = jCas.select(Annotation.class)
             .coveredBy(fixture[0])
             .collect(Collectors.toList());

     assertEquals(4, selection1.size());

     SubType subType = new SubType(jCas, 5, 10);
     subType.addToIndexes();

     assertEquals(5, JCasUtil.selectCovered(jCas, Annotation.class, 
subType).size());

     List<Annotation> selection2 = jCas.select(Annotation.class)
             .coveredBy(subType)
             .collect(Collectors.toList());

     assertEquals(5, selection2.size()); // Fails!
}


________________________________
Disclaimer:
This email and any files transmitted with it are confidential and directed 
solely for the use of the intended addressee or addressees and may contain 
information that is legally privileged, confidential, and exempt from 
disclosure. If you have received this email in error, please notify the sender 
by telephone, fax, or return email and immediately delete this email and any 
files transmitted along with it. Unintended recipients are not authorized to 
disclose, disseminate, distribute, copy or take any action in reliance on 
information contained in this email and/or any files attached thereto, in any 
manner other than to notify the sender; any unauthorized use is subject to 
legal prosecution.


--
*Raffaella Ventaglio*
Senior Software Architect

--



*CELI srl*
via San Quintino, 31 - Torino  <https://www.google.com/maps/place/Via+S.+Quintino,+31,+10121+Torino+TO/@45.0668691,7.6684529,17z/data=%213m1%214b1%214m5%213m4%211s0x47886d13c6b49f81:0x2b74ae2a12fca9de%218m2%213d45.0668653%214d7.6706416> Torino IT – 10121 <https://www.google.com/maps/place/Via+S.+Quintino,+31,+10121+Torino+TO/@45.0668691,7.6684529,17z/data=%213m1%214b1%214m5%213m4%211s0x47886d13c6b49f81:0x2b74ae2a12fca9de%218m2%213d45.0668653%214d7.6706416>

*
*
*T  *+39 011 5627115
*W  *www.celi.it <https://www.celi.it/>

Reply via email to