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

Java example source code file (ASCIICoOccurrenceReader.java)

This example Java source code file (ASCIICoOccurrenceReader.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

asciicooccurrencereader, cooccurencereader, cooccurrenceweight, file, nonnull, override, printwriter, runtimeexception, sentenceiterator, sequenceelement, string, vocabcache

The ASCIICoOccurrenceReader.java Java example source code

package org.deeplearning4j.models.glove.count;

import lombok.NonNull;
import org.deeplearning4j.models.sequencevectors.sequence.SequenceElement;
import org.deeplearning4j.models.word2vec.wordstore.VocabCache;
import org.deeplearning4j.text.sentenceiterator.BasicLineIterator;
import org.deeplearning4j.text.sentenceiterator.PrefetchingSentenceIterator;
import org.deeplearning4j.text.sentenceiterator.SentenceIterator;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintWriter;

 * @author raver119@gmail.com
public class ASCIICoOccurrenceReader<T extends SequenceElement> implements CoOccurenceReader {
    private File file;
    private PrintWriter writer;
    private SentenceIterator iterator;
    private VocabCache<T> vocabCache;

    public ASCIICoOccurrenceReader(@NonNull File file, @NonNull VocabCache<T> vocabCache) {
        this.vocabCache = vocabCache;
        this.file = file;
        try {
            iterator = new PrefetchingSentenceIterator.Builder(new BasicLineIterator(file)).build();
        } catch (Exception e) {
            throw new RuntimeException(e);

    public boolean hasMoreObjects() {
        return iterator.hasNext();

     * Returns next CoOccurrenceWeight object
     * PLEASE NOTE: This method can return null value.
     * @return
    public CoOccurrenceWeight<T> nextObject() {
        String line = iterator.nextSentence();
        if (line == null || line.isEmpty()) return null;
        String[] strings = line.split(" ");

        CoOccurrenceWeight<T> object = new CoOccurrenceWeight<>();

        return object;

    public void finish() {
        try {
            if (writer != null) {
        } catch (Exception e) {
            throw new RuntimeException(e);


Other Java examples (source code examples)

Here is a short list of links related to this Java ASCIICoOccurrenceReader.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.