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);
}
}
}
}
}