public static string GetResponseEnglish(string query) { var logger = NLog.LogManager.GetCurrentClassLogger(); var cache = MemoryCache.Default; if (!(cache["bot"] is Bot bot)) { var settingsPath = HttpContext.Current.Server.MapPath("~/bin/ConfigurationFiles/Settings.xml"); var aimlPath = HttpContext.Current.Server.MapPath("~/bin/AIMLFiles"); var basePath = HttpContext.Current.Server.MapPath("~/bin"); bot = new Bot(basePath); bot.LoadSettings(settingsPath); var loader = new AIMLLoader(bot); loader.LoadAIML(aimlPath); } var userId = Guid.NewGuid().ToString(); var output = bot.Chat(query, userId); logger.LogAimlResult(query, output.RawOutput); return(output.RawOutput); }
protected void Application_Start() { GlobalConfiguration.Configure(WebApiConfig.Register); AreaRegistration.RegisterAllAreas(); RouteConfig.RegisterRoutes(RouteTable.Routes); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); BundleConfig.RegisterBundles(BundleTable.Bundles); Conversation.UpdateContainer(builder => { builder.RegisterModule(new AzureModule(Assembly.GetExecutingAssembly())); var store = new InMemoryDataStore(); builder.Register(c => store) .Keyed <IBotDataStore <BotData> >(AzureModule.Key_DataStore) .AsSelf() .SingleInstance(); builder.RegisterType <DebugActivityLogger>().AsImplementedInterfaces().InstancePerDependency(); builder.RegisterModule(new PostUnhandledExceptionToUserModule()); }); var settingsPath = HttpContext.Current.Server.MapPath("~/bin/ConfigurationFiles/Settings.xml"); var aimlPath = HttpContext.Current.Server.MapPath("~/bin/AIMLFiles"); var basePath = HttpContext.Current.Server.MapPath("~/bin"); var bot = new Bot(basePath); bot.LoadSettings(settingsPath); var loader = new AIMLLoader(bot); loader.LoadAIML(aimlPath); var cache = MemoryCache.Default; cache.Set("bot", bot, new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddDays(1.0) }); }
public static async Task <string> GetResponseNorwegian(string query) { var logger = NLog.LogManager.GetCurrentClassLogger(); var cache = MemoryCache.Default; if (!(cache["bot"] is Bot bot)) { var settingsPath = HttpContext.Current.Server.MapPath("~/bin/ConfigurationFiles/Settings.xml"); var aimlPath = HttpContext.Current.Server.MapPath("~/bin/AIMLFiles"); var basePath = HttpContext.Current.Server.MapPath("~/bin"); bot = new Bot(basePath); bot.LoadSettings(settingsPath); var loader = new AIMLLoader(bot); loader.LoadAIML(aimlPath); } // Calls for AIML should be translated to English var translator = new Translator(ConfigurationManager.AppSettings["TranslatorKey"]); var utteranceInEnglish = await translator.TranslateFromNorwegianToEnglish(query); logger.LogTranslationResult(query, utteranceInEnglish, "Norwegian", "English"); var userId = Guid.NewGuid().ToString(); var output = bot.Chat(utteranceInEnglish, userId); logger.LogAimlResult(utteranceInEnglish, output.RawOutput); var resultInNorwegian = await translator.TranslateFromEnglishToNorwegian(output.RawOutput); resultInNorwegian = FirstLetterToUpper(resultInNorwegian); logger.LogTranslationResult(output.RawOutput, resultInNorwegian, "English", "Norwegian"); return(resultInNorwegian); }
/// <summary> /// Loads AIML from .aiml files into the graphmaster "brain" of the bot /// </summary> public void LoadAIMLFromFiles() { AIMLLoader loader = new AIMLLoader(this); loader.LoadAIML(); }