Example #1
0
        /// <summary>
        /// This method generates synonyms
        /// </summary>
        /// <author>
        /// This code with libraries in TOOLSWord2vec.Tools-master
        /// was programmed by GitHub user: GuntaButya
        /// Link to GitHub code: https://github.com/GuntaButya/Word2Vec.Net-CSharp
        /// </author>
        /// <param name="path">This file is located in Models file</param>


        public static Dictionary <string, string> UseWord2Vec(string path, string[] words)
        {
            Dictionary <string, string> replacedWords = new Dictionary <string, string>();
            var vocabulary = new Word2VecTextReader().Read(path);

            foreach (string word in words)
            {
                int count = 10;

                var closest = vocabulary.Distance(word, count);

                foreach (var neightboor in closest)
                {
                    if ((neightboor.Representation.WordOrNull.ToLower() == neightboor.Representation.WordOrNull) &&
                        (neightboor.Representation.WordOrNull != null) &&
                        (
                            (word.StartsWith("ne") && neightboor.Representation.WordOrNull.StartsWith("ne")) ||
                            (!word.StartsWith("ne") && !neightboor.Representation.WordOrNull.StartsWith("ne"))
                        )
                        )
                    {
                        if (!replacedWords.ContainsKey(word))
                        {
                            replacedWords.Add(word, neightboor.Representation.WordOrNull);
                            if (word != word.ToLower() && !replacedWords.ContainsKey(word.ToLower()))
                            {
                                replacedWords.Add(word.ToLower(), neightboor.Representation.WordOrNull);
                            }
                        }
                        break;
                    }
                }
            }
            return(replacedWords);
        }
Example #2
0
    public void CheckVocublary(string W2Vlocation)
    {
        Vocabulary W2Vvocublary = new Word2VecTextReader().Read(W2Vlocation);

        foreach (var ky in dictwords)
        {
            Console.WriteLine("-------- " + ky.Key + " --------");
            int i = 0;
            foreach (string kyw in ky.Value.Keys)
            {
                if (!W2Vvocublary.ContainsWord(kyw))
                {
                    Console.WriteLine(i++ + kyw);
                }
            }
        }
    }