ABB.Swum.UnigramTagger.TagNounPhrase C# (CSharp) Method

TagNounPhrase() public method

Assigns part-of-speech tags to the word nodes in the given phrase, assuming it is a noun phrase. Only the words between startIndex and stopIndex, inclusive, are tagged.
startIndex or stopIndex are not valid indices, or stopIndex is less than startIndex
public TagNounPhrase ( PhraseNode phrase, int startIndex, int stopIndex ) : void
phrase ABB.Swum.Nodes.PhraseNode The noun phrase to tag.
startIndex int The index of the first word to tag.
stopIndex int The index of the last word to tag.
return void
        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--;
            }
        }

Same methods

UnigramTagger::TagNounPhrase ( PhraseNode phrase ) : void