Skip to content

Commit 980f2f8

Browse files
Angel ChangAngledLuffa
authored andcommitted
Add limit to AnnotationIterator
1 parent a5340a4 commit 980f2f8

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/edu/stanford/nlp/pipeline/AnnotationIterator.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class AnnotationIterator extends AbstractIterator<Annotation> implements
2626
JSONAnnotationReader jsonReader = new JSONAnnotationReader();
2727
String format;
2828
int docCnt = 0;
29+
int limit = 0;
2930

3031
public AnnotationIterator(String filename) throws IOException {
3132
this.filename = filename;
@@ -45,6 +46,11 @@ public AnnotationIterator(String filename) throws IOException {
4546
nextDoc = readNextDocument();
4647
}
4748

49+
public AnnotationIterator(String filename, int limit) throws IOException {
50+
this(filename);
51+
this.limit = limit;
52+
}
53+
4854
@Override
4955
public boolean hasNext() {
5056
return nextDoc != null;
@@ -68,6 +74,9 @@ public Annotation readNextDocument() {
6874
if (br == null && input == null) {
6975
return null;
7076
}
77+
if (limit > 0 && docCnt >= limit) {
78+
return null;
79+
}
7180
try {
7281
if (serializer != null) {
7382
if (input.available() > 0) {

0 commit comments

Comments
 (0)