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