private void WriteHeader(RealModel m) { Writer.Write(m.Words); Writer.Write(' '); Writer.Write(m.Size); Writer.Write('\n'); }
public void Write(RealModel m) { WriteHeader(m); foreach (var wv in m.Vectors) { WriteWordVector(wv); } }
public static IEnumerable <WordDistance> Nearest(this RealModel model, string word) { var vector = model.GetByWord(word); if (vector == null) { throw new ArgumentException(string.Format("cannot find word '{0}'", word)); } return(model.Vectors.Select(x => new WordDistance(x.Word, x.Vector.Distance(vector.Vector))).OrderBy(x => x.Distance).Where(x => x.Word != word)); }
public void Write(RealModel m) { //Write the header WriteHeader(m); //Write the vectors foreach (var wv in m.Vectors) { WriteWordVector(wv); } }
public static double Distance(this RealModel model, string word1, string word2) { var vector1 = model.GetByWord(word1); var vector2 = model.GetByWord(word2); if (vector1 == null) { throw new ArgumentException(string.Format("cannot find word1 '{0}'", word1)); } if (vector2 == null) { throw new ArgumentException(string.Format("cannot find word2 '{0}'", word2)); } return(vector1.Vector.Distance(vector2.Vector)); }
private void WriteHeader(RealModel m) { WriteString(string.Format("{0} {1}\n", m.Words, m.Size)); }
public static WordVector NearestSingle(this RealModel model, float[] vector) { return(model.Vectors.OrderBy(x => x.Vector.Distance(vector)).First()); }
public static IEnumerable <WordVector> Nearest(this RealModel model, float[] vector) { return(model.Vectors.OrderBy(x => x.Vector.Distance(vector))); }
public static WordVector GetByWord(this RealModel model, string word) { return(model.Vectors.FirstOrDefault(x => x.Word == word)); }