/// <summary> /// Inflates the catalog item's feature vector size to the required size. /// </summary> private SarCatalogItem InflateFeaturesVector(SarCatalogItem catalogItem, int newSize) { string[] newVector = new string[newSize]; if (catalogItem.FeatureVector != null) { Array.Copy(catalogItem.FeatureVector, newVector, catalogItem.FeatureVector.Length); } catalogItem.FeatureVector = newVector; return(catalogItem); }
/// <summary> /// Parse the input catalog file into catalog items. /// </summary> private IEnumerable <SarCatalogItem> ParseCatalogFile( string catalogFilePath, ConcurrentDictionary <string, uint> featureNamesIndex, FileParsingReport parsingReport) { using (var reader = new TextFieldParser(catalogFilePath) { Delimiters = new[] { "," } }) { while (!reader.EndOfData) { string[] fields; try { parsingReport.TotalLinesCount++; fields = reader.ReadFields(); } catch (MalformedLineException) { parsingReport.Errors.Add( new ParsingError(Path.GetFileName(catalogFilePath), reader.ErrorLineNumber, ParsingErrorReason.MalformedLine)); if (parsingReport.Errors.Count > _maximumParsingErrorsCount) { parsingReport.IsCompletedSuccessfuly = false; yield break; } continue; } ParsingErrorReason?parsingError; ParsingErrorReason?parsingWarning; SarCatalogItem catalogItem = ParseCatalogItem(fields, featureNamesIndex, out parsingError, out parsingWarning); if (parsingError.HasValue) { parsingReport.Errors.Add( new ParsingError(Path.GetFileName(catalogFilePath), reader.LineNumber - 1, parsingError.Value)); if (parsingReport.Errors.Count > _maximumParsingErrorsCount) { parsingReport.IsCompletedSuccessfuly = false; yield break; } continue; } if (parsingWarning.HasValue) { parsingReport.Warnings.Add( new ParsingError(Path.GetFileName(catalogFilePath), reader.LineNumber - 1, parsingWarning.Value)); continue; } parsingReport.SuccessfulLinesCount++; yield return(catalogItem); } } // no more lines to parse - mark the parsing as successful parsingReport.IsCompletedSuccessfuly = true; }