/// <summary> /// Returns a copy of the label mapping collection. /// </summary> /// <returns></returns> public LabelMappingCollection Clone() { LabelMappingCollection col = new LabelMappingCollection(); foreach (LabelMapping m in m_rgMappings) { col.Add(m.Clone()); } return(col); }
/// <summary> /// Parses a list of strings where each string is a label mapping. /// </summary> /// <param name="rgstrMappings">Specifies the list of label mapping strings.</param> /// <returns>The new LabelMappingCollection is returned.</returns> public static LabelMappingCollection Parse(List <string> rgstrMappings) { LabelMappingCollection col = new LabelMappingCollection(); List <string> rgstrSeparators = new List <string>() { "->" }; foreach (string strMapping in rgstrMappings) { string[] rgstr = strMapping.Split(rgstrSeparators.ToArray(), StringSplitOptions.RemoveEmptyEntries); if (rgstr.Length != 2) { throw new Exception("Each label mapping should have the format 'original->new_label'."); } if (rgstr[0].Length == 0 || rgstr[1].Length == 0) { throw new Exception("Each label mapping should have the format 'original->new_label'."); } string str1 = rgstr[0].Trim('\"'); string str2 = rgstr[1].Trim('\"'); int? nConditionBoostEquals = null; int? nConditionFalse = null; rgstr = str2.Split('?'); if (rgstr.Length > 1) { str2 = rgstr[0].Trim(); string strCondition = ""; string strRightSide = rgstr[1].Trim(); rgstr = strRightSide.Split(','); if (rgstr.Length == 2) { string str3 = rgstr[0].Trim(); if (str3.Length > 0) { nConditionFalse = int.Parse(str3); } strCondition = rgstr[1].Trim(); } else if (rgstr.Length == 1) { strCondition = rgstr[0].Trim(); } else { throw new Exception("Invalid mapping format! Expected format <true_int>?<false_int>,boost=<int>"); } rgstr = strCondition.Split('='); if (rgstr.Length != 2 || rgstr[0].Trim().ToLower() != "boost") { throw new Exception("Invalid boost condition! Expected format = ?boost=<int>"); } nConditionBoostEquals = int.Parse(rgstr[1].Trim()); } col.Add(new LabelMapping(int.Parse(str1), int.Parse(str2), nConditionBoostEquals, nConditionFalse)); } return(col); }