private void getRelatedSynSets_Click(object sender, EventArgs e) { SynSet selectedSynSet = synSets.SelectedItem as SynSet; if (selectedSynSet == null || synSetRelations.SelectedIndex == -1) { return; } synSets.Items.Clear(); // get relations string relationStr = synSetRelations.SelectedItem.ToString(); relationStr = relationStr.Split(':')[0].Trim(); WordNetEngine.SynSetRelation relation = (WordNetEngine.SynSetRelation)Enum.Parse(typeof(WordNetEngine.SynSetRelation), relationStr); // add related synset foreach (SynSet relatedSynset in selectedSynSet.GetRelatedSynSets(relation, false)) { synSets.Items.Add(relatedSynset); } // selected synset if (synSets.Items.Count > 0) { synSets.SelectedIndex = 0; } }
/*--------------------------------------------------------------------------------------------*/ private static void InsertLexAndSemForSynSet(ISession pSess, string pSynSetId, SynSet pSynSet) { Synset dbSynSet = SynsetCache[pSynSetId]; List <LexicalRelation> lexRels = pSynSet.GetLexicallyRelated(); foreach (LexicalRelation lr in lexRels) { var dbLex = new Lexical(); dbLex.Synset = dbSynSet; dbLex.Word = WordCache[dbLex.Synset.SsId + "|" + lr.FromWord]; dbLex.RelationId = (byte)lr.Relation; dbLex.TargetSynset = SynsetCache[lr.ToSyn.ID]; dbLex.TargetWord = WordCache[dbLex.TargetSynset.SsId + "|" + lr.ToWord]; pSess.Save(dbLex); } foreach (WordNetEngine.SynSetRelation rel in pSynSet.SemanticRelations) { Set <SynSet> relSet = pSynSet.GetRelatedSynSets(rel, false); foreach (SynSet rs in relSet) { var dbSem = new Semantic(); dbSem.Synset = dbSynSet; dbSem.RelationId = (byte)rel; dbSem.TargetSynset = SynsetCache[rs.ID]; pSess.Save(dbSem); } } }
static void Main(string[] args) { List <String> relaciones = new List <String>(); if (File.Exists("words.txt")) { // Usernames are listed first in users.ul, and are followed by a period and then the password associated with that username. StreamReader reader = new StreamReader("words.txt"); string line; Set <SynSet> synSetsToShow = null; List <String> rels = new List <string>(); using (var file = File.CreateText("relaciones.csv")) { while ((line = reader.ReadLine()) != null) { try { synSetsToShow = _wordNetEngine.GetSynSets(line, LAIR.ResourceAPIs.WordNet.WordNetEngine.POS.Noun); //main SynSet SynSet s1 = synSetsToShow.Last(); foreach (WordNetEngine.SynSetRelation synSetRelation in s1.SemanticRelations) { if (synSetRelation.ToString().Equals("Hypernym") || synSetRelation.ToString().Equals("Hyponym")) { //related SynSet SynSet s2 = s1.GetRelatedSynSets(synSetRelation, false).First(); //fill the line String csv_line = s1.Words[0] + "," + s2.Words[0] + "," + synSetRelation; file.WriteLine(csv_line); //out of the foreach loop //break; } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } reader.Close(); } } }