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

ReadStemFile() public static method

Reads a word stem file and parses it into a dictionary. The file is assumed to contain one entry per line, with each entry of the format "[word] [stem]". If the file contains duplicate entries for a given word, only the last entry will be in the dictionary.
public static ReadStemFile ( string path ) : string>.Dictionary
path string The file to read.
return string>.Dictionary
        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;
        }