Exemple #1
0
        void Test(string input, string expectedComm)
        {
            ParseState    st   = Parser.Parse(input);
            string        s    = st.TreeForm();
            Communication comm = Grok.GrokInput(input, st);

            if (comm.ToString() == expectedComm)
            {
                return;
            }
            Fail("Grok failed on: " + input);
            Fail("Parse: " + st.TreeForm());
            QA.UnitTest.AssertEqual(expectedComm, comm.ToString());
        }
Exemple #2
0
        public static Communication GrokInput(string text, ParseState st)
        {
            Communication comm = null;
            ActionSpec    act  = null;

            foreach (int child in st.ChildrenOf(-1))
            {
                if (st.partOfSpeech[child] == PartOfSpeech.VB && act == null)
                {
                    act = Grok.GrokAction(st, child);
                }
                if (st.partOfSpeech[child] == PartOfSpeech.IN)
                {
                    // Here's where we get fancy: based on the verb, and
                    // possibly the current state of the world, figure out
                    // this prepositional phrase modifies the last object
                    // already parsed, or instead modifies the verb.
                    // For now, we'll just assume it modifies the verb.
                    if (act != null)
                    {
                        act.location = GrokLocation(st, child);
                    }
                }
                if (st.partOfSpeech[child] == PartOfSpeech.UH)
                {
                    switch (st.words[child].ToLower())
                    {
                    case "hello":
                    case "hi":
                        comm = new ComPhatic(text, st, ComPhatic.Type.Greeting);
                        break;

                    case "bye":
                    case "goodbye":
                    case "good-bye":
                        comm = new ComPhatic(text, st, ComPhatic.Type.Goodbye);
                        break;

                    default:
                        comm = new ComEmote(text, st);
                        break;
                    }
                }
                else if (st.partOfSpeech[child] == PartOfSpeech.VB)
                {
                    switch (st.words[child].ToLower())
                    {
                    case "thank":
                    case "thank_you":
                        comm = new ComPhatic(text, st, ComPhatic.Type.ThankYou);
                        break;
                    }
                }
            }

            if (act != null && act.action != null)
            {
                // For now, we'll assume commands...
                comm = new ComCommand(text, st, act);
            }
            else if (comm == null)
            {
                // Not sure what to do with this.  Wrap it in the base class.
                comm = new Communication(text, st);
            }

            // Check for a direct address.
            // ToDo: find and use user self-knowledge, rather than hard-coded names.
            var firstWord = st.words[0].ToLower();

            if (firstWord == "diana" || firstWord == "sam")
            {
                comm.directAddress = true;
            }

            return(comm);
        }