ABB.Swum.WordData.PositionalFrequencies.PositionalFrequencies C# (CSharp) Метод

PositionalFrequencies() публичный Метод

Creates a new PostionalFrequencies object, using the positional frequency data in the supplied file. The file should contain a single word entry per line, in the format [word] [first-freq] [middle-freq] [last-freq] [only-freq]
public PositionalFrequencies ( string filePath ) : System
filePath string The path to the file with the positional frequency data.
Результат System
        public PositionalFrequencies(string filePath)
        {
            this.frequencies = new Dictionary<string, PositionalFrequencyRecord>();
            using (StreamReader file = new StreamReader(filePath))
            {
                string entry;
                while (!file.EndOfStream)
                {
                    entry = file.ReadLine().Trim();
                    if (!entry.StartsWith("#") && !entry.StartsWith("//")) //ignore commented lines
                    {
                        //the format of an entry is <word> <first> <middle> <last> <only>
                        string[] parts = entry.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
                        if (parts.Length == 5)
                        {
                            //found a valid entry
                            string word = parts[0];
                            try
                            {
                                int first = int.Parse(parts[1]);
                                int middle = int.Parse(parts[2]);
                                int last = int.Parse(parts[3]);
                                int only = int.Parse(parts[4]);
                                this.AddFrequency(word, first, middle, last, only);
                            }
                            catch (FormatException e)
                            {
                                Console.Error.WriteLine("Invalid entry found in {0}: {1}", filePath, entry);
                                Console.Error.WriteLine(e.ToString());
                            }
                        }
                        else
                        {
                            //not a valid entry
                            Console.Error.WriteLine("Invalid entry found in {0}: {1}", filePath, entry);
                        }
                    }
                }
            }
        }

Same methods

PositionalFrequencies::PositionalFrequencies ( ) : System