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()));
            }
        }
Exemple #2
0
        public Phrase SynonymParaphrase(WordNetAccess.PartOfSpeech part, Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List <Phrase> emphasizes, ref double prob)
        {
            if (word == "not" || word == "non")
            {
                return(null);    // we don't replace these!
            }
            // Can we use a synonym?
            List <string> synonyms = wordnet.GetExactSynonyms(word, part);

            if (synonyms != null)
            {
                synonyms.Remove(word);
                synonyms.Remove(word.ToLower());
                // remove any synonyms more than twice as long, or half as long as the original
                List <string> onlygoods = new List <string>();
                foreach (string synonym in synonyms)
                {
                    if (synonym.Length <= 2 * word.Length && synonym.Length >= word.Length / 2)
                    {
                        onlygoods.Add(synonym);
                    }
                }
                synonyms = onlygoods;

                if (synonyms.Count > 0 && RemoveUnemphasizedImprobability(.75, emphasizes, this, ref prob))
                {
                    string newword = synonyms[ImprobabilityToInt(synonyms.Count, ref prob)];
                    if (IsStart(options))
                    {
                        newword = nouns.StartCap(newword);
                    }

                    POSPhrase clone = (POSPhrase)MemberwiseClone();
                    clone.word = newword;

                    return(clone);
                }
            }

            return(null);
        }
        public void Run(string configpath)
        {
            PluginEnvironment plugenv = new PluginEnvironment(this);

            plugenv.Initialize(configpath, null);
            Console.WriteLine(plugenv.GetConfigDirectory("datadirectory"));

            Console.WriteLine("Welcome to the Virsona Commander!");
            bool running = true;

            while (running)
            {
                Console.Write("(: ");
                string   command = Console.ReadLine();
                string[] argv    = Regex.Split(command, "\\s+");

                switch (argv[0])
                {
                case "hepple":
                {
                    string sentence = string.Join(" ", new ArraySegment <string> (argv, 1, argv.Length - 1));
                    object result   = plugenv.ImmediateConvertTo(sentence,
                                                                 LanguageNet.Grammarian.POSTagger.TagEnumerationResultType, 1, 1000);
                    if (result is Exception)
                    {
                        Console.WriteLine(((Exception)result).Message);
                        Console.WriteLine(((Exception)result).StackTrace);
                        continue;
                    }
                    Console.WriteLine(result);
                    string output = string.Join(" ", (IEnumerable <string>)result);
                    Console.WriteLine(output);
                    break;
                }

                case "synonyms":
                {
                    if (wordnet == null)
                    {
                        wordnet = new WordNetAccess(plugenv);
                    }
                    List <string> synonyms = wordnet.GetExactSynonyms(argv [1], WordNetAccess.PartOfSpeech.All);
                    if (synonyms.Count == 0)
                    {
                        Console.WriteLine("None.");
                    }
                    else
                    {
                        string output = string.Join(" ", synonyms);
                        Console.WriteLine(output);
                    }
                    break;
                }

                case "quit":
                    Console.WriteLine("Goodbye!");
                    running = false;
                    break;

                default:
                    Console.WriteLine("Unknown command: " + argv [0]);
                    break;
                }
            }
        }