@Test public void testCreateDocumentTextTokens() throws Exception{ JCas cas = createCasWithText("token1 token2 token3"); Annotation1 annotation1 = new Annotation1(cas); annotation1.setBegin(0); annotation1.setEnd(6); annotation1.addToIndexes(); Annotation1 annotation2 = new Annotation1(cas); annotation2.setBegin(7); annotation2.setEnd(13); annotation2.addToIndexes(); Annotation1 annotation3 = new Annotation1(cas); annotation3.setBegin(14); annotation3.setEnd(20); annotation3.addToIndexes(); AnnotationTokenStream annotationTokenStream = new AnnotationTokenStream(cas, CAS.NAME_DEFAULT_SOFA, "org.apache.uima.lucas.indexer.types.test.Annotation1"); Token nextToken = annotationTokenStream.next(); assertNotNull(nextToken); assertEquals("token1", new String(nextToken.termBuffer(), 0, nextToken.termLength())); assertEquals(0, nextToken.startOffset()); assertEquals(6, nextToken.endOffset()); nextToken = annotationTokenStream.next(); assertNotNull(nextToken); assertEquals("token2", new String(nextToken.termBuffer(), 0, nextToken.termLength())); assertEquals(7, nextToken.startOffset()); assertEquals(13, nextToken.endOffset()); nextToken = annotationTokenStream.next(); assertNotNull(nextToken); assertEquals("token3", new String(nextToken.termBuffer(), 0, nextToken.termLength())); assertEquals(14, nextToken.startOffset()); assertEquals(20, nextToken.endOffset()); }
@Override public Token next(Token token) throws IOException { while (!featureValueIterator.hasNext()) { while (!featureStructureIterator.hasNext()) { if (!annotationIterator.hasNext()) return null; currentAnnotation = (Annotation) annotationIterator.next(); featureStructureIterator = createFeatureStructureIterator( currentAnnotation, featurePath); } featureValueIterator = createFeatureValueIterator( featureStructureIterator.next(), featureNames); } token.reinit(new Token()); token.setStartOffset(currentAnnotation.getBegin()); token.setEndOffset(currentAnnotation.getEnd()); char[] value = featureValueIterator.next().toCharArray(); token.setTermBuffer(value, 0, value.length); return token; }
AnnotationTokenStream extends TokenStream { @Override public Token next(Token token) throws IOException { while (!featureValueIterator.hasNext()) { while (!featureStructureIterator.hasNext()) { if (!annotationIterator.hasNext()) return null; currentAnnotation = (Annotation) annotationIterator.next(); featureStructureIterator = createFeatureStructureIterator( currentAnnotation, featurePath); } featureValueIterator = createFeatureValueIterator( featureStructureIterator.next(), featureNames); } token.reinit(new Token()); token.setStartOffset(currentAnnotation.getBegin()); token.setEndOffset(currentAnnotation.getEnd()); char[] value = featureValueIterator.next().toCharArray(); token.setTermBuffer(value, 0, value.length); return token; } }
AnnotationTokenStream extends TokenStream { @Override public Token next(Token token) throws IOException { while (!featureValueIterator.hasNext()) { while (!featureStructureIterator.hasNext()) { if (!annotationIterator.hasNext()) return null; currentAnnotation = (Annotation) annotationIterator.next(); featureStructureIterator = createFeatureStructureIterator( currentAnnotation, featurePath); } featureValueIterator = createFeatureValueIterator( featureStructureIterator.next(), featureNames); } token.reinit(new Token()); token.setStartOffset(currentAnnotation.getBegin()); token.setEndOffset(currentAnnotation.getEnd()); char[] value = featureValueIterator.next().toCharArray(); token.setTermBuffer(value, 0, value.length); return token; } AnnotationTokenStream(JCas jCas, String sofaName, String typeName);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featureName, Format featureFormat);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			List<String> featureNames, String delimiter,
			Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			List<String> featureNames, Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featurePath, List<String> featureNames,
			Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featurePath, List<String> featureNames, String delimiter,
			Map<String, Format> featureFormats); }
AnnotationTokenStream extends TokenStream { @Override public Token next(Token token) throws IOException { while (!featureValueIterator.hasNext()) { while (!featureStructureIterator.hasNext()) { if (!annotationIterator.hasNext()) return null; currentAnnotation = (Annotation) annotationIterator.next(); featureStructureIterator = createFeatureStructureIterator( currentAnnotation, featurePath); } featureValueIterator = createFeatureValueIterator( featureStructureIterator.next(), featureNames); } token.reinit(new Token()); token.setStartOffset(currentAnnotation.getBegin()); token.setEndOffset(currentAnnotation.getEnd()); char[] value = featureValueIterator.next().toCharArray(); token.setTermBuffer(value, 0, value.length); return token; } AnnotationTokenStream(JCas jCas, String sofaName, String typeName);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featureName, Format featureFormat);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			List<String> featureNames, String delimiter,
			Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			List<String> featureNames, Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featurePath, List<String> featureNames,
			Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featurePath, List<String> featureNames, String delimiter,
			Map<String, Format> featureFormats); @Override Token next(Token token); @Override Token next(); String getValueForFeature(FeatureStructure featureStructure,
			Feature feature, Format format); void reset(); Map<String, Format> getFeatureFormats(); JCas getJCas(); String getFeaturePath(); List<String> getFeatureNames(); String getDelimiter(); Type getAnnotationType(); }
AnnotationTokenStream extends TokenStream { @Override public Token next(Token token) throws IOException { while (!featureValueIterator.hasNext()) { while (!featureStructureIterator.hasNext()) { if (!annotationIterator.hasNext()) return null; currentAnnotation = (Annotation) annotationIterator.next(); featureStructureIterator = createFeatureStructureIterator( currentAnnotation, featurePath); } featureValueIterator = createFeatureValueIterator( featureStructureIterator.next(), featureNames); } token.reinit(new Token()); token.setStartOffset(currentAnnotation.getBegin()); token.setEndOffset(currentAnnotation.getEnd()); char[] value = featureValueIterator.next().toCharArray(); token.setTermBuffer(value, 0, value.length); return token; } AnnotationTokenStream(JCas jCas, String sofaName, String typeName);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featureName, Format featureFormat);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			List<String> featureNames, String delimiter,
			Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			List<String> featureNames, Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featurePath, List<String> featureNames,
			Map<String, Format> featureFormats);  AnnotationTokenStream(JCas jCas, String sofaName, String typeName,
			String featurePath, List<String> featureNames, String delimiter,
			Map<String, Format> featureFormats); @Override Token next(Token token); @Override Token next(); String getValueForFeature(FeatureStructure featureStructure,
			Feature feature, Format format); void reset(); Map<String, Format> getFeatureFormats(); JCas getJCas(); String getFeaturePath(); List<String> getFeatureNames(); String getDelimiter(); Type getAnnotationType();  }