コード例 #1
0
 private void WriteHeader(RealModel m)
 {
     Writer.Write(m.Words);
     Writer.Write(' ');
     Writer.Write(m.Size);
     Writer.Write('\n');
 }
コード例 #2
0
 public void Write(RealModel m)
 {
     WriteHeader(m);
     foreach (var wv in m.Vectors)
     {
         WriteWordVector(wv);
     }
 }
コード例 #3
0
        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));
        }
コード例 #4
0
        public void Write(RealModel m)
        {
            //Write the header
            WriteHeader(m);

            //Write the vectors
            foreach (var wv in m.Vectors)
            {
                WriteWordVector(wv);
            }
        }
コード例 #5
0
        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));
        }
コード例 #6
0
 private void WriteHeader(RealModel m)
 {
     WriteString(string.Format("{0} {1}\n", m.Words, m.Size));
 }
コード例 #7
0
 public static WordVector NearestSingle(this RealModel model, float[] vector)
 {
     return(model.Vectors.OrderBy(x => x.Vector.Distance(vector)).First());
 }
コード例 #8
0
 public static IEnumerable <WordVector> Nearest(this RealModel model, float[] vector)
 {
     return(model.Vectors.OrderBy(x => x.Vector.Distance(vector)));
 }
コード例 #9
0
 public static WordVector GetByWord(this RealModel model, string word)
 {
     return(model.Vectors.FirstOrDefault(x => x.Word == word));
 }