- Code: Select all
using System;
using System.Collections.Generic;
using Wnlib;
namespace GetCoordinateTermsCon
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello from Get Coordinate Terms for POS\n");
string dictPath = @"C:\Program Files\WordNet\3.0\dict\";
WordNetClasses.WN wnc = new WordNetClasses.WN(dictPath);
List<Search> list = new List<Search>();
// used to store an array of searches populated by GetCoords
bool hascoords = false;
// used to determine whether there are any coordinate terms for the word and part of speech
Wnlib.SearchSet ss = null;
// used to retrieve the SearchSet from GetCoords
List<String> outcoords = new List<string>();
// used to build a list of words for the output
string word = "dog";
string poss = "noun";
// Get the coordinate terms
GetCoords(word, poss, ref hascoords, ref ss, ref list);
// iterate the searches in the list.
// because we are only collecting coordinate terms
// we do not take this to any depth beyond the parent
// and its morphs.
foreach (Search se in list)
{
foreach (SynSet sense in se.senses)
{
ProcessSense(sense, ref outcoords);
}
}
// output the list of coordinate terms
for (int i = 0; i <= outcoords.Count - 1; i++)
{
// txtResult.AppendText(outcoords(i).ToString + Constants.vbCrLf);
Console.WriteLine(outcoords[i]);
}
Console.Read();
}
private static void ProcessSense(SynSet sense, ref List<string> outarr)
{
foreach (Lexeme lx in sense.words)
{
string tmpstr = lx.word.Replace("_", " ");
if (outarr.IndexOf(tmpstr.ToLower()) == -1) // not in the list?
{
outarr.Add(tmpstr.ToLower());
}
}
}
static void GetCoords(string wrd, string p, ref bool b, ref SearchSet outss, ref List<Search> list)
{
Wnlib.PartOfSpeech pos = PartOfSpeech.of(p);
SearchSet ss = Wnlib.WNDB.is_defined(wrd, pos);
AddSearchFor(wrd, pos, ref list, "COORDS");
b = ss.NonEmpty;
outss = ss;
}
private static void AddSearchFor(string wrd, PartOfSpeech pos, ref List<Search> list, string schtype)
{
Wnlib.SearchType st = new SearchType(false, schtype);
Wnlib.Search se = new Search(wrd, false, pos, st, 0); // was: true for doMorphs (gm)
list.Add(se);
}
}
}
It runs just like the VB version but the words listed are NOT coordinate terms (sisters) at all. You'll see the difference if you run original WordNet 2.1 console. Use "wn dog -coorn" at command prompt. For more info, use "wn dog -h -coorn".
Obviously, the sample needs to be changed in order to list sisters for each sense. I don't know how to do this yet. Anyone?
