コード例 #1
0
        public void ResolveAndExecute(SentenceBuilder builder)
        {
            logger.LogWarn($"{nameof(SentenceExecutionOptions)}.{nameof(ResolveAndExecute)} is only a prototype");

            foreach (var executable in this.Executables)
            {
                var name = executable.ToString().ToLower();
                switch (name)
                {
                case "list":
                    logger.LogInfo($"{nameof(SentenceExecutionOptions)}.{nameof(ResolveAndExecute)} resolved {name}");
                    var resolutionTarget = builder.Words.Where(x => x.Word != "list" && x.Word != "the" && x.Word != "what" && x.Word != "are").ToList();
                    var target           = ResolveTarget(resolutionTarget);
                    if (target == null)
                    {
                        logger.LogWarn($"{nameof(SentenceExecutionOptions)}.{nameof(ResolveAndExecute)} failed to resolve '{string.Join(", ", resolutionTarget.Select(x => x.Word))}'");
                    }
                    else
                    {
                        ListTarget(target);
                    }
                    break;

                default:
                    logger.LogWarn($"{nameof(SentenceExecutionOptions)}.{nameof(ResolveAndExecute)} failed to resolve executable {name}");
                    break;
                }
            }
        }
コード例 #2
0
        public void ProcessInput(string input)
        {
            logger.LogDebug($"ProcessInput:'{input}'");
            TokenCollection collection      = input;
            var             sentenceBuilder = new SentenceBuilder();

            foreach (var token in collection.TextTokens)
            {
                string nomalized = token.Normalize();
                var    def       = EnglishDictionary.Lookup(nomalized);
                if (def == null)
                {
                    logger.LogWarn($"Defintion for {nomalized} not found");
                }
                else
                {
                    logger.LogDebug($"Defintion for {nomalized}: {def.ToJson()}");
                    sentenceBuilder.Add(def);
                }
            }

            SentenceExecutionOptions executionOptions = sentenceBuilder.BuildOptions();

            if (executionOptions.IsExecutable())
            {
                executionOptions.ResolveAndExecute(sentenceBuilder);
            }
        }