public static double Distance(this Model 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)); }
public static IEnumerable <WordDistance> Nearest(this Model 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)); }