// Определяем принадлежность предложения static int SentenceDefinition(List <string> text, SentenceAttributes sentence, int overlapNumber = 1) { var bestMatch = new int[2]; for (int tNum = 0; tNum < text.Count(); tNum++) { var words = text[tNum].ToLower().Split(new[] { " " }, StringSplitOptions.None); var cell = new int[sentence.keys.Count(), words.Count()]; // Сверяем текст с ключами for (int i = 0; i < sentence.keys.Count(); i++) { for (int j = 0; j < words.Count(); j++) { int i2 = i < 1 ? 0 : i - 1; int j2 = j < 1 ? 0 : j - 1; if (words[j].Contains(sentence.keys[i].ToLower())) { cell[i, j] = cell[i2, j2] + 1; } else { cell[i, j] = Math.Max(cell[i2, j], cell[i, j2]); } } } int maxCell = cell.Cast <int>().Max(); if (bestMatch[1] < maxCell) { bestMatch[0] = tNum; bestMatch[1] = maxCell; } } return((bestMatch[0] > 0 || bestMatch[1] > 0) && bestMatch[1] >= overlapNumber ? bestMatch[0] : -1); }
// Получаем данные в предложении static string GetData(string text, SentenceAttributes sentenceAttributes, string cultureVariable) { /* * Данные могут иметь следующую структуру: * - числовые (int) * - число с плавающей точкой, два знака после запятой (double) * - текстовые * -- с наличием предопределенных вариантов * -- без вариантов */ string output = String.Empty; var temp = new List <string>(); foreach (var splitItem in sentenceAttributes.split) { var splitPart = splitItem.Split(new[] { "." }, StringSplitOptions.None)[0]; var splitDivider = splitItem.Split(new[] { "." }, StringSplitOptions.None)[1]; if (text.Contains(splitDivider)) { if (splitPart.Equals("L")) { text = text.Split(new[] { splitDivider }, StringSplitOptions.None).Last(); } else { text = text.Split(new[] { splitDivider }, StringSplitOptions.None)[Convert.ToInt32(splitPart)]; } } } // Находим значения в строке if (sentenceAttributes.format.Equals("int")) // если формат числовой (int) - возвращается только первое найденное число в строке после деления (split) { output = (Regex.Match(text, @"\d+").Value).ToString(); } else if (sentenceAttributes.format.Equals("double")) // если формат число с плавающей точкой (double) - возвращаются все числа найденные в строке после деления (split) { output = String.Format(CultureInfo.CreateSpecificCulture("ru-RU"), "{0:0.00}", Convert.ToDouble(string.Join("", text.ToCharArray().Where(Char.IsDigit))) / 100); } else if (sentenceAttributes.format.Equals("string")) { var outputList = new List <string>(); // Перечисляем все опции в sentenceAttributes for (int oNum = 0; oNum < sentenceAttributes.options.Count(); oNum++) { // Строку делим на слова var words = text.Trim().ToLower().Split(new[] { " " }, StringSplitOptions.None); // В каждой опции выделяем ключи, которые хранятся внутри скобок "{ }" выбранный вариант ключа может быть только один var optionKeys = sentenceAttributes.options[oNum].Split(new[] { "{", "}" }, StringSplitOptions.None)[1].Split(new[] { "," }, StringSplitOptions.None); // Сверяем текст с ключами for (int i = 0; i < optionKeys.Count(); i++) { if (text.Trim().ToLower().Contains(optionKeys[i].Split(new[] { "." }, StringSplitOptions.None)[0].ToLower().Trim())) { outputList.Add(sentenceAttributes.options[oNum].Replace(sentenceAttributes.options[oNum].Substring(sentenceAttributes.options[oNum].IndexOf("{"), (sentenceAttributes.options[oNum].IndexOf("}") - sentenceAttributes.options[oNum].IndexOf("{") + 1)), optionKeys[i].Replace(".", "")).Trim()); break; } } } // Проверка пустой строки чтобы избежать ошибку в UiPath if (output.Equals(null)) { output = ""; } else { output = String.Join(", ", outputList); } } else if (sentenceAttributes.format.Equals("line") || sentenceAttributes.format.Equals("global")) { output = text; } else { output = ""; } return(output); }