public static Dictionary<string, HashSet<string>> ReadVerbParticleFile(string path)
{
//maps particle -> {set of verbs}
Dictionary<string, HashSet<string>> particleMap = new Dictionary<string, HashSet<string>>();
using (StreamReader file = new StreamReader(path))
{
string entry;
while (!file.EndOfStream)
{
entry = file.ReadLine().Trim();
if (!string.IsNullOrEmpty(entry) && !entry.StartsWith("#") && !entry.StartsWith("//")) //ignore commented lines
{
//the format of an entry is <verb> <particle>
string[] parts = entry.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
if (parts.Length == 2)
{
//found a valid entry
string verb = parts[0];
string particle = parts[1];
//if we haven't seen this particle yet, initialize the set
if (!particleMap.ContainsKey(particle))
particleMap[particle] = new HashSet<string>();
//add new verb
particleMap[particle].Add(verb);
}
else
{
//not a valid entry
Console.Error.WriteLine("Invalid entry found in {0}: {1}", path, entry);
}
}
}
}
return particleMap;
}