コード例 #1
0
        public void GrammarDump(IListener st, ITokenText token)
        {
            if (token.Synset != null && token.Synset != SynSet.Empty)
            {
                string definition = nlp.GetDefinition(token);
                if (!string.IsNullOrEmpty(definition))
                {
                    st.Say(definition);
                }

                // Token is not a Lexeme, it's an Impromptu proxy acting like all interfaces are present
                var ints = token.GetType().GetInterfaces();

                var edges = SynSet.Graph.Follow(token.Synset, null);

                var synonyms = edges.Where(e => e.Predicate == Relation.WordFor).Select(e => e.End)
                               .OfType <Lexeme>()
                               .Where(e => ints.Intersect(e.Interfaces).Intersect(wordFormTypes).Any())
                               .Select(e => e.Text)
                               .Where(e => e != token.Text)
                               .ToList();

                if (synonyms.Any())
                {
                    st.Say("  Synonyms " + string.Join(", ", synonyms));
                }

                // Dump the relations of this Lexeme
                foreach (var outboundEdge in edges)
                {
                    if (outboundEdge.Predicate != Relation.WordFor)
                    {
                        st.Say(outboundEdge.Predicate.ToString() + " " + outboundEdge.End.ToString());
                    }
                }
            }

            if (token is IVerb verb)
            {
                st.Say("  Present self : I " + verb.PresentSelf.Text +
                       ", Present third person: He " + verb.PresentThirdPerson.Text +
                       ", Present plural: We " + verb.PresentPlural.Text +
                       ", Present participle: " + verb.PresentParticiple.Text +
                       ", Past I/He:" + verb.Past.Text +
                       ", Past participle: " + verb.PastParticiple.Text +
                       ", Past plural: We " + verb.PastPlural.Text +
                       ", Infinitive: To " + verb.Infinitive.Text);
            }
            else if (token is INoun noun)
            {
                if (noun is Countable)
                {
                    st.Say("  Noun singular " + ((Countable)noun).Singular.Text +
                           ", plural " + ((Countable)noun).Plural.Text);
                }
                else if (noun is Uncountable)
                {
                    st.Say("  Uncountable noun " + ((Uncountable)noun).Singular.Text);
                }
            }
            else if (token is IAdjective adjective)
            {
                st.Say("  Adjective " + adjective.Normal.Text +
                       (adjective.Comparative == null ? "" : ",  Comparative " + adjective.Comparative.Text) +
                       (adjective.Comparative == null ? "" : ",  Superlative " + adjective.Superlative.Text));
            }
            else if (token is IAdverb adverb)
            {
                st.Say("  Adverb " + adverb.Text);
            }
            else if (token is IPreposition preposition)
            {
                st.Say("  Preposition " + preposition.Text);
            }
            else if (token is IConjunction conjunction)
            {
                st.Say("  Conjunction " + conjunction.Text);
            }
            else if (token is IOperator @operator)
            {
                st.Say("  Operator " + @operator.Text);
            }
            else
            {
                st.Say("  Some other form of word " + token.Text);
            }

            var interestingInterfaces = token.GetType().GetInterfaces()
                                        .Select(x => x.Name)
                                        .Except(new[] { "IActLikeProxyInitialize", "IActLikeProxy", "ISerializable", "ITokenText", "IToken" })
                                        .ToList();

            if (interestingInterfaces.Any())
            {
                st.Say("  Interfaces: " + string.Join(", ", interestingInterfaces));
            }
        }
コード例 #2
0
 public NLPActionResult GrammarDump(define2 define, ITokenText token)
 {
     intent.GrammarDump(st, token);
     return(NLPActionResult.None);
 }