public static bool CheckPersonName(String s) { if (s.Contains('.')) { return(true); } bool hasSpaces = s.Trim().Any(Char.IsWhiteSpace); if (!hasSpaces) { return(false); } string[] words = Regex.Split(s, @"[\,\s\n]+"); if (TextHelpers.CanBePatronymic(words[words.Length - 1])) { return(true); } if (words.Count() != 3) { var predictedField = ColumnByDataPredictor.PredictByString(s); if (!HeaderHelpers.IsNameDeclarationField(predictedField)) { return(false); } } return(true); }
public bool HasNameColumn() { foreach (var x in ColumnOrder.Keys) { if (HeaderHelpers.IsNameDeclarationField(x)) { return(true); } } return(false); }
static public void MapColumnTitlesToInnerConstants(IAdapter adapter, List <Cell> cells, TableHeader columnOrdering) { foreach (var cell in cells) { string text = cell.GetText(true); Logger.Debug(string.Format("column title: \"{0}\"[{1}]", text.ReplaceEolnWithSpace().CoalesceWhitespace(), cell.CellWidth)); DeclarationField field; string clean_text = AbsenceMarkers.Aggregate(text, (x, y) => x.Replace(y, "")).Trim(); if (adapter.GetRowsCount() == cell.MergedRowsCount) { continue; } if ((text == "" || clean_text.Length <= 1) && (text != "№")) { // too short title, try to predict by values field = ColumnByDataPredictor.PredictEmptyColumnTitle(adapter, cell); Logger.Debug("Predict: " + field.ToString()); } else { field = HeaderHelpers.TryGetField(cell.TextAbove, text); if ((field == DeclarationField.None) && clean_text.Length <= 4) { field = ColumnByDataPredictor.PredictEmptyColumnTitle(adapter, cell); Logger.Debug("Predict: " + field.ToString()); } if (field == DeclarationField.None) { throw new SmartParserException(String.Format("Cannot recognize field \"{0}\"", text.Replace('\n', ' '))); } } if (field == DeclarationField.None && !DataHelper.IsEmptyValue(text)) { throw new ColumnDetectorException(String.Format("Fail to detect column type row: {0} title:{1}", cell.Row, text)); } if (ColumnByDataPredictor.CalcPrecision) { ColumnByDataPredictor.PredictForPrecisionCheck(adapter, cell, field); } AddColumn(columnOrdering, field, cell); if (TableHeader.SearchForFioColumnOnly) { if (HeaderHelpers.IsNameDeclarationField(field)) { break; } } } }