package com.pengyifan.word2vec;

import java.util.Map;
import java.util.Set;

import org.apache.commons.math3.linear.RealVector;

public class Word2Vec {

  private final Map<String, RealVector> word2vec;
  private final int vocabSize;
  private final int layer1Size;

  public Word2Vec(
      int vocabSize,
      int layer1Size,
      Map<String, RealVector> word2vec) {
    this.vocabSize = vocabSize;
    this.layer1Size = layer1Size;
    this.word2vec = word2vec;
  }

  public int getVocabSize() {
    return vocabSize;
  }

  public int getLayer1Size() {
    return layer1Size;
  }

  public Set<String> getVocab() {
    return word2vec.keySet();
  }
  
  public boolean contains(String word) {
    return word2vec.containsKey(word);
  }

  public RealVector getRealVector(String word) {
    return word2vec.get(word);
  }
}

@@ -26,16 +26,83 @@
 d2vec;%0A%0A
+import static com.google.common.base.Preconditions.checkArgument;%0A%0A
 import j
@@ -540,121 +540,440 @@
 %0A%0A  
-public int getVocabSize() %7B%0A    return vocabSize;%0A  %7D%0A%0A  public int getLayer1Size() %7B%0A    return layer1Size;%0A  %7D%0A
+/**%0A   * Returns the vocabulary size.%0A   * %0A   * @return the vocabulary size%0A   */%0A  public int getVocabSize() %7B%0A    return vocabSize;%0A  %7D%0A%0A  /**%0A   * Returns the length of vector.%0A   * %0A   * @return the length of vector%0A   */%0A  public int getLayer1Size() %7B%0A    return layer1Size;%0A  %7D%0A%0A  /**%0A   * Returns a Set view of the words contained in this word2vec.%0A   * %0A   * @return a Set view of the words contained in this word2vec%0A   */
 %0A  p
@@ -1041,173 +1041,1308 @@
   %7D%0A
+%0A
   
-%0A  public boolean contains(String word) %7B%0A    return word2vec.containsKey(word);%0A  %7D%0A%0A  public RealVector getRealVector(String word) %7B%0A    return word2vec.get(word
+/**%0A   * Returns true if this word2vec contains a mapping for the specified word.%0A   * %0A   * @param word whose presence in this word2vec is to be tested%0A   * @return true if this word2vec contains a mapping for the specified word%0A   */%0A  public boolean contains(String word) %7B%0A    return word2vec.containsKey(word);%0A  %7D%0A%0A  /**%0A   * Returns the vector of the specified word, or null if this word2vec%0A   * contains no mapping for the word.%0A   * %0A   * @param word whose presence in this word2vec%0A   * @return Returns the vector of the specified word, or null if this word2vec%0A   *         contains no mapping for the word%0A   */%0A  public RealVector getRealVector(String word) %7B%0A    return word2vec.get(word);%0A  %7D%0A%0A  /**%0A   * Computes the cosine of the angle between two word vectors s and t.%0A   * %0A   * @param s word whose presence in this word2vec%0A   * @param t word whose presence in this word2vec%0A   * @return the cosine of the angle between two word vectors s and t%0A   * @throws IllegalArgumentException if either word is not in this word2vec%0A   */%0A  public double cosine(String s, String t) %7B%0A    checkArgument(contains(s), %22The word2vec doesn't contain word%5B%25s%5D%22, s);%0A    checkArgument(contains(t), %22The word2vec doesn't contain word%5B%25s%5D%22, t);%0A    return getRealVector(s).cosine(getRealVector(t)
 );%0A 

add cosine computation