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

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