public void Analyse_Command() { //Arrange var authKey = "key1"; var input = "file.txt"; var output = "result.txt"; var args = new string[] { "analyse", "-a", authKey, "-i", input, "-o", output }; var serviceProvider = Program.GetServiceCollection(); var analysisResponse = new AnalysisResponse { Id = Guid.NewGuid().ToString(), Text = input, Intentions = new List <IntentionResponse> { new IntentionResponse { Id = "a", Score = 0.5f } }.ToArray(), Entities = new List <EntityResponse> { new EntityResponse { Id = "e", Value = "v" } }.ToArray() }; var inputList = InputWithTags.FromTextList(new List <string> { "a", "b", "c" }); var blipAIClient = Substitute.For <IBlipAIClient>(); blipAIClient.AnalyseForMetrics(Arg.Any <string>()).Returns(Task.FromResult(analysisResponse)); var blipAIClientFactory = Substitute.For <IBlipClientFactory>(); blipAIClientFactory.GetInstanceForAI(Arg.Is <string>(s => s.Equals(authKey))).Returns(blipAIClient); var fileService = Substitute.For <IFileManagerService>(); fileService.IsDirectory(input).Returns(true); fileService.IsFile(input).Returns(true); fileService.GetInputsToAnalyseAsync(input).Returns(inputList.ToList()); serviceProvider.AddSingleton <IBlipClientFactory>(blipAIClientFactory); serviceProvider.AddSingleton <IFileManagerService>(fileService); Program.ServiceProvider = serviceProvider.BuildServiceProvider(); //Act int result = Program.Main(args); //Assert Assert.AreEqual(result, 0); }
private void ProcessPartsToFillInputWithTags(string[] parts, InputWithTags inputWithTags, int i) { switch (i) { case 1: // Tags if (parts[i] == "0") { inputWithTags.Tags = null; } else { inputWithTags.Tags = InputWithTags.GetTagsByString(parts[i]).ToList(); } break; case 2: // Intent if (parts[i] == "0") { inputWithTags.IntentExpected = null; } else { inputWithTags.IntentExpected = parts[i]; } break; case 3: // Entities if (parts[i] == "0") { inputWithTags.EntitiesExpected = null; } else { inputWithTags.EntitiesExpected = parts[i].Split(',').ToList(); } break; case 4: // Answer if (parts[i] == "0") { inputWithTags.AnswerExpected = null; } else { inputWithTags.AnswerExpected = parts[i]; } break; } }
private async Task <List <DataBlock> > GetInputList( InputType inputType, string inputSource, IBlipAIClient client, IContentManagerApiClient contentClient, string reportOutput, List <Intention> intentions, bool doContentCheck, bool rawContent) { switch (inputType) { case InputType.Phrase: return(new List <DataBlock> { DataBlock.GetInstance(1, InputWithTags.FromText(inputSource), client, contentClient, reportOutput, doContentCheck, rawContent, intentions) }); case InputType.File: var inputListAsString = await _fileService.GetInputsToAnalyseAsync(inputSource); return(inputListAsString .Select((input, i) => DataBlock.GetInstance(i + 1, input, client, contentClient, reportOutput, doContentCheck, rawContent, intentions)) .ToList()); case InputType.Bot: var botSource = inputSource.Replace(BOT_KEY_PREFIX, "").Trim(); var localClient = _blipClientFactory.GetInstanceForAI(botSource); _logger.LogDebug("\tCarregando intenções do bot fonte..."); var allIntents = await localClient.GetAllIntentsAsync(); var questionListAsString = new List <string>(); foreach (var intent in allIntents) { questionListAsString.AddRange(intent.Questions.Select(q => q.Text)); } _logger.LogDebug("\tIntenções carregadas!"); return(questionListAsString .Select((input, i) => DataBlock.GetInstance(i + 1, InputWithTags.FromText(input), client, contentClient, reportOutput, doContentCheck, rawContent, intentions)) .ToList()); default: throw new ArgumentException($"Unexpected value {inputType}.", "inputType"); } }
private InputWithTags ConvertStringToInputWithTags(string line) { /* Parts: * 0 - Input * 1 - Tags (0 = null) * 2 - Intent (0 = null) * 3 - Entities (0 = null) * 4 - Answer (0 = null) */ var parts = line.Split('\t', StringSplitOptions.RemoveEmptyEntries); var inputWithTags = new InputWithTags { Input = parts[0] }; for (int i = 1; i < parts.Length; i++) { ProcessPartsToFillInputWithTags(parts, inputWithTags, i); } return(inputWithTags); }
public void When_NLPAnalyse_Input_IsFile_Then_AnalyseFile() { //Arrange var authKey = "key1"; var input = "file.txt"; var output = "outpath"; var analysisResponse = new AnalysisResponse { Id = Guid.NewGuid().ToString(), Text = input, Intentions = new List <IntentionResponse> { new IntentionResponse { Id = "a", Score = 0.5f } }.ToArray(), Entities = new List <EntityResponse> { new EntityResponse { Id = "e", Value = "v" } }.ToArray() }; var inputList = InputWithTags.FromTextList(new List <string> { "a", "b", "c" }); var blipAIClient = Substitute.For <IBlipAIClient>(); blipAIClient.AnalyseForMetrics(Arg.Any <string>()).Returns(Task.FromResult(analysisResponse)); var blipAIClientFactory = Substitute.For <IBlipClientFactory>(); blipAIClientFactory.GetInstanceForAI(Arg.Is <string>(s => s.Equals(authKey))).Returns(blipAIClient); var fileService = Substitute.For <IFileManagerService>(); fileService.IsDirectory(input).Returns(true); fileService.IsFile(input).Returns(true); fileService.GetInputsToAnalyseAsync(input).Returns(inputList.ToList()); var logger = Substitute.For <IInternalLogger>(); var analyseService = new NLPAnalyseService(blipAIClientFactory, fileService, logger); var handler = new NLPAnalyseHandler(analyseService, logger) { Authorization = new MyNamedParameter <string> { Value = authKey }, Input = new MyNamedParameter <string> { Value = input }, ReportOutput = new MyNamedParameter <string> { Value = output }, Verbose = new MySwitch { IsSet = false }, DoContentCheck = new MySwitch { IsSet = false }, Raw = new MySwitch { IsSet = false }, }; //Act var status = handler.RunAsync(null).Result; //Assert foreach (var item in inputList) { blipAIClient.Received().AnalyseForMetrics(item.Input); } blipAIClient.Received(inputList.ToList().Count).AnalyseForMetrics(Arg.Any <string>()); }