public void RegisterNewIntentionRecognitionBot_ShouldReturnCorrectDataType() { var user = Builder <User> .CreateNew() .With(x => x.IsDeleted == false && x.Id == "id") .Build(); this._unitOfWork = new Mock <IUnitOfWork>(); this._unitOfWork.Setup(x => x.UserRepository.FindById(It.IsAny <string>())) .Returns(user); this._unitOfWork.Setup(x => x.BotRepository.Add(It.IsAny <Bot>())); this._unitOfWork.Setup(x => x.SaveChanges()) .Returns(1); this._service = new IntentionRecognitionService(this._unitOfWork.Object, null, null, null); var bot = new BotCreateModel() { UserId = user.Id }; var result = this._service.RegisterNewIntentionRecognitionBot(bot, "test"); Assert.AreEqual(typeof(long), result.GetType()); }
public void RegisterNewIntentionRecognitionBot_ShouldTrowCorrectExceptionWithIncorrectInput() { var user = Builder <User> .CreateNew() .With(x => x.IsDeleted == false && x.Id == null) .Build(); this._unitOfWork = new Mock <IUnitOfWork>(); this._unitOfWork.Setup(x => x.UserRepository.FindById("id")) .Returns(user); this._unitOfWork.Setup(x => x.BotRepository.Add(It.IsAny <Bot>())); this._unitOfWork.Setup(x => x.SaveChanges()) .Returns(1); this._service = new IntentionRecognitionService(this._unitOfWork.Object, null, null, null); var bot = new BotCreateModel() { UserId = null }; Assert.Throws <ArgumentException>(() => this._service.RegisterNewIntentionRecognitionBot(bot, "test")); }
public long RegisterNewIntentionRecognitionBot(BotCreateModel model, string createdBy) { var user = this.FindUserById(model.UserId); var bot = new Bot() { CreatedBy = createdBy, Name = model.Name, BotType = model.BotType.ToString(), EnvironmentType = model.EnvironmentType.ToString(), Image = model.Image, User = user, UserId = user.Id }; this.Data.BotRepository.Add(bot); this.Data.SaveChanges(); //var network = this.GenerateIntentionRecognizerBotNetwork(model); //network.Bot = bot; //network.BotId = bot.Id; //network.CreatedBy = createdBy; //this.Data.NeuralNetworkDataRepository.Add(network); //this.Data.SaveChanges(); //foreach (var intentionModel in model.Intentions) //{ // var intention = new Intention // { // Bot = bot, // BotId = bot.Id, // Name = intentionModel.Name, // CreatedBy = createdBy, // }; // this.Data.IntentionRepository.Add(intention); // this.Data.SaveChanges(); // foreach (var keymodel in intentionModel.ActivationKeys) // { // var key = new ActivationKey // { // Name = keymodel.Name, // CreatedBy = createdBy, // Intention = intention, // IntentionId = intention.Id // }; // this.Data.ActivationKeyRepository.Add(key); // } // this.Data.SaveChanges(); //} return(bot.Id); }
private void GenerateNetwork(BotCreateModel model, string createdBy, Bot bot) { var network = this.GenerateIntentionRecognizerBotNetwork(model); network.Bot = bot; network.BotId = bot.Id; network.CreatedBy = createdBy; this.Data.NeuralNetworkDataRepository.Add(network); this.Data.SaveChanges(); }
private NeuralNetworkData GenerateIntentionRecognizerBotNetwork(BotCreateModel bot) { var inputLayer = 0; foreach (var intention in bot.Intentions) { for (int i = 0; i < intention.ActivationKeys.Count; i++) { inputLayer++; } } return(this._neuralNetworkService.GenerateIntentionRecognitionNeuralNetworkData( inputLayer, bot.Intentions.Count)); }
private void CreateAndTrainPizzaLoverBot(User user) { //{ "i", "like", "pizza", "eat", "lunch", "every", "day"}) //{"i", "am", "name", "is", "hello", "hi", "how", "are", "you", "who", "what"}) Console.WriteLine("Creating new bot started..."); var botModel = new BotCreateModel() { UserId = user.Id, Name = "Pizza lover Bot", BotType = BotType.IntentionRecognizer, EnvironmentType = EnvironmentType.Test, Image = @"http://i2.cdn.turner.com/money/dam/assets/151111102126-artificial-intelligence-ai-robots-780x439.jpg", Intentions = this.GenerateSampleIntentions() }; var id = this._botService.FullRegisterNewIntentionRecognitionBot(botModel, "admin"); Console.WriteLine("Creating new bot done."); Console.WriteLine(); Console.WriteLine("Training started..."); var trainingData = new Dictionary <string, long>() { { "i like pizza", 1 }, { "i lunch pizza", 1 }, { "i eat pizza every day", 1 }, { "i lunch pizza every day", 1 }, { "i like pizza for lunch", 1 }, { "every day is pizza day", 1 }, { "i am john", 2 }, { "my name is john", 2 }, { "who are you", 2 }, { "how are you", 2 }, { "hi", 2 }, { "hello", 2 } }; var result = this._botService.TrainIntentionRecognitionBot(id, trainingData); Console.WriteLine("Training done..."); Console.WriteLine(result); }
private void CreateAndTrainIntroductionBot(User user) { //{ "i", "like", "pizza", "eat", "lunch", "every", "day"}) //{"i", "am", "name", "is", "hello", "hi", "how", "are", "you", "who", "what"}) Console.WriteLine("Creating new bot started..."); var botModel = new BotCreateModel() { UserId = user.Id, Name = "Introduction Bot", BotType = BotType.IntentionRecognizer, EnvironmentType = EnvironmentType.Test, Image = @"http://static3.businessinsider.com/image/5661d93edd0895060c8b48ae/the-best-science-fiction-as-picked-by-20-ai-experts.jpg", Intentions = this.GenerateSampleIntentions() }; var id = this._botService.FullRegisterNewIntentionRecognitionBot(botModel, "admin"); Console.WriteLine("Creating new bot done."); Console.WriteLine(); Console.WriteLine("Training started..."); var trainingData = new Dictionary <string, long>() { { "i like pizza", 1 }, { "i lunch pizza", 1 }, { "i eat pizza every day", 1 }, { "i lunch pizza every day", 1 }, { "i like pizza for lunch", 1 }, { "every day is pizza day", 1 }, { "i am john", 2 }, { "my name is john", 2 }, { "who are you", 2 }, { "how are you", 2 }, { "hi", 2 }, { "hello", 2 } }; var result = this._botService.TrainIntentionRecognitionBot(id, trainingData); Console.WriteLine("Training done..."); Console.WriteLine(result); }
public ActionResult Create([Bind(Include = "Id,Name,Image")] BotCreateModel bot) { try { if (this.ModelState.IsValid) { bot.BotType = BotType.IntentionRecognizer; bot.EnvironmentType = EnvironmentType.Production; bot.UserId = this.User.Identity.GetUserId(); this._intentionRecognitionService.RegisterNewIntentionRecognitionBot(bot, this.User.Identity.Name); return(RedirectToAction("Index")); } return(View(bot)); } catch (NotFoundException ex) { return(HttpNotFound(ex.Message)); } }
public long FullRegisterNewIntentionRecognitionBot(BotCreateModel model, string createdBy) { //var intentions = model.Intentions // .Select(i => new Intention // { // Name = i.Name, // CreatedBy = createdBy, // ActivationKeys = i.ActivationKeys // .Select(a => new ActivationKey // { // Name = a.Name, // CreatedBy = createdBy // }) // .ToArray() // }) // .ToArray(); var user = this.FindUserById(model.UserId); var bot = new Bot() { CreatedBy = createdBy, Name = model.Name, BotType = model.BotType.ToString(), EnvironmentType = model.EnvironmentType.ToString(), Image = model.Image, User = user, UserId = user.Id //Intentions = intentions, //NeuralNetworkDatas = new List<NeuralNetworkData> { this.GenerateIntentionRecognizerBotNetwork(model) } //NeuralNetworkDatas = new List<NeuralNetworkData>() //{ // new NeuralNetworkData() // { // CreatedOn = DateTime.Now, // CreatedBy = UserRoleType.Admin.ToString(), // Type = NeuralNetworkType.Test.ToString(), // Data = Encoding.ASCII.GetBytes("test") // } //} }; //bot.NeuralNetworkDatas.Add(network); //this.CheckBotForExistingName(bot.Name); this.Data.BotRepository.Add(bot); this.Data.SaveChanges(); //var network = this.GenerateIntentionRecognizerBotNetwork(model); //network.Bot = bot; //network.BotId = bot.Id; //network.CreatedBy = createdBy; //this.Data.NeuralNetworkDataRepository.Add(network); //this.Data.SaveChanges(); this.GenerateNetwork(model, createdBy, bot); foreach (var intentionModel in model.Intentions) { var intention = new Intention { Bot = bot, BotId = bot.Id, Name = intentionModel.Name, CreatedBy = createdBy, }; this.Data.IntentionRepository.Add(intention); this.Data.SaveChanges(); foreach (var keymodel in intentionModel.ActivationKeys) { var key = new ActivationKey { Name = keymodel.Name, CreatedBy = createdBy, Intention = intention, IntentionId = intention.Id }; this.Data.ActivationKeyRepository.Add(key); } this.Data.SaveChanges(); } return(bot.Id); }