Пример #1
0
        void HandleMysterySpeech(SpeechResult speech)
        {
            ///"what is" = "was it" :/. MSFT, get it together man!

            var text = speech.Name.ToLower();


            if (text.Contains(" you "))
            {
                //I have nothing to do with this...
                DependencyService.Get <ITextToSpeech>().Speak(VoiceLines.NOTHING_TO_DO);
            }

            //do they need a clue?
            if (speech.TopIntent.Intent == Intents.CLUE)
            {
                //give one if there is one.
                if (!knowledge.Clues.ElementAt(0).Revealed)
                {
                    DependencyService.Get <ITextToSpeech>().Speak(VoiceLines.CLUE1);
                    knowledge.Clues.ElementAt(0).Revealed = true;
                }
                else
                {
                    DependencyService.Get <ITextToSpeech>().Speak(VoiceLines.CLUE2);
                    knowledge.Clues.ElementAt(1).Revealed = true;
                }
            }

            //Are they ready for the answer?
            if (speech.TopIntent.Intent == Intents.GIVE_ANSWER)
            {
                DependencyService.Get <ITextToSpeech>().Speak(VoiceLines.SOLUTION);
            }

            //let's see if we can determine forced yes/no questions...
            //if (text.Contains("was it") ||
            //   text.Contains("is ") ||
            //    text.StartsWith("was ") ||
            //    text.StartsWith("did ") ||
            //    text.StartsWith("there was ") ||
            //   text.Contains("were") ||
            //   text.Contains("are ") ||
            //    text.Contains("does ") ||
            //    text.Contains("do ") ||
            //	text.Contains("is it true that "))
            if (speech.TopIntent.Intent == Intents.GUESS)
            {
                //crack into the facts.
                SearchMind(speech);
            }
            else
            {
                //must be a yes/no question
                DependencyService.Get <ITextToSpeech>().Speak(VoiceLines.ASK_YES_NO);
            }
        }
Пример #2
0
 void HandleSpeech(SpeechResult speech)
 {
     ResponseText = speech.Name;
     if (mode == MysteryMode.Welcome)
     {
         HandleWelcomeSpeech(speech);
     }
     else if (mode == MysteryMode.Mystery)
     {
         HandleMysterySpeech(speech);
     }
 }
Пример #3
0
        void HandleWelcomeSpeech(SpeechResult speech)
        {
            var text = speech.Name.ToLower();

            //if (text.Contains("get started") ||
            //   text.Contains("give me a puzzle") ||
            //   text.Contains("give me a mystery") ||
            //   text.Contains("ready")
            //  )
            if (speech.TopIntent.Intent == Intents.START_MYSTERY)
            {
                mode = MysteryMode.Mystery;

                //get started and give the puzzle.
                DependencyService.Get <ITextToSpeech>().Speak(VoiceLines.PUZZLE);
            }
            else
            {
                DependencyService.Get <ITextToSpeech>().Speak(VoiceLines.REPHRASE);
                //I'm sorry, come again?
            }
        }
Пример #4
0
        public void SearchMind(SpeechResult speech)
        {
            //this is where the magic happens...
            textToSay = "";

            //does it have negation? btw... GOTTA be a better way to do this... LUIS?
            var text        = speech.Name.ToLowerInvariant();
            var hasNegation = text.Contains("wasn't ") ||
                              text.Contains("isn't ") ||
                              text.Contains("is not ") ||
                              text.Contains("cannot ") ||
                              text.Contains("can't ") ||
                              text.Contains("will not ") ||
                              text.Contains("won't ") ||
                              text.Contains("didn't ") ||
                              text.Contains("don't ") ||
                              text.Contains("do not ") ||
                              text.Contains("did not ") ||
                              text.Contains("wasn't ") ||
                              text.Contains("weren't ") ||
                              text.Contains("not ") ||
                              text.Contains("aren't ");

            //let's get any entities in the speech...
            var entities = speech.IntentResult.Entities;

            //search knowledge for key words. If there is a match, we have uncovered something.
            var  facts            = knowledge.Facts.Where(oo => entities.Select(ee => ee.Entity).ToList().Contains(oo.Subject)).ToList();
            var  relevantFacts    = new List <Fact>();
            var  factAssociations = knowledge.Facts.Where(oo => entities.Select(ee => ee.Entity).ToList().Contains(oo.Association)).ToList();
            bool foundMatch       = false;

            if (hasNegation)
            {
                facts         = facts.Where(oo => !oo.PositiveAssociation).ToList();
                relevantFacts = facts.Where(oo => factAssociations.Contains(oo)).ToList();
                foundMatch    = facts.Any(oo => factAssociations.Contains(oo));
            }
            else
            {
                facts         = facts.Where(oo => oo.PositiveAssociation).ToList();
                relevantFacts = facts.Where(oo => factAssociations.Contains(oo)).ToList();
                foundMatch    = facts.Any(oo => factAssociations.Contains(oo));
            }


            if (foundMatch)
            {
                //they are on to something!
                if (hasNegation)
                {
                    textToSay += VoiceLines.CORRECT;
                }
                else
                {
                    textToSay += VoiceLines.YES;
                }

                foreach (var fact in relevantFacts)
                {
                    fact.WasLearned = true;
                }

                AssessProgress();
            }
            else
            {
                textToSay = VoiceLines.NO;
            }

            DependencyService.Get <ITextToSpeech>().Speak(textToSay);
        }