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 2017/10/30 17:26:53 UTC
svn commit: r1813806 - in
/uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial:
ex1/RoomNumberAnnotator.java ex2/RoomNumberAnnotator.java
ex4/MeetingAnnotator.java ex5/RoomNumberAnnotator.java
Author: schor
Date: Mon Oct 30 17:26:53 2017
New Revision: 1813806
URL: http://svn.apache.org/viewvc?rev=1813806&view=rev
Log:
[UIMA-5625] uv3 idioms in examples
Modified:
uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex1/RoomNumberAnnotator.java
uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex2/RoomNumberAnnotator.java
uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex4/MeetingAnnotator.java
uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex5/RoomNumberAnnotator.java
Modified: uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex1/RoomNumberAnnotator.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex1/RoomNumberAnnotator.java?rev=1813806&r1=1813805&r2=1813806&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex1/RoomNumberAnnotator.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex1/RoomNumberAnnotator.java Mon Oct 30 17:26:53 2017
@@ -41,22 +41,18 @@ public class RoomNumberAnnotator extends
// get document text
String docText = aJCas.getDocumentText();
// search for Yorktown room numbers
- Matcher matcher = mYorktownPattern.matcher(docText);
- while (matcher.find()) {
+ Matcher m = mYorktownPattern.matcher(docText);
+ while (m.find()) {
// found one - create annotation
- RoomNumber annotation = new RoomNumber(aJCas);
- annotation.setBegin(matcher.start());
- annotation.setEnd(matcher.end());
+ RoomNumber annotation = new RoomNumber(aJCas, m.start(), m.end());
annotation.setBuilding("Yorktown");
annotation.addToIndexes();
}
// search for Hawthorne room numbers
- matcher = mHawthornePattern.matcher(docText);
- while (matcher.find()) {
+ m = mHawthornePattern.matcher(docText);
+ while (m.find()) {
// found one - create annotation
- RoomNumber annotation = new RoomNumber(aJCas);
- annotation.setBegin(matcher.start());
- annotation.setEnd(matcher.end());
+ RoomNumber annotation = new RoomNumber(aJCas, m.start(), m.end());
annotation.setBuilding("Hawthorne");
annotation.addToIndexes();
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex2/RoomNumberAnnotator.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex2/RoomNumberAnnotator.java?rev=1813806&r1=1813805&r2=1813806&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex2/RoomNumberAnnotator.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex2/RoomNumberAnnotator.java Mon Oct 30 17:26:53 2017
@@ -67,9 +67,7 @@ public class RoomNumberAnnotator extends
Matcher matcher = mPatterns[i].matcher(docText);
while (matcher.find()) {
// found one - create annotation
- RoomNumber annotation = new RoomNumber(aJCas);
- annotation.setBegin(matcher.start());
- annotation.setEnd(matcher.end());
+ RoomNumber annotation = new RoomNumber(aJCas, matcher.start(), matcher.end());
annotation.addToIndexes();
annotation.setBuilding(mLocations[i]);
getLogger().log(Level.FINEST, "Found: " + annotation);
Modified: uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex4/MeetingAnnotator.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex4/MeetingAnnotator.java?rev=1813806&r1=1813805&r2=1813806&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex4/MeetingAnnotator.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex4/MeetingAnnotator.java Mon Oct 30 17:26:53 2017
@@ -57,54 +57,40 @@ public class MeetingAnnotator extends JC
*/
public void process(JCas aJCas) {
// get annotation indexes
- FSIndex roomNumberIndex = aJCas.getAnnotationIndex(RoomNumber.type);
- FSIndex dateIndex = aJCas.getAnnotationIndex(DateAnnot.type);
- FSIndex timeIndex = aJCas.getAnnotationIndex(TimeAnnot.type);
+ FSIndex<RoomNumber> roomNumberIndex = aJCas.getAnnotationIndex(RoomNumber.class);
+ FSIndex<DateAnnot> dateIndex = aJCas.getAnnotationIndex(DateAnnot.class);
+ FSIndex<TimeAnnot> timeIndex = aJCas.getAnnotationIndex(TimeAnnot.class);
// store end position of last meeting we identified, to prevent multiple
// annotations over same span
int lastMeetingEnd = -1;
- // iterate over all combinations
- Iterator roomNumberIter = roomNumberIndex.iterator();
- while (roomNumberIter.hasNext()) {
- RoomNumber room = (RoomNumber) roomNumberIter.next();
-
- Iterator dateIter = dateIndex.iterator();
- while (dateIter.hasNext()) {
- DateAnnot date = (DateAnnot) dateIter.next();
-
- Iterator time1Iter = timeIndex.iterator();
- while (time1Iter.hasNext()) {
- TimeAnnot time1 = (TimeAnnot) time1Iter.next();
-
- Iterator time2Iter = timeIndex.iterator();
- while (time2Iter.hasNext()) {
- TimeAnnot time2 = (TimeAnnot) time2Iter.next();
+ for (RoomNumber room : roomNumberIndex.select()) {
+ for (DateAnnot date : dateIndex.select()) {
+ for(TimeAnnot time1 : timeIndex.select()) {
+ for (TimeAnnot time2 : timeIndex.select()) {
// times must be different annotations
if (time1 != time2) {
// compute the begin and end of the span
- int minBegin = Math.min(Math.min(time1.getBegin(), time2.getBegin()), Math.min(date
- .getBegin(), room.getBegin()));
- int maxEnd = Math.max(Math.max(time1.getEnd(), time2.getEnd()), Math.max(date
- .getEnd(), room.getEnd()));
+ int minBegin = Math.min(Math.min(time1.getBegin(), time2.getBegin()),
+ Math.min(date .getBegin(), room .getBegin()));
+ int maxEnd = Math.max(Math.max(time1.getEnd(), time2.getEnd()),
+ Math.max(date .getEnd(), room .getEnd()));
// span must be smaller than the window size?
- if (maxEnd - minBegin < mWindowSize) {
+ if (maxEnd - minBegin < mWindowSize &&
// span must not overlap the last annotation we made
- if (minBegin > lastMeetingEnd) {
- // annotate
- Meeting mtg = new Meeting(aJCas, minBegin, maxEnd, room, date, time1, time2);
- mtg.addToIndexes();
- lastMeetingEnd = maxEnd;
- }
+ minBegin > lastMeetingEnd) {
+ // annotate
+ Meeting mtg = new Meeting(aJCas, minBegin, maxEnd, room, date, time1, time2);
+ mtg.addToIndexes();
+ lastMeetingEnd = maxEnd;
}
}
}
}
- }
+ }
}
}
-
}
Modified: uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex5/RoomNumberAnnotator.java
URL: http://svn.apache.org/viewvc/uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex5/RoomNumberAnnotator.java?rev=1813806&r1=1813805&r2=1813806&view=diff
==============================================================================
--- uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex5/RoomNumberAnnotator.java (original)
+++ uima/uv3/uimaj-v3/trunk/uimaj-examples/src/main/java/org/apache/uima/tutorial/ex5/RoomNumberAnnotator.java Mon Oct 30 17:26:53 2017
@@ -74,11 +74,9 @@ public class RoomNumberAnnotator extends
Matcher matcher = mPatterns[i].matcher(docText);
while (matcher.find()) {
// found one - create annotation
- RoomNumber annotation = new RoomNumber(aJCas);
- annotation.setBegin(matcher.start());
- annotation.setEnd(matcher.end());
- annotation.addToIndexes();
+ RoomNumber annotation = new RoomNumber(aJCas, matcher.start(), matcher.end());
annotation.setBuilding(mLocations[i]);
+ annotation.addToIndexes();
getContext().getLogger().log(Level.FINEST, "Found: " + annotation);
}
}