/// <summary> /// Save the sentence master label info to a stream writer. /// </summary> /// <param name="sw">The stream writer will be saved to.</param> /// <param name="type">Indicate the type, which will impact the context of the label.</param> public void Save(TextWriter sw, LabelInfo.LabelType type) { sw.WriteLine("\"*/{0}.lab\"", _sid); for (int i = 0; i < _listLabelInfo.Count; ++i) { sw.WriteLine(_listLabelInfo[i].ToString(type)); } sw.WriteLine(EndOfSentence); }
/// <summary> /// Save the master labels to file. /// </summary> /// <param name="file">The file name.</param> /// <param name="type">Indicate the type, which will impact the context of the master label.</param> public void Save(string file, LabelInfo.LabelType type) { using (StreamWriter sw = new StreamWriter(file, false, System.Text.Encoding.ASCII)) { sw.WriteLine(MasterLabelFileHeader); foreach (KeyValuePair<string, LabelInfoSentence> kvp in _dictLabelInfoSent) { kvp.Value.Save(sw, type); } } }
/// <summary> /// Parse the line in master label file to generate a LabelInfo instance. /// </summary> /// <param name="line">The line from master label file.</param> /// <returns>A new LabelInfo instance according to the line.</returns> public static LabelInfo ParseLine(string line) { LabelInfo labelInfo = new LabelInfo(); string[] parts = line.Split(_splitChars, StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 3 || parts.Length == 4) { labelInfo.Start = int.Parse(parts[0], CultureInfo.InvariantCulture.NumberFormat); labelInfo.End = int.Parse(parts[1], CultureInfo.InvariantCulture.NumberFormat); labelInfo.Label = parts[2]; if (parts.Length == 4) { labelInfo.SecondLabel = parts[3]; } Debug.Assert(labelInfo.End >= labelInfo.Start && labelInfo.Start >= 0, "The end time point mustn't less than the start and zero."); } else if (parts.Length == 1) { labelInfo.Label = parts[0]; } else { string message = Helper.NeutralFormat("Unsupported label format : [{0}].", line); throw new InvalidDataException(message); } return labelInfo; }