/** * normalize a single (section, row) input * Given a (Section, Row) input, returns (section_id, row_id, valid) * where * section_id = int or None * row_id = int or None * valid = True or False * Arguments: * section {[type]} -- [description] * row {[type]} -- [description] */ public NormalizationResult Normalize(string section, string row) { // initialize return data structure var r = new NormalizationResult(); r.SectionId = -1; r.RowId = -1; r.Valid = false; // TODO your code goes here return(r); }
/** * normalize a single (section, row) input * Given a (Section, Row) input, returns (section_id, row_id, valid) * where * section_id = int or None * row_id = int or None * valid = True or False * Arguments: * section {[type]} -- [description] * row {[type]} -- [description] */ public NormalizationResult Normalize(string section, string row) { // initialize return data structure NormalizationResult r = null; //TODO::add your code here var sectionName = LookUpSectionName(section); //look for section id based off the provided section name var bDirectMatchOnSectionName = _ManifestRecords.Any(i => i.SectionName.ToLower().Equals(sectionName.ToLower())); var bContainsComparision = _ManifestRecords.Any(i => i.SectionName.ToLower().Contains(sectionName.ToLower())); if (bDirectMatchOnSectionName || bContainsComparision) { int sectionId = 0; if (bContainsComparision) { var possibleRecords = _ManifestRecords .Where(i => i.SectionName.ToLower().Contains(sectionName.ToLower()) && i.RowName.ToLower().Contains(row.ToLower())) .Distinct() .Select(i => i.SectionId) .Distinct() .OrderByDescending(k => k) .ToList(); if (possibleRecords.Count() > 1) { //incorporate the provided row to try to find the section foreach (var possibleSectionId in possibleRecords) { var possibleSection = _ManifestRecords.Where(i => i.SectionId == possibleSectionId).FirstOrDefault(); var isMatch = Regex.IsMatch(possibleSection.SectionName, string.Format(@"\b{0}\b", Regex.Escape(sectionName))); if (isMatch) { sectionId = possibleSection.SectionId; break; } } } else { sectionId = possibleRecords.FirstOrDefault(); } } else { //locate the sectionId sectionId = _ManifestRecords .Where(i => i.SectionName.ToLower().Equals(sectionName.ToLower())) .Select(j => j.SectionId) .FirstOrDefault(); } var manifestRecordsForSectionId = GetManifestRecordsForSectionId(sectionId); //do the row analysis var bHasRows = manifestRecordsForSectionId.Any(i => i.RowName.ToLower().Equals(row.Trim().ToLower())); if (bHasRows) { var rowsInSectionId = manifestRecordsForSectionId .Where(k => k.RowName.ToLower().Equals(row.Trim().ToLower())); var rowId = rowsInSectionId.FirstOrDefault().RowId; if (rowId.HasValue) { r = ValidMatchingRecord(sectionId, rowId.Value); } else { r = InvalidateRecordWithMatchingSectionId(sectionId); } } else { r = InvalidateRecordWithMatchingSectionId(sectionId); } } else { r = InvalidateRecordWithNoMatch(); } return(r); }