Beispiel #1
0
        protected override async Task Handle(PublishEventRequest request, CancellationToken cancellationToken)
        {
            var @event = await _eventService.Get(request.Date.Year, request.Date.Month, request.Guid);

            var text = await _ocrSpaceService.ReadImageText(new Uri(@event.ImageUrl));

            text = text.RemoveDiacritics();

            var results = DateTimeRecognizer.RecognizeDateTime(text, Culture.Spanish);


            _logger.LogInformation(results.Any() ? $"I found the following entities ({results.Count:d}):" : "I found no entities.");

            var resultJson = JsonSerializer.Serialize(results, new JsonSerializerOptions
            {
                WriteIndented = true
            });

            if (text.ToLower().Contains(@event.Title.ToLower().RemoveDiacritics()))
            {
                _logger.LogInformation($"El título `{@event.Title}` se encuentra en la imagen.");
            }
            else
            {
                _logger.LogWarning($"El título `{@event.Title}` no coincide en la imagen.");
            }

            if (text.ToLower().Contains(@event.Speaker.ToLower().RemoveDiacritics()))
            {
                _logger.LogInformation($"El speaker `{@event.Speaker}` se encuentra en la imagen.");
            }
            else
            {
                _logger.LogWarning($"El speaker `{@event.Speaker}` no se encuentra en la imagen.");
            }

            if (resultJson.Contains(@event.Date.ToString("yyyy-MM-dd")))
            {
                _logger.LogInformation($"La fecha `{@event.Date.ToLongDateString()}` se encuentra en la imagen.");
            }
            else
            {
                _logger.LogError($"La fecha `{@event.Date.ToLongDateString()}` no se encuentra en la imagen.");
                throw new EventImageConflictException($"La fecha `{@event.Date.ToLongDateString()}` no se encuentra en la imagen.");
            }
        }
        protected override async Task Handle(TestRequest request, CancellationToken cancellationToken)
        {
            _logger.LogInformation("Starting Test Handler");

            Event @event = await _eventService.GetNextEventAsync();

            _logger.LogInformation($"The Next Event is: {@event.Title}");

            await _telegramService.GetSubscribedChats();

            await _easyCronService.List();

            string text = await _ocrSpaceService.ReadImageText(new Uri(@event.ImageUrl));

            _logger.LogInformation($"Text (GetText): \r\n{text}");

            _logger.LogInformation("Finish Test Handler");
        }
        public void AnalyzeImage(int entityId)
        {
            if (_dataService.GetEntity(entityId, LoadLevel.Shallow).EntityType.Id != "Resource")
            {
                return;
            }
            var entity = _dataService.GetEntity(entityId, LoadLevel.DataOnly);

            if (entity == null)
            {
                return;
            }

            var imageText = _ocrService.ReadImageText(_utilityService.GetFile((int)entity.GetField("ResourceFileId").Data, "visualrecognition"));

            if (!string.IsNullOrEmpty(imageText))
            {
                entity.GetField("ResourceImageText").Data           = imageText;
                entity.GetField("ResourceImageTextTranslated").Data = TranslateImageText(imageText);
            }

            _dataService.UpdateEntity(entity);
        }