[Priority(10000)]   // over the non-ambiguous form
 public NLPActionResult QuestionIsaXaY(amIsAre isVerb,
                                       [Optional] AAn a, IAmbiguous <INoun> nounAmbiguous,
                                       [Optional] AAn a2, IAmbiguous <INoun> classAmbiguous)
 {
     intent.AnswerIsXaY(st, nounAmbiguous, classAmbiguous);
     return(NLPActionResult.None);
 }
Пример #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);
 }
Пример #3
0
        /// <summary>
        /// Get the common ancestors for a pair of ambiguous INouns
        /// </summary>
        private IEnumerable <SynSet> FindCommonAncestors(IAmbiguous <INoun> nounAmbiguous, IAmbiguous <INoun> classAmbiguous)
        {
            Abodit.Mutable.Graph <SynSet, Relation> classSuccessors = null;
            foreach (var @class in classAmbiguous)
            {
                var successorsForOne = SynSet.Graph.Successors <SynSet>(@class.Synset, Relation.RDFSType);
                classSuccessors = classSuccessors?.Union(successorsForOne) ?? successorsForOne;
            }

            Abodit.Mutable.Graph <SynSet, Relation> nounSuccessors = null;
            foreach (var noun in nounAmbiguous)
            {
                var edgeSuccessors = SynSet.Graph.Successors <SynSet>(noun.Synset, Relation.RDFSType);
                nounSuccessors = nounSuccessors?.Union(edgeSuccessors) ?? edgeSuccessors;
            }

            var commonAncestors = classSuccessors.Intersect(nounSuccessors);

            var topSort = commonAncestors.TopologicalSortApprox();

            return(topSort);
        }
Пример #4
0
        private FoundConnection FindConnections(IAmbiguous <INoun> nounAmbiguous, IAmbiguous <INoun> classAmbiguous)
        {
            bool onlyOne = nounAmbiguous.Count() == 1 && classAmbiguous.Count() == 1;

            foreach (var @class in classAmbiguous)
            {
                foreach (var noun in nounAmbiguous)
                {
                    if (@class.Synset == noun.Synset)
                    {
                        return(new FoundConnection {
                            Text = "Yes, those words can be synonyms."
                        });
                    }

                    var edgeSuccessors = SynSet.Graph.Successors <SynSet>(noun.Synset, Relation.RDFSType).ToList();

                    if (edgeSuccessors.Any(e => e == @class.Synset))
                    {
                        if (onlyOne)
                        {
                            return new FoundConnection {
                                       Text = "Yes, a " + noun.Singular.Text + " is a " + @class.Singular.Text
                            }
                        }
                        ;
                        else
                        {
                            return new FoundConnection {
                                       Text = "Yes, a " + noun.Singular.Text + " can be a " + @class.Singular.Text
                            }
                        };
                    }
                }
            }
            return(null);
        }
Пример #5
0
        public void GrammarDump(IListener st, IAmbiguous <ITokenText> tokenAmbiguous)
        {
            if (tokenAmbiguous.Count() > 1)
            {
                st.Say(tokenAmbiguous.First().Text + " could mean one of several things:");
            }
            int i = 0;

            foreach (var tokenGroup in tokenAmbiguous.GroupBy(t => t.Synset ?? SynSet.Empty))
            {
                st.Say(++i + ". " + tokenGroup.Key.Name);
                if (tokenGroup.Key == SynSet.Empty)
                {
                    foreach (var t in tokenGroup)
                    {
                        this.GrammarDump(st, t);
                    }
                }
                else
                {
                    this.GrammarDump(st, tokenGroup.First());
                }
            }
        }
Пример #6
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!?!?");
                }
            }
        }
 public NLPActionResult GrammarDump(define2 define, IAmbiguous <ITokenText> tokenAmbiguous)
 {
     intent.GrammarDump(st, tokenAmbiguous);
     return(NLPActionResult.None);
 }