public override void TagNounPhrase(PhraseNode phrase, int startIndex, int stopIndex)
{
if (phrase == null || phrase.Size() <= 0) { return; }
if (startIndex < 0 || startIndex >= phrase.Size())
{
throw new ArgumentOutOfRangeException("startIndex", startIndex, string.Format("The given value is not a valid index of the PhraseNode. It must be between 0 and {0}.", phrase.Size() - 1));
}
if (stopIndex < startIndex || stopIndex >= phrase.Size())
{
throw new ArgumentOutOfRangeException("stopIndex", stopIndex, string.Format("The given value must be a valid index of the PhraseNode, and must be larger than the given startIndex value of {0}", startIndex));
}
//start from the end of the phrase
int currentWord = stopIndex;
//skip any digits at the end
while (phrase[currentWord].Tag == PartOfSpeechTag.Digit) { currentWord--; }
//tag the last word
if (currentWord >= startIndex)
{
if (pos.IsDeterminer(phrase[currentWord].Text))
{
phrase[currentWord].Tag = PartOfSpeechTag.Determiner;
}
else if (pos.IsPronoun(phrase[currentWord].Text))
{
phrase[currentWord].Tag = PartOfSpeechTag.Pronoun;
}
else if (pos.IsIgnorableHeadWord(phrase[currentWord].Text))
{
phrase[currentWord].Tag = PartOfSpeechTag.NounIgnorable;
}
else
{
phrase[currentWord].Tag = PartOfSpeechTag.Noun;
}
currentWord--;
}
//tag the rest of the words
while (currentWord >= startIndex)
{
if (pos.IsDeterminer(phrase[currentWord].Text))
{
phrase[currentWord].Tag = PartOfSpeechTag.Determiner;
}
else if (pos.IsPronoun(phrase[currentWord].Text))
{
phrase[currentWord].Tag = PartOfSpeechTag.Pronoun;
}
else if (phrase[currentWord].Tag != PartOfSpeechTag.Digit)
{
phrase[currentWord].Tag = PartOfSpeechTag.NounModifier;
}
currentWord--;
}
}