/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { string term1 = null; string term2 = null; if (!DA.GetData(0, ref term1)) { return; } // If the retrieved data is Nothing, we need to abort. // We're also going to abort on a zero-length String. if (term1 == null) { return; } if (term1.Length == 0) { return; } var synSetList = wordNet.GetSynSets(term1); if (synSetList.Count == 0) { Console.WriteLine($"No SynSet found for '{term1}'"); } var wordList = new List <String>(); var partOfSpeechList = new List <String>(); var glossList = new List <String>(); foreach (var synSet in synSetList) { var synonym = string.Join(", ", synSet.Words); wordList.Add(synonym); partOfSpeechList.Add(synSet.PartOfSpeech.ToString()); glossList.Add(synSet.Gloss); } if (DA.GetData(1, ref term2)) { var similarity = wordNet.GetSentenceSimilarity(term1, term2); DA.SetData(3, similarity); } // Use the DA object to assign a new String to the first output parameter. DA.SetDataList(0, wordList); DA.SetDataList(1, partOfSpeechList); DA.SetDataList(2, glossList); }
public float GetWordNetPathLength(WordNetEngine wordNet) { const string methodKey = "WordNet"; string valueKey = NounPhrase.PhraseString + " | " + NounPhrase.TargetString; float?cachedValue = caching.Get <float?>(methodKey, valueKey); if (cachedValue != null) { return((float)cachedValue); } else { var value = wordNet.GetSentenceSimilarity(NounPhrase.PhraseString, NounPhrase.TargetString); caching.Add(methodKey, valueKey, value); return(value); } }