home | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Java example source code file (SentenceIteratorConverter.java)

This example Java source code file (SentenceIteratorConverter.java) is included in the alvinalexander.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Learn more about this Java project at its project page.

Java - Java tags/keywords

labelawareiterator, labelawaresentenceiterator, labelleddocument, labelssource, logger, nonnull, override, sentenceiteratorconverter, string

The SentenceIteratorConverter.java Java example source code

package org.deeplearning4j.text.sentenceiterator.interoperability;

import lombok.NonNull;
import org.deeplearning4j.text.documentiterator.LabelAwareIterator;
import org.deeplearning4j.text.documentiterator.LabelledDocument;
import org.deeplearning4j.text.documentiterator.LabelsSource;
import org.deeplearning4j.text.sentenceiterator.SentenceIterator;
import org.deeplearning4j.text.sentenceiterator.labelaware.LabelAwareSentenceIterator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

 * Simple class providing compatibility between SentenceIterator/LabelAwareSentenceIterator and LabelAwareIterator
 * @author raver119@gmail.com
public class SentenceIteratorConverter implements LabelAwareIterator {
    private SentenceIterator backendIterator;
    private LabelsSource generator;
    protected static final Logger log = LoggerFactory.getLogger(SentenceIteratorConverter.class);

    public SentenceIteratorConverter(@NonNull SentenceIterator iterator) {
        this.backendIterator = iterator;
        this.generator = new LabelsSource();

    public SentenceIteratorConverter(@NonNull SentenceIterator iterator, @NonNull LabelsSource generator) {
        this.backendIterator = iterator;
        this.generator = generator;

    public boolean hasNextDocument() {
        return backendIterator.hasNext();

    public LabelledDocument nextDocument() {
        LabelledDocument document = new LabelledDocument();

        if (backendIterator instanceof LabelAwareSentenceIterator) {
            String currentLabel = ((LabelAwareSentenceIterator) backendIterator).currentLabel();
        } else if (generator != null) document.setLabel(generator.nextLabel());

        return document;

    public void reset() {

    public LabelsSource getLabelsSource() {
        return generator;

Other Java examples (source code examples)

Here is a short list of links related to this Java SentenceIteratorConverter.java source code file:

my book on functional programming


new blog posts


Copyright 1998-2019 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.