Esempio n. 1
0
        public static void Main(string[] args)
        {
            PluginEnvironment plugenv  = new PluginEnvironment(new MainClass());
            string            plugbase = "/Users/jrising/projects/virsona/github";

            plugenv.Initialize(plugbase + "/config.xml", 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 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"));
            Console.WriteLine("eats becomes " + verbs.ComposePrespart(verbs.InputToBase("eats")));

            // Test 3: Paraphrasing
            Random randgen = new Random();

            try {
                IParsedPhrase after = parser.Paraphrase(before, null, null, randgen.NextDouble());
                Console.WriteLine(after.Text);
            } catch (Exception ex) {
                Console.WriteLine("Error: " + ex.Message);
            }

            // Test 4: Look up some indices
            WordNetAccess wordnet  = new WordNetAccess(plugenv);
            List <string> synonyms = null;

            try {
                synonyms = wordnet.GetExactSynonyms("rug", WordNetAccess.PartOfSpeech.Noun);
            } catch (Exception ex) {
                Console.WriteLine("Error: " + ex.Message);
            }
            if (synonyms == null)
            {
                Console.WriteLine("Could not find a synonym for 'rug'.  Is Memcached installed?");
            }
            else
            {
                Console.WriteLine("Synonyms: " + string.Join(", ", synonyms.ToArray()));
            }
        }
        public override void Propogate(Context env, object matched, double strength)
        {
            base.Propogate(env, matched, strength);

            if (strength > .5 && matched is IParsedPhrase)
            {
                ((Variable)env.Lookup("%verb")).Propogate(env, new WordPhrase(verbs.InputToBase(((IParsedPhrase)matched).Text), "VB"), .5 * strength);
            }
        }
Esempio n. 3
0
 public static Concept ConceptNetGetConcept(Memory memory, Verbs verbs, Notion notion, Concept.Kind kind)
 {
     if (kind == Concept.Kind.Event)
     {
         return(memory.NewConcept(verbs.InputToBase(notion.Canonical), kind));
     }
     else
     {
         return(memory.NewConcept(notion.Canonical, kind));
     }
 }
        public object Decline(object value)
        {
            if (value is IParsedPhrase)
            {
                IParsedPhrase phrase = (IParsedPhrase)value;

                string inflected = verbs.InflectVerb(verbs.InputToBase(phrase.Text), inflection);
                return(new WordPhrase(inflected, pos));
            }

            return(value);
        }
Esempio n. 5
0
        public VerbChoiceVariable(string name, List <string> options, PluginEnvironment plugenv, WordComparer comparer)
            : base(name, 100.0, new POSTagger(plugenv), new GrammarParser(plugenv))
        {
            this.options  = options;
            this.verbs    = new Verbs(plugenv);
            this.comparer = comparer;

            this.bases = new List <string>();
            foreach (string option in options)
            {
                bases.Add(verbs.InputToBase(option));
            }
        }
        public override void Propogate(Context env, object matched, double strength)
        {
            base.Propogate(env, matched, strength);

            if (matched is IParsedPhrase)
            {
                IParsedPhrase matchphr = (IParsedPhrase)matched;
                ((Variable)env.Lookup("%verbx")).Propogate(env, new WordPhrase(verbs.InputToBase(matchphr.Text), "VB"), .5 * strength);
                ((Variable)env.Lookup("%verben")).Propogate(env, new WordPhrase(verbs.ComposePastpart(matchphr.Text), "VBN"), .5 * strength);
                ((Variable)env.Lookup("%verbing")).Propogate(env, new WordPhrase(verbs.ComposePrespart(matchphr.Text), "VBG"), .5 * strength);
                ((Variable)env.Lookup("%verbed")).Propogate(env, new WordPhrase(verbs.ComposePast(matchphr.Text), "VBD"), .5 * strength);
                ((Variable)env.Lookup("%verbs")).Propogate(env, new WordPhrase(verbs.ComposePresent(matchphr.Text), "VBZ"), .5 * strength);
            }
        }
Esempio n. 7
0
        public static string ConjugateToTense(Memory memory, string verb, Verbs.Person person, Concept right, Verbs verbs)
        {
            if (right == memory.past)
            {
                return(verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Ved));
            }
            if (right == memory.now)
            {
                return(verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Vs));
            }
            if (right == memory.future)
            {
                return("will " + verbs.ComposePersonable(verb, person, Verbs.Convert.ext_V));
            }

            List <string> parts    = StringUtilities.SplitWords(right.Name, true);
            bool          usedverb = false;

            for (int ii = 0; ii < parts.Count; ii++)
            {
                if (parts[ii] == "en")
                {
                    parts[ii] = verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Ven);
                    usedverb  = true;
                }
                else if (parts[ii] == "ing")
                {
                    parts[ii] = verbs.ComposePersonable(verb, person, Verbs.Convert.ext_Ving);
                    usedverb  = true;
                }
            }
            if (!usedverb)
            {
                parts.Add(verbs.InputToBase(verb));
            }
            return(StringUtilities.JoinWords(parts));
        }
Esempio n. 8
0
        public override bool?IsMatch(IParsedPhrase check)
        {
            string verb;

            if (check.IsLeaf || !check.Text.Contains(" "))
            {
                verb = check.Text;

                if (Verbs.IsToHave(verb))
                {
                    if (bases.Contains("have"))
                    {
                        return(true);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (Verbs.IsToBe(verb))
                {
                    if (bases.Contains("be"))
                    {
                        return(true);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (Verbs.IsToDo(verb))
                {
                    if (bases.Contains("do"))
                    {
                        return(true);
                    }
                    else
                    {
                        return(null);
                    }
                }
                if (verb == "will" || verb == "shall")
                {
                    return(null);                    // not sure yet
                }
            }
            else
            {
                GroupPhrase groupPhrase = new GroupPhrase(check);
                if (groupPhrase.Count > 2)
                {
                    return(false);
                }

                string helper = groupPhrase.GetBranch(0).Text.ToLower();
                verb = groupPhrase.GetBranch(1).Text.ToLower();

                if (!Verbs.IsToHave(helper) && !Verbs.IsToBe(helper) && !Verbs.IsToDo(helper) &&
                    helper != "will" && helper != "shall")
                {
                    return(false);
                }
            }

            string baseverb = verbs.InputToBase(verb);

            return(comparer.MatchAny(verb, options) || comparer.MatchAny(verb, bases) ||
                   comparer.MatchAny(baseverb, bases));
        }