Пример #1
0
        public static void Main(string[] args)
        {
            PluginEnvironment plugenv = new PluginEnvironment(new MainClass());
            string plugbase = "/Users/jrising/projects/virsona/plugins/data";
            plugenv.Initialize(plugbase + "/config.xml", plugbase, new NameValueCollection());

            // Test 1: POS Tagging
            POSTagger tagger = new POSTagger(plugenv);
            List<KeyValuePair<string, string>> tagged = tagger.TagList(StringUtilities.SplitWords("This is a test.", false));
            foreach (KeyValuePair<string, string> kvp in tagged)
                Console.WriteLine(kvp.Key + ": " + kvp.Value);

            // Test 2: Grammar parsing
            GrammarParser parser = new GrammarParser(plugenv);
            IParsedPhrase before = parser.Parse("This is a rug and a keyboard.");
            Console.WriteLine(before.ToString());

            // Test 3: Paraphrasing
            Random randgen = new Random();
            IParsedPhrase after = parser.Paraphrase(before, null, null, randgen.NextDouble());
            Console.WriteLine(after.Text);

            // Test 4: Look up some indices
            WordNetAccess wordnet = new WordNetAccess(plugenv);
            Console.WriteLine("Synonyms: " + string.Join(", ", wordnet.GetExactSynonyms("rug", WordNetAccess.PartOfSpeech.Noun).ToArray()));

            // Test 5: Pluralize nouns and conjugate verbs
            Nouns nouns = new Nouns(plugenv);
            Console.WriteLine("person becomes " + nouns.Pluralize("person"));
            Verbs verbs = new Verbs(plugenv);
            Console.WriteLine("goes becomes " + verbs.ComposePast("goes"));
        }
Пример #2
0
        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);
        }
Пример #3
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");
            }
        }