You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2020/01/10 18:55:41 UTC
[uima-uimaj] 01/01: [UIMA-6160] add startAt with one int,
incl doc and test
This is an automated email from the ASF dual-hosted git repository.
schor pushed a commit to branch feature/UIMA-6160-startAt-with-single-int-arg
in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit c5ab3a798aa1739ed36b110a83a2b1c95d422a7e
Author: Marshall Schor <ms...@schor.com>
AuthorDate: Fri Jan 10 13:55:24 2020 -0500
[UIMA-6160] add startAt with one int, incl doc and test
---
.../src/docbook/uv3.select.xml | 16 +++++++++-------
.../src/main/java/org/apache/uima/cas/SelectFSs.java | 11 +++++++++++
.../java/org/apache/uima/cas/impl/SelectFSs_impl.java | 7 +++++++
.../apache/uima/cas/test/AnnotationIteratorTest.java | 19 ++++++++++++-------
4 files changed, 39 insertions(+), 14 deletions(-)
diff --git a/uima-docbook-v3-users-guide/src/docbook/uv3.select.xml b/uima-docbook-v3-users-guide/src/docbook/uv3.select.xml
index 8d5cb47..4a04d79 100644
--- a/uima-docbook-v3-users-guide/src/docbook/uv3.select.xml
+++ b/uima-docbook-v3-users-guide/src/docbook/uv3.select.xml
@@ -421,18 +421,20 @@ FSIterator<Token> token_iterator =
<term><emphasis role="">startAt</emphasis></term>
<listitem>
<para>position the starting point of any iteration.
- <code>startAt(xxx)</code> takes two forms, each of which has, in turn 2 subforms.
- The form using <code>begin, end</code> is only valid for Annotation Indexes.
- <programlisting>startAt(fs); // fs specifies a feature structure
+ <code>startAt(...)</code> can be used for general sorted indexes, and also has special
+ formats only usable for Annotation Indexes.
+ <programlisting>// Forms for any sorted index
+startAt(fs); // fs specifies a feature structure
// indicating the starting position
startAt(fs, shifted); // same as above, but after positioning,
// shift to the right or left by the shift
- // amount which can be positive or negative
-
+ // amount which can be positive or negative
+
+// Forms for AnnotationIndex sources
-// the next two forms are only valid for AnnotationIndex sources
-
+startAt(begin); // sets no TypePriorities, and starts at the
+ // leftmost annotation whose begin is >= begin
startAt(begin, end); // start at the position indicated by begin/end
startAt(begin, end, shifted) // same as above,
diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/SelectFSs.java b/uimaj-core/src/main/java/org/apache/uima/cas/SelectFSs.java
index e2f6096..965cd81 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/SelectFSs.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/SelectFSs.java
@@ -226,6 +226,17 @@ public interface SelectFSs<T extends FeatureStructure> extends Iterable<T>, Stre
* @return the updated SelectFSs object
*/
SelectFSs<T> startAt(FeatureStructure fs);
+
+ /**
+ * Starting Position specification - For Annotation Indexes, specifies which FS to start at.
+ * Sets no typepriorities.
+ * Positions to the leftmost (if there are multiple equal ones) Annotation
+ * whose begin is >= begin
+ * @param begin the begin bound
+ * @return the updated SelectFSs object
+ */
+ SelectFSs<T> startAt(int begin); // requires Annotation Index, no type priorities
+
/**
* Starting Position specification - For Annotation Indexes, specifies which FS to start at.
* @param begin the begin bound
diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java b/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
index 36accf2..dc89c7e 100644
--- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
+++ b/uimaj-core/src/main/java/org/apache/uima/cas/impl/SelectFSs_impl.java
@@ -383,6 +383,13 @@ public class SelectFSs_impl <T extends FeatureStructure> implements SelectFSs<T>
// }
@Override
+ public SelectFSs_impl<T> startAt(int begin) {
+ this.isTypePriority = false;
+ this.startingFs = makePosAnnot(begin, Integer.MAX_VALUE);
+ return this;
+ }
+
+ @Override
public SelectFSs_impl<T> startAt(int begin, int end) { // AI
this.startingFs = makePosAnnot(begin, end);
return this;
diff --git a/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java b/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java
index 75bc739..7196a80 100644
--- a/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java
+++ b/uimaj-core/src/test/java/org/apache/uima/cas/test/AnnotationIteratorTest.java
@@ -204,7 +204,7 @@ public class AnnotationIteratorTest extends TestCase {
public void testIterator1() {
- int annotCount = setupTheCas();
+ final int annotCount = setupTheCas();
FSIndexRepository ir = this.cas.getIndexRepository();
/***************************************************
@@ -258,7 +258,7 @@ public class AnnotationIteratorTest extends TestCase {
* @param fss
*/
// called twice, the 2nd time should be with flattened indexes (List afss non empty the 2nd time)
- private void iterateOverAnnotations(int annotCount, List<Annotation> afss) {
+ private void iterateOverAnnotations(final int annotCount, List<Annotation> afss) {
this.fss = afss;
isSave = fss.size() == 0; // on first call is 0, so save on first call
// int count;
@@ -273,6 +273,8 @@ public class AnnotationIteratorTest extends TestCase {
assertEquals(annotCount, select(annotIndex).toArray().length); // stream op
assertEquals(annotCount, select(annotIndex).asArray(Annotation.class).length); // select op
+ assertEquals(annotCount - 5, annotIndex.select().startAt(2).asArray(Annotation.class).length);
+
Annotation[] tokensAndSentencesAndPhrases = annotIndex.select().asArray(Annotation.class);
JCas jcas = null;
try {
@@ -761,6 +763,9 @@ public class AnnotationIteratorTest extends TestCase {
// +--------+
// Sentences +--------+
// +----------+
+// one xtr sent +-----------------+ (12, 31)
+//
+// Phrases some overlap, some dont, 3-7 length
//
// bound4strict +------------------+
// sentence4strict +-----------------------------+
@@ -802,16 +807,16 @@ public class AnnotationIteratorTest extends TestCase {
}
}
- // create overlapping phrases
- // begin = 0, 6, 10, 14, ...
- // end = 5, 9, 16, 19, ...
+ // create overlapping and non-overlapping phrases
+ // begin = 0, 6, 9, 15, 21, 24, 30, 36, ...
+ // end = 5, 9, 16, 20, 24, 31, 35, 39, ...
int beginAlt = 0, endAlt = 0;
for (int i = 0; i < text.length() - 10; i += 5) {
++annotCount;
ir.addFS(fs = this.cas.createAnnotation(this.phraseType, i + beginAlt, i + 5 + endAlt));
- beginAlt = (beginAlt == 1) ? -1 : beginAlt + 1;
- endAlt = (endAlt == -1) ? 1 : endAlt - 1;
+ beginAlt = (beginAlt == 1) ? -1 : beginAlt + 1; // sequence: start @ 0, then 1, -1, 0, 1, ...
+ endAlt = (endAlt == -1) ? 1 : endAlt - 1; //sequence: start At 0, then -1, 1, 0, -1, ...
if (showFSs) {
System.out.format("creating: %d begin: %d end: %d type: %s%n", annotCount, fs.getBegin(), fs.getEnd(), fs.getType().getName() );
}