/** * <summary>The mostSimilarWord method takes a String name as an input, declares a maxDistance as -MAX_VALUE and creates a * {@link VectorizedWord} word by getting the given name from words {@link ArrayList}. Then, it loops through the * words {@link ArrayList} and if the current word is not equal to given input it calculates the distance between current * word and given word by using dot product and updates the maximum distance. It then returns the result {@link VectorizedWord} * which holds the most similar word to the given word.</summary> * * <param name="name">String input.</param> * <returns>VectorizedWord type result which holds the most similar word to the given word.</returns> */ public VectorizedWord MostSimilarWord(string name) { var maxDistance = double.MinValue; VectorizedWord result = null; var word = (VectorizedWord)GetWord(name); if (word == null) { return(null); } foreach (var currentWord in words) { var current = (VectorizedWord)currentWord; if (!current.Equals(word)) { var distance = word.GetVector().DotProduct(current.GetVector()); if (distance > maxDistance) { maxDistance = distance; result = current; } } } return(result); }
/** * <summary>The addWord method takes a {@link VectorizedWord} as an input and adds it to the words {@link ArrayList}.</summary> * * <param name="word">{@link VectorizedWord} input.</param> */ public void AddWord(VectorizedWord word) { words.Add(word); }