public static Dictionary<string, string> ReadStemFile(string path)
{
Dictionary<string, string> obs = new Dictionary<string, string>();
using (StreamReader file = new StreamReader(path))
{
char[] space = { ' ' }; //the delimeter between the fields
while (!file.EndOfStream)
{
string entry = file.ReadLine().Trim();
if (!string.IsNullOrEmpty(entry) && !entry.StartsWith("#") && !entry.StartsWith("//")) //ignore blank and commented lines
{
//the format of an entry is "<word> <stem>"
string[] parts = entry.Split(space, 2);
if (parts.Length == 2)
{
//add entry to dictionary
obs[parts[0]] = parts[1];
}
else
{
//not a valid entry
Console.Error.WriteLine("Invalid entry found in {0}: {1}", path, entry);
}
}
}
}
return obs;
}