예제 #1
0
파일: DemoTest.cs 프로젝트: ngocnt1801/QBCS
        void Test_1()
        {
            SentenceSimilarity semsim = new SentenceSimilarity();

            float score = 0;

            //System.Console.WriteLine("Defense Ministry");
            //System.Console.WriteLine("Department of defence");

            score = semsim.GetScore(
                "plane",
                "plane");
            System.Console.WriteLine(score);

            /*
             * score = semsim.GetScore(
             * "flora",
             * "person");
             * System.Console.WriteLine("Score: " + (score == 0.83F));
             *
             * score = semsim.GetScore(
             * "boy",
             * "teacher");
             * System.Console.WriteLine("Score: " + (score == 0.57F));
             *
             * //is cursing the boy?
             * score = semsim.GetScore(
             * "boy",
             * "animal");
             * System.Console.WriteLine("Score: " + (score == 0.71F));
             */
        }
예제 #2
0
        void Test_1()
        {
            SentenceSimilarity semsim = new SentenceSimilarity();

            float score = 0;

            System.Console.WriteLine("Monkey: ");

            score = semsim.GetScore(
                "monkey",
                "animal");
            System.Console.WriteLine("animal: " + score);

            score = semsim.GetScore(
                "monkey",
                "mineral");
            System.Console.WriteLine("mineral: " + score);

            score = semsim.GetScore(
                "monkey",
                "vegetable");
            System.Console.WriteLine("vegetable: " + score);

            /*
             * score = semsim.GetScore(
             * "flora",
             * "person");
             * System.Console.WriteLine("Score: " + (score == 0.83F));
             *
             * score = semsim.GetScore(
             * "boy",
             * "teacher");
             * System.Console.WriteLine("Score: " + (score == 0.57F));
             *
             * //is cursing the boy?
             * score = semsim.GetScore(
             * "boy",
             * "animal");
             * System.Console.WriteLine("Score: " + (score == 0.71F));
             */
        }
예제 #3
0
        void Test_1()
        {
            SentenceSimilarity semsim = new SentenceSimilarity();

            float score = 0;

            System.Console.WriteLine("Monkey: ");

            score = semsim.GetScore(
            "monkey",
            "animal");
            System.Console.WriteLine("animal: " + score);

            score = semsim.GetScore(
            "monkey",
            "mineral");
            System.Console.WriteLine("mineral: " + score);

            score = semsim.GetScore(
            "monkey",
            "vegetable");
            System.Console.WriteLine("vegetable: " + score);

            /*
            score = semsim.GetScore(
            "flora",
            "person");
            System.Console.WriteLine("Score: " + (score == 0.83F));

            score = semsim.GetScore(
             "boy",
             "teacher");
            System.Console.WriteLine("Score: " + (score == 0.57F));

            //is cursing the boy?
            score = semsim.GetScore(
            "boy",
            "animal");
            System.Console.WriteLine("Score: " + (score == 0.71F));
            */
        }
예제 #4
0
        void Test_1()
        {
            SentenceSimilarity semsim = new SentenceSimilarity();
            float score = 0;

            score = semsim.GetScore(
                "flora",
                "person");
            System.Console.WriteLine("Score: " + (score == 0.83F));

            score = semsim.GetScore(
                "boy",
                "teacher");
            System.Console.WriteLine("Score: " + (score == 0.57F));

            //is cursing the boy?
            score = semsim.GetScore(
                "boy",
                "animal");
            System.Console.WriteLine("Score: " + (score == 0.71F));
        }
예제 #5
0
        void Test_1()
        {
            // MessageBox.Show("button");

            SentenceSimilarity semsim = new SentenceSimilarity();

            float score = 0;

            //System.Console.WriteLine("car: ");


            score = semsim.GetScore(
                "People like listening music",
                "people never listen son");
            System.Console.WriteLine("second: " + score);

            score = semsim.GetScore(
                "I love driving car",
                "vehicle is moving by me");
            System.Console.WriteLine("third: " + score);

            /*
             * score = semsim.GetScore(
             * "flora",
             * "person");
             * System.Console.WriteLine("Score: " + (score == 0.83F));
             *
             * score = semsim.GetScore(
             * "boy",
             * "teacher");
             * System.Console.WriteLine("Score: " + (score == 0.57F));
             *
             * //is cursing the boy?
             * score = semsim.GetScore(
             * "boy",
             * "animal");
             * System.Console.WriteLine("Score: " + (score == 0.71F));
             */
        }
예제 #6
0
        void Test_1()
        {
            SentenceSimilarity semsim = new SentenceSimilarity();

            float score = 0;

            // System.Console.WriteLine("car: ");

            score = semsim.GetScore(
                richTextBox1.Text,
                richTextBox2.Text);
            DiplScore.Text = score.ToString();
        }
        public void ComputeSimilarity(string outputFilePath)
        {
            Wnlib.WNCommon.path = @"E:\v-wacui\software\WordNet\3.0\WordNet-3.0\dict\";
            client = new SentenceSimilarity();
            StreamWriter writer=new StreamWriter(outputFilePath);

            //client.GetScore("Defense Ministry", "Department of defence");

            foreach(string category in categoryToAttributepath.Keys)
            {
                if (category != "country") continue;

                List<KeyValuePair<string, double>> tlist = new List<KeyValuePair<string, double>>();

                if (categoryToAttribute.ContainsKey(category)==false) continue;
                foreach(string attributepath in categoryToAttributepath[category])
                    foreach (string attribute in categoryToAttribute[category])
                    {
                        string attributepath_formalize = FormalizeAttributePath(attributepath);
                        double temp=client.GetScore(attribute, attributepath_formalize);
            //                        writer.WriteLine(attribute + "\t" + attributepath_formalize + "\t" + temp);
                        Console.WriteLine(attribute + "\t" + attributepath_formalize + "\t" + temp);
                        if (attributeToAttributepath.ContainsKey(attribute) == false)
                            attributeToAttributepath.Add(attribute, new Dictionary<string, double>());
                        attributeToAttributepath[attribute].Add(attributepath, temp);

                        tlist.Add(new KeyValuePair<string, double>(attribute + "\t" + attributepath_formalize + "\t" + temp, temp));
                    }

                DinoComparer dc = new DinoComparer();
                tlist.Sort(dc);

                foreach (var item in tlist)
                    writer.WriteLine(category + "\t" + item.Key);

            }
            writer.Close();
        }
예제 #8
0
        static void Test1()
        {
            var semsim = new SentenceSimilarity();

            Console.WriteLine("Monkey: ");

            float score = semsim.GetScore(
                "monkey",
                "animal");

            Console.WriteLine("animal: " + score);

            score = semsim.GetScore(
                "monkey",
                "mineral");
            Console.WriteLine("mineral: " + score);

            score = semsim.GetScore(
                "monkey",
                "vegetable");
            Console.WriteLine("vegetable: " + score);

            score = semsim.GetScore(
                "what color is an apple",
                "an apple is pink");
            Console.WriteLine("apple:pink: " + score);

            score = semsim.GetScore("Pepsi is being drunk by Shilpa", "Shilpa is drinking pepsi");
            Console.WriteLine("Pepsi is being drunk by Shilpa:Shilpa is drinking pepsi " + score);

            score = semsim.GetScore("Pepsi is being drunk by Shilpa", "Shilpa is drinking pepsi");
            Console.WriteLine("Pepsi is drinking Shilpa:Shilpa is drinking pepsi " + score);

            Console.WriteLine(Lexicon.FindWordInfo("Smiling", true).ToString());

            Console.ReadLine();
        }
예제 #9
0
	    static void Test1()
        {
            var semsim = new SentenceSimilarity();

	        Console.WriteLine("Monkey: ");

            float score = semsim.GetScore(
                "monkey",
                "animal");
            Console.WriteLine("animal: " + score);

            score = semsim.GetScore(
            "monkey",
            "mineral");
            Console.WriteLine("mineral: " + score);

            score = semsim.GetScore(
            "monkey",
            "vegetable");
            Console.WriteLine("vegetable: " + score);

            score = semsim.GetScore(
                "what color is an apple",
                "an apple is pink");
            Console.WriteLine("apple:pink: " + score);

            score = semsim.GetScore("Pepsi is being drunk by Shilpa", "Shilpa is drinking pepsi");
            Console.WriteLine("Pepsi is being drunk by Shilpa:Shilpa is drinking pepsi " + score);

            score = semsim.GetScore("Pepsi is being drunk by Shilpa", "Shilpa is drinking pepsi");
            Console.WriteLine("Pepsi is drinking Shilpa:Shilpa is drinking pepsi " + score);

            Console.WriteLine(Lexicon.FindWordInfo("Smiling",true).ToString());

            Console.ReadLine();
        }
예제 #10
0
        private string Replace(string[] words, int index)
        {
            string word = words[index];

            WordNetEngine.POS wnepos = StaticHelper.GetWordNetEnginePOS(word);

            if (wnepos == WordNetEngine.POS.None) return word;

            PartsOfSpeech wnlibpos = StaticHelper.GetWnlibPOSFromWordNetEnginePOS(wnepos);

            LAIR.ResourceAPIs.WordNet.SynSet[] synsets = wne.GetSynSets(word, wnepos).ToArray();

            double currentSimilarity = THRESHOLD;
            List<string> possibleWords = new List<string>();

            string sentence = StaticHelper.composer.ComposeSentence(words);

            string[] tempWords = words;

            foreach (LAIR.ResourceAPIs.WordNet.SynSet synset in synsets)
            {
                foreach(string possibleWord in synset.Words)
                {
                    if (word.Equals(possibleWord, StringComparison.CurrentCultureIgnoreCase)) continue;

                    tempWords[index] = StaticHelper.WithoutUnderScore(possibleWord);
                    string newSentence = StaticHelper.composer.ComposeSentence(tempWords);

                    SentenceSimilarity ss = new SentenceSimilarity();

                    double similarity = ss.GetScore(sentence, newSentence);

                    if(similarity >= currentSimilarity)
                    {
                        possibleWords.Add(StaticHelper.WithoutUnderScore(possibleWord));
                    }
                }
            }

            words[index] = word;

            if (possibleWords.Count > 1)
            {
                WordSimilarity ws = new WordSimilarity();

                HierarchicalWordData defaultWord = new HierarchicalWordData(new MyWordInfo(word, StaticHelper.GetWnlibPOS(word)));

                currentSimilarity = 0;
                string replacement = word;

                foreach(string possibleWord in possibleWords)
                {
                    HierarchicalWordData newWord = new HierarchicalWordData(new MyWordInfo(possibleWord, wnlibpos));

                    double similarity = ws.GetSimilarity(defaultWord, newWord);

                    if(similarity > currentSimilarity)
                    {
                        replacement = possibleWord;
                        currentSimilarity = similarity;
                    }
                }

                return replacement;
            }
            else if (possibleWords.Count == 1) return possibleWords.ToArray()[0];
            else
            {
                return word;
            }
        }