private void getSynSets_Click(object sender, EventArgs e) { synSets.Items.Clear(); semanticRelations.Items.Clear(); lexicalRelations.Items.Clear(); getRelatedSynSets.Enabled = false; // retrive synsets Set <SynSet> synSetsToShow = null; if (synsetID.Text != "") { try { synSetsToShow = new Set <SynSet>(new SynSet[] { _wordNetEngine.GetSynSet(synsetID.Text) }); } catch (Exception) { MessageBox.Show("Invalid SynSet ID"); return; } } else { // get single most common synset if (mostCommon.Checked) { try { SynSet synset = _wordNetEngine.GetMostCommonSynSet(word.Text, (WordNetEngine.POS)pos.SelectedItem); if (synset != null) { synSetsToShow = new Set <SynSet>(new SynSet[] { synset }); } } catch (Exception ex) { MessageBox.Show("Error: " + ex); return; } } // get all synsets else { try { synSetsToShow = _wordNetEngine.GetSynSets(word.Text, (WordNetEngine.POS)pos.SelectedItem); } catch (Exception ex) { MessageBox.Show("Error: " + ex); return; } } } if (synSetsToShow.Count > 0) { foreach (SynSet synSet in synSetsToShow) { synSets.Items.Add(synSet); } } else { MessageBox.Show("No synsets found"); } }
/*--------------------------------------------------------------------------------------------*/ public static bool InsertLexicalsAndSemantics(ISession pSess, WordNetEngine pEngine, int pStart, int pCount) { List <string> keys = SynsetCache.Keys.ToList(); int i = pStart; for ( ; i < pStart + pCount; ++i) { if (i >= keys.Count) { break; } InsertLexAndSemForSynSet(pSess, keys[i], pEngine.GetSynSet(keys[i])); } return(i < keys.Count); }
// Defualt Constructor public SemCluster(string DataFolder) { try { Console.WriteLine("\tSemCluster Text Analytics Tool"); Console.WriteLine("\t------------------------------"); Console.WriteLine("\t-Wikipedia local server couldn't be found!"); Console.WriteLine("\t-Seeds SemAve is in manual mode!"); Console.WriteLine(); Console.WriteLine(); Console.WriteLine("-> Resources loading ..."); Console.WriteLine(); #region Loading External Resources _wn = new WordNetEngine(DataFolder + "WordNet", InMemoryWordNet); _tokenizer = new EnglishRuleBasedTokenizer(TokenizeHyphen); _sentenceDetector = new EnglishMaximumEntropySentenceDetector(DataFolder + "EnglishSD.nbin"); _posTagger = new EnglishMaximumEntropyPosTagger(DataFolder + "EnglishPOS.nbin", DataFolder + "\\Build\\tagdict"); _chunker = new EnglishTreebankChunker(DataFolder + "EnglishChunk.nbin"); #endregion PlugInsManager(DataFolder); Console.WriteLine("\tResources loaded successfully"); Console.WriteLine("\t" + PlugInsNumber + " KB plug-ins found in the repository"); Console.WriteLine("\tPress any key to continue ..."); Console.ReadKey(); Console.WriteLine(); RootVirtualNode = _wn.GetSynSet("Noun:1740"); ap = new AffinityPropagationClustering(); SynSetRelationTypes = new WordNetApi.Core.WordNetEngine.SynSetRelation[2]; SynSetRelationTypes[0] = WordNetApi.Core.WordNetEngine.SynSetRelation.Hypernym; SynSetRelationTypes[1] = WordNetApi.Core.WordNetEngine.SynSetRelation.InstanceHypernym; } catch (Exception ex) { Dispose(); throw new Exception(ex.Message); } }
public static Category FromString(WordNetEngine wordNetEngine, String text) { string categoryName; int wordCount; Dictionary<SynSet, int> synSetDictionary; // split into lines var lines = Regex.Split(text, "\r\n|\r|\n"); // first line "name=.." var firstLineSplit = lines[0].Split(new char[] {'='}, StringSplitOptions.RemoveEmptyEntries); if (firstLineSplit.Length != 2) { return null; } if (firstLineSplit[0] != STRING_REPRESENTATION_FIRST_LINE_KEY) { return null; } categoryName = firstLineSplit[1]; // second line "wordcount=.." var secondLineSplit = lines[1].Split(new char[] {'='}, StringSplitOptions.RemoveEmptyEntries); if (secondLineSplit.Length != 2) { return null; } if (secondLineSplit[0] != STRING_REPRESENTATION_SECOND_LINE_KEY || !Int32.TryParse( secondLineSplit[1], out wordCount)) { return null; } synSetDictionary = new Dictionary<SynSet,int>(); // rest of the lines - dictionary for(int i = 2 ; i < lines.Length ; ++i) { var lineSplit = lines[i].Split(new char[] {'|'}, StringSplitOptions.RemoveEmptyEntries); if (lineSplit.Length != 2) { break; } // synset word count int synSetWordCount; if (!Int32.TryParse(lineSplit[1], out synSetWordCount)) { return null; } // synset var synSet = wordNetEngine.GetSynSet(lineSplit[0]); if (synSet == null) { return null; } synSetDictionary.Add(synSet, synSetWordCount); } Utility.Log("loaded " + categoryName + " (" + wordCount + ") with " + synSetDictionary.Count + " synsets"); return new Category(categoryName, wordCount, synSetDictionary); }
public List <SynSet> Query(WordNetEngine _wn, string term) { try { HttpWebRequest request; ExternalSet obj; int SynsCount; string InternalSynSetId; string HypernymInfo; int tmpDepth; List <SynSet> Syns = new List <SynSet>(); SynSet tmpSyn; request = WebRequest.Create("http://lookup.dbpedia.org/api/search.asmx/KeywordSearch?QueryString=" + term) as HttpWebRequest; request.Method = "Get"; request.Accept = "application/json"; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) using (StreamReader reader = new StreamReader(response.GetResponseStream())) obj = JsonConvert.DeserializeObject <ExternalSet>(reader.ReadToEnd()); SynsCount = obj.SynSets.Count; if (SynsCount > 0) { for (int k = 0; k < SynsCount; k++) { if (MeasureOverlap(term, obj.SynSets[k].Synonym)) { // If the Sense has classes, map directly to WordNet if (obj.SynSets[k].Hypernyms.Count > 0) { tmpDepth = 0; InternalSynSetId = ""; foreach (ExternalHypernym hypernym in obj.SynSets[k].Hypernyms) { // if the class RDF Identifier has URL, extract only the concept if (hypernym.URI.StartsWith("ht")) { hypernym.URI = hypernym.URI.Substring(hypernym.URI.LastIndexOf("/") + 1); } hypernym.URI = hypernym.URI.Trim().ToLower(); if (SchemaMap.TryGetValue(hypernym.URI, out HypernymInfo)) { if (tmpDepth < Convert.ToInt32(HypernymInfo[0])) { tmpDepth = Convert.ToInt32(HypernymInfo[0]); InternalSynSetId = HypernymInfo.Substring(1); } } } if (InternalSynSetId != "") { tmpSyn = _wn.GetSynSet("Noun:" + InternalSynSetId); if (obj.SynSets[k].Gloss != null) { tmpSyn.Gloss = rx.Replace(obj.SynSets[k].Gloss, string.Empty); } tmpSyn.URI = obj.SynSets[k].ID; Syns.Add(tmpSyn); } } else if (obj.SynSets[k].Synonym.Contains("(")) { List <SynSet> tmpSyns = _wn.GetSynSets(obj.SynSets[k].Synonym.Split('(', ')')[1], "noun"); if (tmpSyns.Count > 0) { tmpSyn = tmpSyns.First(); if (obj.SynSets[k].Gloss != null) { tmpSyn.Gloss = rx.Replace(obj.SynSets[k].Gloss, string.Empty); } tmpSyn.URI = obj.SynSets[k].ID; Syns.Add(tmpSyn); } } else { // Infer a class from categries } } } } return(Syns); } catch (Exception ex) { return(null); } }