ABB.Swum.Utilities.LibFileLoader.ReadVerbParticleFile C# (CSharp) Method

ReadVerbParticleFile() public static method

Reads the verb particle file at the given path and reads it into a Dictionary. Each line of the file should be in the format: [verb] [particle]. The returned Dictionary maps a particle to a set of verbs.
public static ReadVerbParticleFile ( string path ) : HashSet>.Dictionary
path string The verb particle file to read.
return HashSet>.Dictionary
        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;
        }