// 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));
  
    // Write out document vectors
    for (cnt = 0; cnt < luceneUtils.getNumDocs(); cnt++) {
      String thePath = this.luceneUtils.getDoc(cnt).get(flagConfig.docidfield());
      outputStream.writeString(thePath);
      float[] tmp = new float[flagConfig.dimension()];
  
      for (int i = 0; i < flagConfig.dimension(); i++)
        tmp[i] = (float) uT.value[i][cnt];
      RealVector docVector = new RealVector(tmp);
      docVector.normalize();
      
      docVector.writeToLuceneStream(outputStream);
    }
    outputStream.close();
    VerbatimLogger.info("Wrote " + cnt + " document vectors incrementally to file "
                        + flagConfig.docvectorsfile() + ". Done.\n");
  }

  public static void main(String[] args) throws IllegalArgumentException, IOException {
    FlagConfig flagConfig;
    try {
      flagConfig = FlagConfig.getFlagConfig(args);
      args = flagConfig.remainingArgs;
    } catch (IllegalArgumentException e) {
      System.out.println(usageMessage);
      throw e;
    }
// 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));
  
    // Write out document vectors
    for (cnt = 0; cnt < luceneUtils.getNumDocs(); cnt++) {
      String thePath = this.luceneUtils.getDoc(cnt).get(flagConfig.docidfield());
      outputStream.writeString(thePath);
      float[] tmp = new float[flagConfig.dimension()];
  
      for (int i = 0; i < flagConfig.dimension(); i++)
        tmp[i] = (float) uT.value[i][cnt];
      RealVector docVector = new RealVector(tmp);
      docVector.normalize();
      
      docVector.writeToLuceneStream(outputStream);
    }
    outputStream.close();
    VerbatimLogger.info("Wrote " + cnt + " document vectors incrementally to file "
                        + flagConfig.docvectorsfile() + ". Done.\n");
  }

  public static void main(String[] args) throws IllegalArgumentException, IOException {
    FlagConfig flagConfig;
    try {
      flagConfig = FlagConfig.getFlagConfig(args);
      args = flagConfig.remainingArgs;
    } catch (IllegalArgumentException e) {
      System.out.println(usageMessage);
      throw e;
    }
    if (flagConfig.vectortype() != VectorType.REAL) {