Represents a phrase, consisting of one or more words.
Inheritance: Node
コード例 #1
0
 /// <summary>
 /// Parses the node's Name into words.
 /// </summary>
 /// <param name="splitter"></param>
 public virtual void Parse(IdSplitter splitter)
 {
     if (ParsedName == null)
     {
         ParsedName = new PhraseNode(Name, splitter);
     }
 }
コード例 #2
0
 /// <summary>
 /// Concatenates the supplied phrase to the end of the current phrase.
 /// </summary>
 /// <param name="phrase">The phrase to add.</param>
 public void Add(PhraseNode phrase)
 {
     if (phrase != null)
     {
         Words.AddRange(phrase.GetPhrase());
     }
 }
コード例 #3
0
 /// <summary>
 /// Concatenates the given phrases and assigns the result to Theme.
 /// ** Note that this will potentially modify phrase1. **
 /// </summary>
 /// <param name="phrase1">The first phrase.</param>
 /// <param name="phrase2">The second phrase.</param>
 public void CreateThemeFromPhrases(PhraseNode phrase1, PhraseNode phrase2)
 {
     if (phrase1 != null && !phrase1.IsEmpty())
     {
         phrase1.Add(phrase2);
         this.Theme = phrase1;
     }
     else
     {
         this.Theme = phrase2;
     }
 }
コード例 #4
0
        /// <summary>
        /// Creates a PhraseNode by parsing the given string representation.
        /// </summary>
        /// <param name="source">The string to parse the PhraseNode from.</param>
        /// <returns>A new PhraseNode.</returns>
        public static PhraseNode Parse(string source)
        {
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }

            var words = source.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var pn    = new PhraseNode();

            foreach (var word in words)
            {
                pn.Words.Add(WordNode.Parse(word));
            }
            return(pn);
        }
コード例 #5
0
        public bool PhraseNodesAreEqual(PhraseNode pn1, PhraseNode pn2)
        {
            if(pn1 == pn2) {
                return true;
            }
            if(pn1 == null ^ pn2 == null) {
                return false;
            }

            if(pn1.Size() != pn2.Size()) {
                return false;
            }
            for(int i = 0; i < pn1.Size(); i++) {
                if(!WordNodesAreEqual(pn1[i], pn2[i])) {
                    return false;
                }
            }
            return true;
        }
コード例 #6
0
ファイル: PhraseNode.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Concatenates the supplied phrase to the end of the current phrase.
 /// </summary>
 /// <param name="phrase">The phrase to add.</param>
 public void Add(PhraseNode phrase) {
     if(phrase != null) {
         Words.AddRange(phrase.GetPhrase());
     }
 }
コード例 #7
0
ファイル: Tagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Assigns part-of-speech tags to the word nodes in the given type name.
 /// </summary>
 /// <param name="parsedName">The parsed type name to tag.</param>
 public abstract void TagType(PhraseNode parsedName);
コード例 #8
0
ファイル: UnigramTagger.cs プロジェクト: abb-iss/Swum.NET
        /// <summary>
        /// Tags any word nodes in the given phrase that contain digits.
        /// </summary>
        /// <param name="phrase">The phrase to tag.</param>
        public void TagDigits(PhraseNode phrase)
        {
            if (phrase == null) { return; }

            foreach (var word in phrase.GetPhrase())
            {
                if(Regex.IsMatch(word.Text, @"\d+"))
                {
                    word.Tag = PartOfSpeechTag.Digit;
                }
            }
        }
コード例 #9
0
 /// <summary>
 /// Creates a new ProgramElementNode and sets Name and ParsedName to the supplied values.
 /// </summary>
 /// <param name="name">The name of the program element.</param>
 /// <param name="parsedName">A PhraseNode constructed from the program element's name.</param>
 public ProgramElementNode(string name, PhraseNode parsedName)
 {
     this.Name       = name;
     this.ParsedName = parsedName;
 }
コード例 #10
0
ファイル: UnigramMethodRule.cs プロジェクト: abb-iss/Swum.NET
        /// <summary>
        /// Determines whether the given PhraseNode overlaps with the given word.
        /// The two overlap if the last word of the phrase is the same as the given word, 
        /// or if the second-to-last word of the phrase is the same as the given word and the last word of the phrase is ignorable.
        /// </summary>
        /// <param name="name">The phrase to check for overlap.</param>
        /// <param name="word">The word to check for overlap with.</param>
        /// <returns>True if the phrase and word overlap, False otherwise.</returns>
        private bool HasOverlap(PhraseNode name, string word)
        {
            if (name == null || name.Size() == 0 || string.IsNullOrEmpty(word)) { return false; }

            bool hasOverlap = false;
            if (string.Equals(name.LastWord().Text, word, StringComparison.InvariantCultureIgnoreCase))
            {
                //last word of name is same as given word
                hasOverlap = true;
            }
            else if (name.Size() > 1)
            {
                if (string.Equals(name[name.Size() - 2].Text, word, StringComparison.InvariantCultureIgnoreCase) 
                    && PosData.IsIgnorableHeadWord(name.LastWord().Text))
                {
                    //second-to-last word of name is same as given word, and the last word of name is ignorable
                    hasOverlap = true;
                }
            }

            return hasOverlap;
        }
コード例 #11
0
ファイル: UnigramMethodRule.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Returns a PhraseNode containing the noun phrase words from the given name.
 /// All noun phrase words prior to the first preposition are included.
 /// </summary>
 /// <param name="parsedName">The PhraseNode to get the noun phrase from.</param>
 private PhraseNode GetNounPhrase(PhraseNode parsedName)
 {
     return GetNounPhrase(parsedName, 0);
 }
コード例 #12
0
ファイル: UnigramMethodRule.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Finds the index of the first preposition within the given PhraseNode, starting from the word indicated by startIndex.
 /// </summary>
 /// <param name="parsedName">The PhraseNode to search.</param>
 /// <param name="startIndex">The index of the word to start searching for prepositions from.</param>
 /// <returns>The index of the first preposition in the PhraseNode after startIndex, inclusively.</returns>
 private int FindFirstPreposition(PhraseNode parsedName, int startIndex)
 {
     for (int i = startIndex; i < parsedName.Size(); i++)
     {
         if (parsedName[i].Tag == PartOfSpeechTag.Preposition) { return i; }
     }
     return -1;
 }
コード例 #13
0
ファイル: NullTagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Does nothing; simply returns
 /// </summary>
 /// <param name="nounPhrase"></param>
 /// <param name="startIndex"></param>
 /// <param name="stopIndex"></param>
 public override void TagNounPhrase(PhraseNode nounPhrase, int startIndex, int stopIndex)
 {
     return;
 }
コード例 #14
0
ファイル: NullTagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Does nothing; simply returns
 /// </summary>
 /// <param name="nounPhrase"></param>
 public override void TagNounPhrase(PhraseNode nounPhrase)
 {
     return;
 }
コード例 #15
0
ファイル: NullTagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Does nothing; simply returns
 /// </summary>
 /// <param name="parsedName"></param>
 public override void TagType(PhraseNode parsedName)
 {
     return;
 }
コード例 #16
0
ファイル: NullTagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Does nothing; simply returns
 /// </summary>
 /// <param name="parsedName"></param>
 public override void TagVariableName(PhraseNode parsedName)
 {
     return;
 }
コード例 #17
0
ファイル: TypeNode.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Creates a new TypeNode.
 /// </summary>
 /// <param name="name">The name of the type.</param>
 /// <param name="isPrimitive">Whether the type is a primitive data type.</param>
 /// <param name="parsedName">A PhraseNode representing the parsed type name.</param>
 public TypeNode(string name, bool isPrimitive, PhraseNode parsedName)
     : base(name, parsedName) {
     this.IsPrimitive = isPrimitive;
 }
コード例 #18
0
ファイル: Tagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Assigns part-of-speech tags to the word nodes in the given phrase, assuming it is a noun phrase.
 /// </summary>
 /// <param name="nounPhrase">The noun phrase to tag.</param>
 public abstract void TagNounPhrase(PhraseNode nounPhrase);
コード例 #19
0
 /// <summary>
 /// Concatenates the given phrases and assigns the result to Theme.
 /// ** Note that this will potentially modify phrase1. **
 /// </summary>
 /// <param name="phrase1">The first phrase.</param>
 /// <param name="phrase2">The second phrase.</param>
 public void CreateThemeFromPhrases(PhraseNode phrase1, PhraseNode phrase2) {
     if(phrase1 != null && !phrase1.IsEmpty()) {
         phrase1.Add(phrase2);
         this.Theme = phrase1;
     } else {
         this.Theme = phrase2;
     }
 }
コード例 #20
0
ファイル: UnigramMethodRule.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Determines whether the specified word in the given phrase is an ignorable verb. If so, it tags it appropriately.
 /// </summary>
 /// <param name="parsedName">The PhraseNode containing the word to check.</param>
 /// <param name="wordIndex">The index of the desired word within the PhraseNode.</param>
 /// <returns>wordIndex+1 if the word was an ignorable verb; wordIndex if it was not.</returns>
 private int CheckForIgnorableVerb(PhraseNode parsedName, int wordIndex)
 {
     if (wordIndex < parsedName.Size() - 1 //make sure last word in name is verb
         && (PosData.IsIgnorableVerb(parsedName[wordIndex].Text)
             && (PositionalFrequencies.GetVerbProbability(parsedName[wordIndex + 1].Text) > PositionalFrequencies.GetNounProbability(parsedName[wordIndex + 1].Text))
             || PosData.IsModalVerb(parsedName[wordIndex].Text))
         )
     {
         parsedName[wordIndex].Tag = PartOfSpeechTag.VerbIgnorable;
         wordIndex++;
     }
     return wordIndex;
 }        
コード例 #21
0
ファイル: BaseVerbRule.cs プロジェクト: abb-iss/Swum.NET
 private bool IsPrepositionalPhrase(PhraseNode parsedName)
 {
     foreach (WordNode word in parsedName.GetPhrase())
     {
         if (word.Tag == PartOfSpeechTag.Preposition) { return true; }
     }
     return false;
 }
コード例 #22
0
ファイル: UnigramMethodRule.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Finds all the verbs in the given name and adds them to the given preamble.
 /// </summary>
 /// <param name="parsedName">The PhraseNode to gets the verbs from.</param>
 /// <param name="preamble">The preamble PhraseNode to add the verbs to.</param>
 /// <returns>The preamble PhraseNode with the verbs added.</returns>
 private PhraseNode GetVerbPhrase(PhraseNode parsedName, PhraseNode preamble)
 {
     //TODO: should this make a copy of the preamble first?
     PhraseNode phrase = preamble;
     foreach (WordNode word in parsedName.GetPhrase())
     {
         if (word.Tag == PartOfSpeechTag.Verb
             || word.Tag == PartOfSpeechTag.VerbModifier
             || word.Tag == PartOfSpeechTag.VerbParticle
             || word.Tag == PartOfSpeechTag.NonVerb
             || word.Tag == PartOfSpeechTag.VerbIgnorable)
         {
             phrase.Add(word);
         }
     }
     return phrase;
 }
コード例 #23
0
ファイル: UnigramTagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Assigns part-of-speech tags to the word nodes in the given variable name.
 /// </summary>
 /// <param name="parsedName">The parsed variable name to tag.</param>
 public override void TagVariableName(PhraseNode parsedName)
 {
     TagNounPhrase(parsedName);
 }
コード例 #24
0
ファイル: UnigramMethodRule.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Returns a PhraseNode containing the noun phrase words from the given name, starting from startIndex.
 /// All noun phrase words prior to the first encountered preposition are included.
 /// </summary>
 /// <param name="parsedName">The PhraseNode to get the noun phrase from.</param>
 /// <param name="startIndex">The index of the word to start from.</param>
 private PhraseNode GetNounPhrase(PhraseNode parsedName, int startIndex)
 {
     PhraseNode phrase = parsedName.GetNewEmpty();
     for (int i = startIndex; i < parsedName.Size(); i++)
     {
         PartOfSpeechTag tag = parsedName[i].Tag;
         if (tag == PartOfSpeechTag.Noun
             || tag == PartOfSpeechTag.NounModifier
             || tag == PartOfSpeechTag.Determiner
             || tag == PartOfSpeechTag.Pronoun
             || tag == PartOfSpeechTag.NounIgnorable
             || tag == PartOfSpeechTag.Digit
             || tag == PartOfSpeechTag.Preamble)
         {
             phrase.Add(parsedName[i]);
         }
         else if (tag == PartOfSpeechTag.Preposition)
         {
             break;
         }
     }
     return phrase;
 }
コード例 #25
0
ファイル: UnigramTagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Assigns part-of-speech tags to the word nodes in the given phrase, assuming it is a noun phrase.
 /// </summary>
 /// <param name="phrase">The noun phrase to tag.</param>
 public override void TagNounPhrase(PhraseNode phrase)
 {
     TagNounPhrase(phrase, 0, phrase.Size() - 1);
 }
コード例 #26
0
ファイル: UnigramMethodRule.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Determines whether the given phrase indicates an event handler method.
 /// </summary>
 /// <param name="parsedName">The PhraseNode to test.</param>
 /// <returns>True if the phrase indicates an event handler method, False otherwise.</returns>
 protected bool IsEventHandler(PhraseNode parsedName)
 {
     if (parsedName == null || parsedName.Size() == 0)
     {
         return false;
     }
     else
     {
         return IsNonBaseVerb(parsedName.LastWord().Text)
             && parsedName[0].Text.ToLower() != "get"
             && parsedName[0].Text.ToLower() != "set";
     }
 }
コード例 #27
0
ファイル: Tagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// 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.
 /// </summary>
 /// <param name="nounPhrase">The noun phrase to tag.</param>
 /// <param name="startIndex">The index of the first word to tag.</param>
 /// <param name="stopIndex">The index of the last word to tag.</param>
 public abstract void TagNounPhrase(PhraseNode nounPhrase, int startIndex, int stopIndex);
コード例 #28
0
 /// <summary>
 /// Creates a new TypeNode.
 /// </summary>
 /// <param name="name">The name of the type.</param>
 /// <param name="isPrimitive">Whether the type is a primitive data type.</param>
 /// <param name="parsedName">A PhraseNode representing the parsed type name.</param>
 public TypeNode(string name, bool isPrimitive, PhraseNode parsedName)
     : base(name, parsedName)
 {
     this.IsPrimitive = isPrimitive;
 }
コード例 #29
0
 /// <summary>
 /// Creates a new ProgramElementNode and sets Name and ParsedName to the supplied values.
 /// </summary>
 /// <param name="name">The name of the program element.</param>
 /// <param name="parsedName">A PhraseNode constructed from the program element's name.</param>
 public ProgramElementNode(string name, PhraseNode parsedName) {
     this.Name = name;
     this.ParsedName = parsedName;
 }
コード例 #30
0
ファイル: UnigramTagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Assigns part-of-speech tags to the word nodes in the given type name.
 /// </summary>
 /// <param name="parsedName">The parsed type name to tag.</param>
 public override void TagType(PhraseNode parsedName)
 {
     TagNounPhrase(parsedName);
 }
コード例 #31
0
 /// <summary>
 /// Parses the node's Name into words.
 /// </summary>
 /// <param name="splitter"></param>
 public virtual void Parse(IdSplitter splitter) {
     if(ParsedName == null)
         ParsedName = new PhraseNode(Name, splitter);
 }
コード例 #32
0
ファイル: UnigramTagger.cs プロジェクト: abb-iss/Swum.NET
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="phrase">The noun phrase to tag.</param>
        /// <param name="startIndex">The index of the first word to tag.</param>
        /// <param name="stopIndex">The index of the last word to tag.</param>
        /// <exception cref="System.ArgumentOutOfRangeException">startIndex or stopIndex are not valid indices, or stopIndex is less than startIndex</exception>
        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--;
            }
        }
コード例 #33
0
ファイル: PhraseNode.cs プロジェクト: abb-iss/Swum.NET
        /// <summary>
        /// Creates a PhraseNode by parsing the given string representation.
        /// </summary>
        /// <param name="source">The string to parse the PhraseNode from.</param>
        /// <returns>A new PhraseNode.</returns>
        public static PhraseNode Parse(string source) {
            if(source == null) {
                throw new ArgumentNullException("source");
            }

            var words = source.Split(new[] {' '}, StringSplitOptions.RemoveEmptyEntries);
            var pn = new PhraseNode();
            foreach(var word in words) {
                pn.Words.Add(WordNode.Parse(word));
            }
            return pn;
        }
コード例 #34
0
ファイル: UnigramTagger.cs プロジェクト: abb-iss/Swum.NET
        /// <summary>
        /// Tags any word nodes in the given phrase that are prepositions.
        /// </summary>
        /// <param name="phrase">The phrase to tag.</param>
        public void TagPrepostions(PhraseNode phrase)
        {
            if (phrase == null) { return; }

            foreach (var word in phrase.GetPhrase())
            {
                if (pos.IsPreposition(word.Text))
                {
                    word.Tag = PartOfSpeechTag.Preposition;
                }
            }
        }
コード例 #35
0
ファイル: Tagger.cs プロジェクト: abb-iss/Swum.NET
 /// <summary>
 /// Assigns part-of-speech tags to the word nodes in the given variable name.
 /// </summary>
 /// <param name="parsedName">The parsed variable name to tag.</param>
 public abstract void TagVariableName(PhraseNode parsedName);