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")); }
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; }