// Path: src/main/java/pitt/search/semanticvectors/LuceneUtils.java
// public enum TermWeight {
//   /** No term weighting: all terms have weight 1. */
//   NONE,
//   /** Use inverse document frequency: see {@link LuceneUtils#getIDF}. */
//   IDF,
//   /** Use log entropy: see {@link LuceneUtils#getEntropy}. */
//   LOGENTROPY,
//   /** Use term frequency: see {@link LuceneUtils#getGlobalTermFreq} */
//   FREQ,
//   /** Use square root of term frequency. */
//   SQRT,
//   /** Use log of term frequency. */
//   LOGFREQ,
// }
// 
// Path: src/main/java/pitt/search/semanticvectors/vectors/VectorType.java
// public enum VectorType {
//   /**
//    * Uses binary-valued vectors. May be slower for some operations, but highly accurate.
//    */
//   BINARY,
//   /**
//    * "Standard" real-valued vectors. Performs well for many operations though bind and release
//    * are (in some cases) either lossy with respect to argument structure and binding, or
//    * inexact with respect to inverse.
//    */
//   REAL,
//   /**
//    * Complex-valued vectors, default "polar" version, normalized to coordinates on the unit circle,
//    * and compared using angular differences.
//    */
//   COMPLEX,
//   /**
//    * Complex-valued vectors, normalized and compared using a hermitian scalar product.
//    */
//   COMPLEXFLAT,
//   /**
//    * Vector of integer values, describing a permutation
//    */
//   PERMUTATION
// }


import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
import pitt.search.semanticvectors.LuceneUtils.TermWeight;
import pitt.search.semanticvectors.utils.VerbatimLogger;
import pitt.search.semanticvectors.vectors.RealVector;
import pitt.search.semanticvectors.vectors.Vector;
import pitt.search.semanticvectors.vectors.VectorType;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.logging.Logger;
import ch.akuhn.edu.mit.tedlab.*;
  
    // Write header giving number of dimensions for all vectors and make sure type is real.
    outputStream.writeString(VectorStoreWriter.generateHeaderString(flagConfig));
    int cnt;
    // Write out term vectors
    for (cnt = 0; cnt < this.termList.length; cnt++) {
      outputStream.writeString(this.termList[cnt]);
      Vector termVector;
  
      float[] tmp = new float[flagConfig.dimension()];
      for (int i = 0; i < flagConfig.dimension(); i++)
        tmp[i] = (float) vT.value[i][cnt];
      termVector = new RealVector(tmp);
      termVector.normalize();
  
      termVector.writeToLuceneStream(outputStream);
    }
    outputStream.close();
    VerbatimLogger.info(
        "Wrote " + cnt + " term vectors incrementally to file " + flagConfig.termvectorsfile() + ".\n");
  
    // Write document vectors.
    // Open file and write headers.
    outputStream = fsDirectory.createOutput(
        VectorStoreUtils.getStoreFileName(flagConfig.docvectorsfile(), flagConfig), IOContext.DEFAULT);
  
    // Write header giving number of dimensions for all vectors and make sure type is real.
    outputStream.writeString(VectorStoreWriter.generateHeaderString(flagConfig));
  
    // Write out document vectors
// Path: src/main/java/pitt/search/semanticvectors/LuceneUtils.java
// public enum TermWeight {
//   /** No term weighting: all terms have weight 1. */
//   NONE,
//   /** Use inverse document frequency: see {@link LuceneUtils#getIDF}. */
//   IDF,
//   /** Use log entropy: see {@link LuceneUtils#getEntropy}. */
//   LOGENTROPY,
//   /** Use term frequency: see {@link LuceneUtils#getGlobalTermFreq} */
//   FREQ,
//   /** Use square root of term frequency. */
//   SQRT,
//   /** Use log of term frequency. */
//   LOGFREQ,
// }
// 
// Path: src/main/java/pitt/search/semanticvectors/vectors/VectorType.java
// public enum VectorType {
//   /**
//    * Uses binary-valued vectors. May be slower for some operations, but highly accurate.
//    */
//   BINARY,
//   /**
//    * "Standard" real-valued vectors. Performs well for many operations though bind and release
//    * are (in some cases) either lossy with respect to argument structure and binding, or
//    * inexact with respect to inverse.
//    */
//   REAL,
//   /**
//    * Complex-valued vectors, default "polar" version, normalized to coordinates on the unit circle,
//    * and compared using angular differences.
//    */
//   COMPLEX,
//   /**
//    * Complex-valued vectors, normalized and compared using a hermitian scalar product.
//    */
//   COMPLEXFLAT,
//   /**
//    * Vector of integer values, describing a permutation
//    */
//   PERMUTATION
// }


// Path: src/main/java/pitt/search/semanticvectors/LSA.java
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.BytesRef;
import pitt.search.semanticvectors.LuceneUtils.TermWeight;
import pitt.search.semanticvectors.utils.VerbatimLogger;
import pitt.search.semanticvectors.vectors.RealVector;
import pitt.search.semanticvectors.vectors.Vector;
import pitt.search.semanticvectors.vectors.VectorType;
import java.io.IOException;
import java.nio.file.FileSystems;
import java.util.logging.Logger;
import ch.akuhn.edu.mit.tedlab.*;

  
    // Write header giving number of dimensions for all vectors and make sure type is real.
    outputStream.writeString(VectorStoreWriter.generateHeaderString(flagConfig));
    int cnt;
    // Write out term vectors
    for (cnt = 0; cnt < this.termList.length; cnt++) {
      outputStream.writeString(this.termList[cnt]);
      Vector termVector;
  
      float[] tmp = new float[flagConfig.dimension()];
      for (int i = 0; i < flagConfig.dimension(); i++)
        tmp[i] = (float) vT.value[i][cnt];
      termVector = new RealVector(tmp);
      termVector.normalize();
  
      termVector.writeToLuceneStream(outputStream);
    }
    outputStream.close();
    VerbatimLogger.info(
        "Wrote " + cnt + " term vectors incrementally to file " + flagConfig.termvectorsfile() + ".\n");
  
    // Write document vectors.
    // Open file and write headers.
    outputStream = fsDirectory.createOutput(
        VectorStoreUtils.getStoreFileName(flagConfig.docvectorsfile(), flagConfig), IOContext.DEFAULT);
  
    // Write header giving number of dimensions for all vectors and make sure type is real.
    outputStream.writeString(VectorStoreWriter.generateHeaderString(flagConfig));
  
    // Write out document vectors
    for (cnt = 0; cnt < luceneUtils.getNumDocs(); cnt++) {