Пример #1
0
        public IParsedPhrase ToPhrase(POSTagger tagger, GrammarParser parser)
        {
            if (name.Contains(" "))
            {
                List <IParsedPhrase> phrases = new List <IParsedPhrase>();
                List <string>        words   = StringUtilities.SplitWords(name, true);
                foreach (string word in words)
                {
                    phrases.Add(new WordPhrase(word, "??"));
                }

                List <KeyValuePair <string, string> > tokens = tagger.ResolveUnknowns(phrases);

                return(parser.Parse(tokens));
            }
            else
            {
                if (kind == Kind.Event)
                {
                    return(new WordPhrase(name, "VB"));
                }
                if (kind == Kind.Attribute)
                {
                    return(new WordPhrase(name, "JJ"));
                }
                // entity
                return(new WordPhrase(name, "NN"));
            }
        }
        public static IParsedPhrase ProducedPhrase(Context context, POSTagger tagger, GrammarParser parser)
        {
            List <IParsedPhrase> phrases = new List <IParsedPhrase>();

            foreach (IContent content in context.Contents)
            {
                if (content is Word)
                {
                    phrases.Add(new WordPhrase(content.Name));
                }
                else if (content is Special && (content.Name.StartsWith("*") || content.Name.StartsWith("_")))
                {
                    List <IContent> words = GetStarValue(context, content.Name);
                    foreach (IContent word in words)
                    {
                        phrases.Add(new WordPhrase(content.Name));
                    }
                }
                else if (content is Variable)
                {
                    IParsedPhrase phrase = ((Variable)content).Produce(context, tagger, parser);
                    if (phrase == null)
                    {
                        return(null);    // failed!
                    }
                    phrases.Add(phrase);
                }
                else if (content is Concept)
                {
                    phrases.Add(new WordPhrase(((Concept)content).Name));
                }
                else
                {
                    phrases.Add(new WordPhrase(content.Name));
                }
            }

            if (phrases.Count == 0)
            {
                return(null);
            }

            List <KeyValuePair <string, string> > tokens = tagger.ResolveUnknowns(phrases);

            return(parser.Parse(tokens));
        }