use of org.deeplearning4j.text.sentenceiterator.labelaware.LabelAwareListSentenceIterator in project deeplearning4j by deeplearning4j.
the class SentenceIteratorTest method testLabelAware.
@Test
public void testLabelAware() throws Exception {
String s = "1; hello";
ByteArrayInputStream bis = new ByteArrayInputStream(s.getBytes());
LabelAwareSentenceIterator labelAwareSentenceIterator = new LabelAwareListSentenceIterator(bis, ";", 0, 1);
assertTrue(labelAwareSentenceIterator.hasNext());
labelAwareSentenceIterator.nextSentence();
assertEquals("1", labelAwareSentenceIterator.currentLabel());
InputStream is2 = new ClassPathResource("labelawaresentenceiterator.txt").getInputStream();
LabelAwareSentenceIterator labelAwareSentenceIterator2 = new LabelAwareListSentenceIterator(is2, ";", 0, 1);
int count = 0;
Map<Integer, String> labels = new HashMap<>();
while (labelAwareSentenceIterator2.hasNext()) {
String sentence = labelAwareSentenceIterator2.nextSentence();
labels.put(count, labelAwareSentenceIterator2.currentLabel());
count++;
}
assertEquals("SENT37", labels.get(0));
assertEquals("SENT38", labels.get(1));
assertEquals("SENT39", labels.get(2));
assertEquals("SENT42", labels.get(3));
assertEquals(4, count);
}
Aggregations