Example #1
0
        public void CanRecognizeTestIntent()
        {
            var engine = new SnipsNLUEngine(Path.Combine("Engines", "beverage"));

            engine.GetSnipsIntents("Make me two cups of coffee.", out string[] intents, out string json, out string error);
            Assert.NotEmpty(intents);
        }
Example #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Snips Nlu Version: " + SnipsNLUEngine.SnipsNluVersion);
            Console.WriteLine("Model Version: " + SnipsNLUEngine.GetModelVersion());
            Console.WriteLine(SnipsNLUEngine.Is64bit ? "x64" : "x86");

            using (var snipsNLUEngine = SnipsNLUEngine.CreateFromZip(zipDir))
            {
                IntentParserResult parsed = snipsNLUEngine.Parse(_sentence);
                Console.WriteLine(parsed);
            }

            using (var snipsNLUEngine = new SnipsNLUEngine(rootDir))
            {
                IntentClassifierResult[] intents = snipsNLUEngine.GetIntents(_sentence);
                Slot[]             slots         = snipsNLUEngine.GetSlots(_sentence, intents[0].IntentName);
                IntentParserResult parsed        = snipsNLUEngine.Parse(_sentence);
                Console.WriteLine(parsed);
            }

            using (var snipsNLUEngine = SnipsNLUEngine.CreateFromDirectory(rootDir))
            {
                IntentClassifierResult[] intents = snipsNLUEngine.GetIntents(_sentence);
                Slot[]             slots         = snipsNLUEngine.GetSlots(_sentence, intents[0].IntentName);
                IntentParserResult parsed        = snipsNLUEngine.Parse(_sentence);
                Console.WriteLine(parsed);
            }

            Console.WriteLine("\nDone.");
            Console.ReadKey();
        }
Example #3
0
        public SnipsNLUService(string engineDirectory) : base()
        {
            EnginesDirectory = new DirectoryInfo(engineDirectory);
            if (!EnginesDirectory.Exists)
            {
                return;
            }
            var dirs = EnginesDirectory.EnumerateDirectories();

            foreach (var d in dirs)
            {
                var e = new SnipsNLUEngine(d.FullName, Api.Ct);
                if (e.Initialized)
                {
                    Engines.Add(d.Name, e);
                }
            }
            if (Engines.Count == 0)
            {
                Error("Did not initialize any Snips NLU engines from directory {0}", engineDirectory);
                return;
            }
            else
            {
                Initialized = true;
                Info("Initialized {0} Snips NLU engines: {1}.", Engines.Count, Engines.Keys);
            }
        }
Example #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            SnipsNLUEngine.DownloadSnipsNativeLibIfMissing(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location));
            var enginesDir = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "Engines");

            services.AddSingleton(new SnipsNLUService(enginesDir));
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
Example #5
0
        static void NLU(NLUOptions o)
        {
            SnipsNLUEngine engine = new SnipsNLUEngine("nlu_engine_beverage");

            if (!engine.Initialized)
            {
                Error("Could not initialize SnipsNLU engine.");
                Exit(ExitResult.UNKNOWN_ERROR);
            }
        }
Example #6
0
        static void ASR()
        {
            #if UNIX
            JuliusSession s = new JuliusSession();
            if (!s.Initialized)
            {
                Error("Could not initialize Julius session.");
                Exit(ExitResult.UNKNOWN_ERROR);
            }
            SnipsNLUEngine engine = new SnipsNLUEngine(Path.Combine("Engines", "beverage"));
            if (!engine.Initialized)
            {
                Error("Could not initialize SnipsNLU engine.");
                Exit(ExitResult.UNKNOWN_ERROR);
            }

            s.Recognized += (text) =>
            {
                Info("Text: {0}", text);
                engine.GetSnipsIntents(text, out string[] intents, out string json, out string error);
                if (intents.Length > 0)
                {
                    Info("Intents: {0}", intents);
                    if (!intents.First().StartsWith("None"))
                    {
                        Info(intents.First().Split(':').First());
                    }
                    if (!string.IsNullOrEmpty(json))
                    {
                        Info("Slots: {0}", json);
                    }
                }
                Info("Listening. Press any key to exit...");
            };
            s.Start();
            Info("Waiting for the ASR process to become ready...");
            s.Listening += () =>
            {
                Info("Listening. Press any key to exit...");
            };
            System.Console.ReadKey(false);
            Info("Exiting...");
            s.Stop();
            #endif
        }
Example #7
0
        public void CanInitEngine()
        {
            var engine = new SnipsNLUEngine(Path.Combine("Engines", "beverage"));

            Assert.True(engine.Initialized);
        }