Пример #1
0
        public void AnswerIsXaY(IListener st, IAmbiguous <INoun> nounAmbiguous, IAmbiguous <INoun> classAmbiguous)
        {
            var found = FindConnections(nounAmbiguous, classAmbiguous);

            if (found != null)
            {
                st.Say(found.Text);
            }
            else
            {
                var reverse = FindConnections(classAmbiguous, nounAmbiguous);

                var possibleNouns   = nounAmbiguous.Select(n => n.Synset);
                var possibleClasses = classAmbiguous.Select(n => n.Synset);

                var nounNames = possibleNouns.Select(possible =>
                                                     possible.Lexemes
                                                     .OfType <LexNoun>()
                                                     .Select(x => x.Plural)
                                                     .Select(x => x.Text)
                                                     .First())
                                .Distinct();

                var classNames = possibleClasses.Select(possible =>
                                                        possible.Lexemes
                                                        .OfType <LexNoun>()
                                                        .Select(x => x.Singular)
                                                        .Select(x => x.Text)
                                                        .First())
                                 .Distinct();

                string pluralAsEntered      = nounAmbiguous.Select(n => n.Plural.Text).First();
                string classPluralAsEntered = classAmbiguous.Select(n => n.Plural.Text).First();

                if (reverse != null)
                {
                    st.Say("No, but some " + classPluralAsEntered + " are " + pluralAsEntered);
                }
                else
                {
                    st.Say("No, no " + pluralAsEntered + " are " + classPluralAsEntered + " and no " + classPluralAsEntered + " are " + pluralAsEntered + ".");
                }

                var commonAncestors = FindCommonAncestors(classAmbiguous, nounAmbiguous).ToList();

                var commonNames = commonAncestors.Select(ca => ca.Lexemes.OfType <LexNoun>()
                                                         .Select(x => x.Plural)
                                                         .Select(x => x.Text)
                                                         .DefaultIfEmpty("-").First())
                                  .Distinct()
                                  .ToList();

                if (commonNames.Any())
                {
                    st.Say("They are both " + JoinOr(commonNames) + ".");
                    st.Say($"The  {commonAncestors.Count} SynSets for these are: {JoinOr(commonAncestors.Select(c => $"`{c.Name}`"))}");
                }
                else
                {
                    st.Say("No common ancestry!?!?");
                }
            }
        }
Пример #2
0
 public NLPActionResult GrammarDumpWithSpellingMistake(define2 define, [AboditNLP.Attributes.Insensitive(caseInsensitive: true, editDistance: 1)] IAmbiguous <ITokenText> token)
 {
     if (token.Count() == 1)
     {
         st.Say($"I think you perhaps meant 'define {token.First().Text}'");
         // But go ahead and show some more aggressive approximate matches anyway
         intent.DefineSuggestions(st, token.First().Text);
     }
     else
     {
         st.Say($"I think you perhaps meant 'define' and then one of {string.Join(", ", token.Select(x => x.Text))}");
     }
     return(NLPActionResult.None);
 }