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)); */ }
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(); }
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)); */ }
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)); */ }
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)); }
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)); */ }
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(); }
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(); }
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(); }
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; } }
//private void GetWikiInfoBoxAnswer(Answer ans, List<Answer> answers) private void GetWikiInfoBoxAnswer(Answer ans) { Dictionary<string, string> InfoBoxValues = new Dictionary<string, string>(); Dictionary<string, float> InfoKeySimValues = new Dictionary<string, float>(); SentenceSimilarity semsim = new SentenceSimilarity(); try { string articleTitle = GetWikiEditUrl(ans.url); if (String.IsNullOrEmpty(articleTitle)) return; string wikiSourceWebResponse = Util.MakeWebRequest(articleTitle); wikiSourceWebResponse = HttpUtility.HtmlDecode(wikiSourceWebResponse); string infoBoxText = InfoBoxRegex.Match(wikiSourceWebResponse).Groups[0].Captures[0].Value; // reading all the key value pairs in the infobox MatchCollection matches = InfoKeyValueRegex.Matches(infoBoxText); foreach (Match match in matches) { InfoBoxValues[match.Groups[1].Value] = match.Groups[2].Value; } // Getting keys that match user Request string[] infoBoxNames = InfoBoxValues["name"].ToLower().Split(); List<MyWordInfo> words = new List<MyWordInfo>(); for(int i=0; i < ranker.queryWords.Count; i++) { words.Add(new MyWordInfo(ranker.queryWords[i],PartOfSpeech.PennTag2Pos(ranker.queryTags[i]))); } // adding extra words depending on the WH words present in the list if (ranker.queryWords.Contains("when")) words.Add(new MyWordInfo("date", PartsOfSpeech.Unknown)); if (ranker.queryWords.Contains("where")) words.Add(new MyWordInfo("place", PartsOfSpeech.Unknown)); if (ranker.queryWords.Contains("why")) words.Add(new MyWordInfo("cause", PartsOfSpeech.Unknown)); MyWordInfo[] simQueryWords = words.Where(word => !infoBoxNames.Contains(word.Word)).ToArray(); foreach (string key in InfoBoxValues.Keys) { MyWordInfo[] keyWords = key.Split('_').Select(k => new MyWordInfo(k, PartsOfSpeech.Unknown)).ToArray(); InfoKeySimValues[key] = ranker.GetWordNetSimScore(keyWords,simQueryWords, key); //InfoKeySimValues[key] = GetSimScore(semsim.GetSimilarityMatrix(key.Split('_'), simQuery.ToArray())); } // choosing more than one answer float max = InfoKeySimValues.Max(key => key.Value); List<string> validKeys = InfoKeySimValues.Where(key => key.Value == max).Select(key => key.Key).ToList(); foreach (string key in validKeys) { Answer infoanswer = new Answer(); infoanswer.url = ans.url; infoanswer.topAnswer = ParseWikiText(InfoBoxValues[key]).Replace("[[", "").Replace("]]", ""); infoanswer.isStarred = true; infoanswer.source = AnswerSource.Wikipedia; infoanswer.type = AnswerType.Text; infoanswer.question = InfoBoxValues["name"] + " " + key.Replace("_", " ");; ranker.GetFeatures(infoanswer); //answers.Add(infoanswer); Answers.Add(infoanswer); } } catch(Exception e) {} }