Beispiel #1
0
        public override Phrase Parapharse(Verbs verbs, Nouns nouns, WordNetAccess wordnet, GrammarParser.ParaphraseOptions options, List <Phrase> emphasizes, ref double prob)
        {
            POSPhrase phrase = (POSPhrase)MemberwiseClone();

            if ((options & GrammarParser.ParaphraseOptions.MoveToStart) != GrammarParser.ParaphraseOptions.NoOptions)
            {
                phrase.word = nouns.StartCap(phrase.word);
            }
            else if ((options & GrammarParser.ParaphraseOptions.MoveOffStart) != GrammarParser.ParaphraseOptions.NoOptions)
            {
                phrase.word = nouns.UnStartCap(phrase.word);
            }

            return(phrase);
        }
 // The initial operation on the sentence is to transform tagged tokens to phrases.
 public void Populate(IEnumerable <KeyValuePair <string, string> > tokens)
 {
     foreach (KeyValuePair <string, string> token in tokens)
     {
         POSPhrase phrase = GetPOSPhrase(token.Key, token.Value);
         if (phrase == null)
         {
             // unknown!
             //Unilog.Notice(this, "Could not find part for {0}/{1}", token.Key, token.Value);
             phrases.Add(new UnknownPart(token.Key));
             continue;
         }
         phrases.Add(phrase);
     }
 }
Beispiel #3
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);
        }