add_recipient() public method

public add_recipient ( Phrase recipient, double weight ) : void
recipient Phrase
weight double
return void
Ejemplo n.º 1
0
        public PhraseGraph(JudgeOfRelevancy JoR_, String text, String q, HashSet <String> q_content_words)
        {
            JoR                 = JoR_;
            phrases             = new SortedDictionary <String, Phrase>();
            query               = q;
            query_content_words = q_content_words;

            String[] sentences     = get_sentences(text.ToLower());
            Phrase   last_sentence = null;

            foreach (var sentence in sentences)
            {
                Phrase sentence_phrase = ensure_phrase(sentence);
                // link neighboring sentences
                if (last_sentence != null)
                {
                    // 0.5 < 0.6 so weight will drift back
                    // earlier sentences are better
                    last_sentence.add_recipient(sentence_phrase, 0.5);
                    sentence_phrase.add_recipient(last_sentence, 0.6);
                }
                String[] words = get_words(sentence);
                // link sentences with their words
                foreach (var word in words)
                {
                    if (word == "")
                    {
                        continue;
                    }
                    Phrase word_phrase = ensure_phrase(word);
                    // weight flows from long sentences to words, to short sentences
                    word_phrase.add_recipient(sentence_phrase, 1.0);
                    sentence_phrase.add_recipient(word_phrase, 1.0);
                }
                last_sentence = sentence_phrase;
            }

            // link synonyms
            //foreach (var word in phrases.Keys)
            //{
            //    // don't include sentences
            //    if (word.Split().Count() >= 2) { continue; }
            //    HashSet<String> syns = JoR.get_synonyms(word);
            //    foreach (String synonym in syns)
            //    {
            //        // TODO: fix this :D can't modify the phrases collection while we're enumerating phrases.Keys!
            //        Phrase word_phrase = ensure_phrase(word);
            //        Phrase syn_phrase = ensure_phrase(synonym);
            //        syn_phrase.add_recipient(word_phrase, 1.0 * syns.Count());
            //        word_phrase.add_recipient(syn_phrase, 1.0 * syns.Count());
            //    }
            //}
        }
Ejemplo n.º 2
0
        public PhraseGraph(JudgeOfRelevancy JoR_, String text, String q, HashSet <String> q_content_words)
        {
            JoR                 = JoR_;
            phrases             = new SortedDictionary <String, Phrase>();
            query               = q;
            query_content_words = q_content_words;

            List <Tuple <String, List <String> > > sentence_words = TextCleaner.get_sentence_words(text);
            Phrase last_sentence = null;

            foreach (Tuple <String, List <String> > sentence_and_words in sentence_words)
            {
                String        sentence = sentence_and_words.Item1;
                List <String> words    = sentence_and_words.Item2;

                Phrase sentence_phrase = ensure_phrase(sentence);
                if (last_sentence != null)                             // Link neighbor sentences
                {
                    last_sentence.add_recipient(sentence_phrase, 0.5); // 0.5 < 0.6, so weight will drift back:
                    sentence_phrase.add_recipient(last_sentence, 0.6); // so earlier sentences better
                }

                foreach (var word in words) // Link sentences with their words
                {
                    if (word == "")
                    {
                        continue;
                    }
                    Phrase word_phrase = ensure_phrase(word);
                    word_phrase.add_recipient(sentence_phrase, 10.0 / words.Count()); // weight flows from long sentences
                    sentence_phrase.add_recipient(word_phrase, 1.0);                  // to words, to short sentences
                }

                last_sentence = sentence_phrase;
            }

            foreach (String word in phrases.Keys) // Link synonyms
            {
                if (word.Split().Count() >= 2)
                {
                    continue;
                }                                            // don't include sentences
                HashSet <String> syns = JoR.get_synonyms(word);
                foreach (String synonym in syns)
                {
                    Phrase word_phrase = ensure_phrase(word);
                    Phrase syn_phrase  = ensure_phrase(synonym);
                    syn_phrase.add_recipient(word_phrase, 1.0 * syns.Count());
                    word_phrase.add_recipient(syn_phrase, 1.0 * syns.Count());
                }
            }
        }