public async Task <FileAnalysisResult> AnalyzeFileContentAsync(InputFileData inputFileData) { if (inputFileData.FileContentType == FileContentType.PDF) { var sasToken = _storageService.GenerateSasToken(); inputFileData.FilePath = $"{inputFileData.FilePath}?{sasToken}"; var textFromTheInputDocument = await _ocrScannerService.ScanDocumentAndGetResultsAsync(inputFileData.FilePath); var sentimentAnalysisResponse = await _textAnalyticsClient.AnalyzeSentimentAsync(textFromTheInputDocument); if (sentimentAnalysisResponse != null) { var sentimentAnalysisResult = sentimentAnalysisResponse.Value; var fileAnalysisResult = new FileAnalysisResult(); fileAnalysisResult.SentimentValues.Add(sentimentAnalysisResult.Sentiment.ToString()); return(fileAnalysisResult); } } throw new ArgumentException("Input file shuld be either TXT or PDF file."); }
public async Task RunOrchestratorAsync( [OrchestrationTrigger] IDurableOrchestrationContext context, ILogger log) { var fileLocation = context.GetInput <string>(); if (!string.IsNullOrEmpty(fileLocation)) { var fileFormat = _fileFormatValidationService.VeriyFileContentType(fileLocation); var inputFileData = new InputFileData { FileContentType = fileFormat, FilePath = fileLocation }; if (fileFormat == FileContentType.PDF) { var analysisResult = await context.CallActivityAsync <FileAnalysisResult>(FunctionNamesRepository.TextFileAnalyzerFunc, inputFileData); await context.CallActivityAsync(FunctionNamesRepository.AnalysisResultAggregatorFunc, analysisResult); } if (fileFormat == FileContentType.MP3 || fileFormat == FileContentType.MP4) { var analysisResult = await context.CallActivityAsync <FileAnalysisResult>(FunctionNamesRepository.AudioVideoFileAnalyzerFunc, inputFileData); await context.CallActivityAsync(FunctionNamesRepository.AnalysisResultAggregatorFunc, analysisResult); } if (fileFormat == FileContentType.Unsupported) { log.LogError($"Unsupported file content type. File path: {fileLocation}"); } } }
public async Task <FileAnalysisResult> AnalyzeTextFileAsync([ActivityTrigger] InputFileData inputFileData, ILogger log) { var fileAnalysisResult = await _textFileProcessingService.AnalyzeFileContentAsync(inputFileData); return(fileAnalysisResult); }
public async Task <FileAnalysisResult> AnalyzeFileContentAsync(InputFileData inputFileData) { FileAnalysisResult fileAnalysisResult = new FileAnalysisResult(); var sasToken = _storageService.GenerateSasToken(); var videoUrl = $"{inputFileData.FilePath}?{sasToken}"; AddApiKeyHeader(); var accountAccessToken = await GetVideoIndexerAccountAccessTokenAsync(); var content = new MultipartFormDataContent(); var queryParams = CreateQueryString( new Dictionary <string, string>() { { "accessToken", accountAccessToken }, { "name", $"new-video-{Guid.NewGuid()}" }, { "privacy", "private" }, { "partition", "partition" }, { "videoUrl", videoUrl }, }); var uploadRequestResult = await _httpClient.PostAsync($"{_videoIndexerServiceConfiguration.Endpoint}/{_videoIndexerServiceConfiguration.Location}/Accounts/{_videoIndexerServiceConfiguration.AccountId}/Videos?{queryParams}", content); var uploadResult = await uploadRequestResult.Content.ReadAsStringAsync(); var videoId = JsonConvert.DeserializeObject <dynamic>(uploadResult)["id"]; var videoTokenRequestResult = await _httpClient.GetAsync($"{_videoIndexerServiceConfiguration.Endpoint}/auth/" + $"{_videoIndexerServiceConfiguration.Location}/Accounts/" + $"{_videoIndexerServiceConfiguration.AccountId}/Videos/{videoId}/AccessToken?allowEdit=true"); var videoAccessToken = await videoTokenRequestResult.Content.ReadAsStringAsync(); videoAccessToken = videoAccessToken.Replace("\"", ""); RemoveApiKeyHeader(); queryParams = CreateQueryString( new Dictionary <string, string>() { { "accessToken", videoAccessToken }, { "language", "English" } }); AudioVideoAnalysisResult audioVideoAnalysisResult = null; while (true) { await Task.Delay(10000); var videoGetIndexRequestResult = await _httpClient.GetAsync($"{_videoIndexerServiceConfiguration.Endpoint}/{_videoIndexerServiceConfiguration.Location}/Accounts/" + $"{_videoIndexerServiceConfiguration.AccountId}/Videos/{videoId}/Index?{queryParams}"); var videoGetIndexResult = await videoGetIndexRequestResult.Content.ReadAsStringAsync(); var processingState = JsonConvert.DeserializeObject <dynamic>(videoGetIndexResult)["state"]; if (processingState != "Uploaded" && processingState != "Processing") { audioVideoAnalysisResult = JsonConvert.DeserializeObject <AudioVideoAnalysisResult>(videoGetIndexResult); break; } } if (audioVideoAnalysisResult != null) { if (audioVideoAnalysisResult.summarizedInsights != null) { foreach (var sentimentValue in audioVideoAnalysisResult.summarizedInsights.sentiments) { fileAnalysisResult.SentimentValues.Add(sentimentValue.sentimentKey); } } } return(fileAnalysisResult); }
public void SetScanDuration(IInputFile inputFile, TimeSpan scanDuration) { InputFileData inputFileData = GetInputFileData(inputFile); inputFileData.ScanDuration = scanDuration; }
public TimeSpan GetScanDuration(IInputFile inputFile) { InputFileData inputFileData = GetInputFileData(inputFile); return(inputFileData.ScanDuration); }
public IList <IDataBlock> GetDataBlocks(IInputFile inputFile) { InputFileData inputFileData = GetInputFileData(inputFile); return(inputFileData.DataBlocks.AsReadOnly()); }
public IList <IDetector> GetDetectors(IInputFile inputFile) { InputFileData inputFileData = GetInputFileData(inputFile); return(inputFileData.Detectors); }