public string Summarize(string input, int numberOfSentences)
{
// get the frequency of each word in the input
Hashtable wordFrequencies = Utilities.GetWordFrequency(input);
// now create a set of the X most frequent words
ArrayList mostFrequentWords = GetMostFrequentWords(100, wordFrequencies);
// break the input up into sentences
string[] workingSentences = Utilities.GetSentences(input.ToLower());
string[] actualSentences = Utilities.GetSentences(input);
// iterate over the most frequent words, and add the first sentence
// that includes each word to the result.
ArrayList outputSentences = new ArrayList();
foreach (string word in mostFrequentWords)
{
for (int i = 0; i < workingSentences.Length; i++)
{
if (workingSentences[i].IndexOf(word) >= 0)
{
outputSentences.Add(actualSentences[i]);
break;
}
if (outputSentences.Count >= numberOfSentences)
break;
}
if (outputSentences.Count >= numberOfSentences)
break;
}
ArrayList reorderedOutputSentences = ReorderSentences(outputSentences, input);
StringBuilder result = new StringBuilder();
foreach (string sentence in reorderedOutputSentences)
{
if (result.Length > 0)
result.Append(" ");
result.Append(sentence);
result.Append("."); // this isn't correct - it should be whatever symbol the sentence finished with
}
return result.ToString();
}