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