Пример #1
0
        public async Task <string> GetWordsByMaskAsync(Guid id, [FromQuery] string[] setWords)
        {
            if (Request != null)
            {
                var bearerToken = Request.Headers["Authorization"];
                _logger.LogInformation($"GetWordsByMaskAsync {bearerToken} {DateTime.Now}");
            }

            if (setWords != null)
            {
                var setWordsParse = new string[] { };
                if (setWords.Length == 1 && setWords[0].Contains(","))
                {
                    setWordsParse = setWords[0].Split(",");
                }
                var textFromClient = await _textClient.GetById(id);

                if (textFromClient != null)
                {
                    if (setWords.Length == 0)
                    {
                        return("Количество совпадений: 0");
                    }

                    var wordsFromText = textFromClient.TextValue.Split(" ");
                    var countMatches  = setWordsParse.Length > 0 ? setWordsParse.Sum(word => wordsFromText.Count(wft => wft == word))
                        : setWords.Sum(word => wordsFromText.Count(wft => wft == word));

                    return($"Количество совпадений: {countMatches}");
                }
            }
            return("Количество совпадений: 0");
        }
Пример #2
0
        public async Task <WordMatches> FindMatches(Guid id, List <string> findStr)
        {
            //_textClient = textClient;
            TextFile text;

            try
            {
                var localTextFile = await _textClient.GetById(id);

                text = localTextFile;

                // перехват 404 ?
            }
            catch (ApiException ex)
            {
                var errors = await ex.GetContentAsAsync <Dictionary <string, string> >();

                var message = string.Join("; ", errors.Values);
                //_logger.LogInformation("|ERROR| Ошибка опроса |{time}", DateTimeOffset.Now);
                throw new Exception(message);
            }


            var result = new WordMatches();

            //result.Quantity = new List<int>();
            result.Quantity = "";
            foreach (var item in findStr)
            {
                //result.Quantity.Add(text.TextValue.Split(item).Count() - 1);
                result.Quantity += text.TextValue.Split(item).Count() - 1 + " ";
            }

            return(result);
        }
Пример #3
0
        public async Task <string> GetWordsByMaskAsync(Guid id, [FromQuery] string[] setWords)
        {
            if (setWords != null)
            {
                var setWordsParse = new string[] { };
                if (setWords.Length == 1 && setWords[0].Contains(","))
                {
                    setWordsParse = setWords[0].Split(",");
                }
                var textFromClient = await _textClient.GetById(id);

                if (textFromClient != null)
                {
                    if (setWords.Length == 0)
                    {
                        return("Количество совпадений: 0");
                    }

                    var wordsFromText = textFromClient.TextValue.Split(" ");
                    var countMatches  = setWordsParse.Length > 0 ? setWordsParse.Sum(word => wordsFromText.Count(wft => wft == word))
                        : setWords.Sum(word => wordsFromText.Count(wft => wft == word));

                    return($"Количество совпадений: {countMatches}");
                }
            }
            return("Количество совпадений: 0");
        }
Пример #4
0
        public async Task <IEnumerable <string> > FindWordsAsync(Guid id, string[] words)
        {
            if (words != null)
            {
                var getText = await _textClient.GetById(id);

                if (getText != null)
                {
                    var textArray  = getText.Text.Replace('\r', ' ').Replace('\n', ' ').Replace("  ", " ").Split(" ");
                    var selectText = textArray.SelectMany(e => words.Where(x => x == e));
                    return(selectText);
                }
            }

            return(null);
        }
Пример #5
0
        public async Task <SingleFind[]> Find(Guid id, string[] words)
        {
            var text = await TextClient.GetById(id);

            var result = new List <SingleFind>();

            foreach (string word in words)
            {
                int matches = text.TextValue.Split(word).Length - 1;
                var item    = new SingleFind()
                {
                    Word = word, Matched = matches
                };
                result.Add(item);
            }
            return(result.ToArray());
        }
Пример #6
0
 public async Task <ActionResult <TextFile> > GetById(Guid id)
 {
     return(await _textClient.GetById(id));
 }