On 03/11/20 11:19, Mario Juric wrote:
Thanks Rafaella.

We haven’t had any need for type priorities yet, so we don’t use this feature 
at all. I am not sure, how the problem I am describing, where these annotations 
are not included in the selection, can be caused by arbitrary ordering?

Hi, unfortunately I can't try your example at the moment, but if `/JCasUtil.selectCovered/` behavior is similar to `AnnotationIndex.subiterator` behavior, than having an arbitrary ordering between your annotation types could impact the definition of "covered by".

I am referring to this passage in the /subiterator/ JavaDoc:

For annotations x, y,|x < y|here is to be interpreted as "x comes before y in the index", according to the rules defined in the description of|this class| <https://uima.apache.org/d/uimaj-current/apidocs/org/apache/uima/cas/text/AnnotationIndex.html>.

This definition implies that annotations|b|that have the same span as|annot|may or may not be returned by the subiterator. This is determined by the type priorities; the subiterator will only return such an annotation|b|if the type of|annot|precedes the type of|b|in the type priorities definition. If you have not specified the priority, or if|annot|and|b|are of the same type, then the behavior is undefined.


Bye,

/Raf/




Cheers
Mario

On 3 Nov 2020, at 09.49, Raffaella Ventaglio <raffaella.ventag...@celi.it> 
wrote:

External email – Do not click links or open attachments unless you recognize 
the sender and know that the content is safe.


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/>

________________________________
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