Represents an abstract program element.
Inheritance: Node
Esempio n. 1
0
 /// <summary>
 /// Constructs the SWUM for the given node, using this rule.
 /// </summary>
 /// <param name="node">The node to construct SWUM for.</param>
 public override void ConstructSwum(ProgramElementNode node)
 {
     if (node is MethodDeclarationNode)
     {
         ((MethodDeclarationNode)node).Parse(this.Splitter);
         this.PosTagger.PreTag(node);
         base.ConstructSwum(node);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Constructs the SWUM for the given node, using this rule.
 /// </summary>
 /// <param name="node">The node to construct SWUM for.</param>
 public override void ConstructSwum(ProgramElementNode node)
 {
     if (node is MethodDeclarationNode)
     {
         var mdn = (MethodDeclarationNode)node;
         mdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
         ParseReactiveName(mdn);
         //set action, theme, arguments?
         mdn.SwumRuleUsed = this;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Constructs the SWUM for the given node, using this rule.
        /// </summary>
        /// <param name="node">The node to construct SWUM for.</param>
        public override void ConstructSwum(ProgramElementNode node)
        {
            if (node is MethodDeclarationNode)
            {
                var mdn = (MethodDeclarationNode)node;

                mdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
                ParseBaseVerbName(mdn);
                SetDefaultActionAndTheme(mdn);
                mdn.SwumRuleUsed = this;
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Constructs the SWUM for the given node, using this rule.
 /// </summary>
 /// <param name="node">The node to construct SWUM for.</param>
 public override void ConstructSwum(ProgramElementNode node)
 {
     if (node is MethodDeclarationNode)
     {
         MethodDeclarationNode mdn = (MethodDeclarationNode)node;
         //don't need to parse or tag, because there's no name
         //fill in SWUM
         mdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
         mdn.Theme = mdn.Preamble;
         //TODO: from Emily, how to fill in Action?
         mdn.SwumRuleUsed = this;
     }
 }
Esempio n. 5
0
        /// <summary>
        /// Applies the rules defined within this SwumBuilder to the specified node.
        /// The first matching rule found is used to construct the SWUM.
        /// </summary>
        /// <param name="node">The ProgramElementNode to construct a SWUM on.</param>
        /// <returns>The SwumRule that was used to construct the SWUM for the given node.</returns>
        public SwumRule ApplyRules(ProgramElementNode node)
        {
            if (Rules == null) { DefineRuleSet(); }

            foreach (SwumRule rule in this.Rules)
            {
                if (rule.InClass(node))
                {
                    rule.ConstructSwum(node);
                    return rule;
                }
            }
            return null;
        }
Esempio n. 6
0
        /// <summary>
        /// Constructs the SWUM for the given node, using this rule.
        /// </summary>
        /// <param name="node">The node to construct SWUM for.</param>
        public override void ConstructSwum(ProgramElementNode node)
        {
            if (node is MethodDeclarationNode)
            {
                var mdn = (MethodDeclarationNode)node;
                mdn.Action = mdn.ParsedName[0].GetNewWord("handle", PartOfSpeechTag.Verb);
                this.PosTagger.TagNounPhrase(mdn.ParsedName);
                mdn.CreateThemeFromPhrases(mdn.Preamble, mdn.ParsedName);

                SetDefaultUnknownArguments(mdn);
                mdn.IsReactive = true;

                mdn.SwumRuleUsed = this;
            }
        }
Esempio n. 7
0
 /// <summary>
 /// Constructs the Software Word Use Model on the given node, using this Rule.
 /// </summary>
 /// <param name="node">The node to construct the SWUM on.</param>
 public override void ConstructSwum(ProgramElementNode node)
 {
     if (node is FieldDeclarationNode)
     {
         FieldDeclarationNode fdn = node as FieldDeclarationNode;
         fdn.Parse(this.Splitter);
         this.PosTagger.TagNounPhrase(fdn.ParsedName);
         fdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
         //TODO: set fdn.Type.IsPrimitive
         fdn.SwumRuleUsed = this;
     }
     else
     {
         //TODO: return some sort of error indicator?
         Console.Error.WriteLine("FieldRule.ConstructSwum expected a FieldDeclarationNode, received a {0}", node.GetType());
     }
 }
Esempio n. 8
0
        /// <summary>
        /// Performs various actions that should occur prior to further tagging. 
        /// This method tags any digits in the name, identifies and removes any preamble, and tags any prepositions remaining in the name.
        /// </summary>
        /// <param name="node">The node to be tagged.</param>
        public override void PreTag(ProgramElementNode node)
        {
            if (node == null) { return; }

            TagDigits(node.ParsedName);

            if (node.Preamble == null)
            {
                int wordIndex = 0;
                bool checkForMorePreamble = true;
                //identify and tag any preamble words
                while (node.ParsedName.Size() > 1 && checkForMorePreamble)
                {
                    checkForMorePreamble = false;

                    //skip any digits
                    while (wordIndex < node.ParsedName.Size() && node.ParsedName[wordIndex].Tag == PartOfSpeechTag.Digit) { wordIndex++; }

                    //check if word is preamble
                    if (wordIndex < node.ParsedName.Size() - 1)
                    {
                        string word = node.ParsedName[wordIndex].Text;
                        if (word.Length == 1 ||
                            (word.Length == 2 && !pos.IsTwoLetterDictionaryWord(word)) ||
                            (word.Length < 5 && !Regex.IsMatch(word, ".*[gs]et.*") && !pos.IsPotentialVerb(word) &&
                             positionalFrequencies.GetOnlyFrequency(word) == 0 && positionalFrequencies.GetFirstFrequency(word) > 0))
                        {
                            node.ParsedName[wordIndex].Tag = PartOfSpeechTag.Preamble;
                            wordIndex++;
                            checkForMorePreamble = true;
                        }
                    }
                }

                //move preamble words from ParsedName to Preamble
                node.Preamble = node.ParsedName.GetNewEmpty();
                for (int j = 0; j < wordIndex; j++)
                {
                    node.Preamble.Add(node.ParsedName[0]);
                    node.ParsedName.RemoveWord(0);
                }
            }

            TagPrepostions(node.ParsedName);
        }
Esempio n. 9
0
        /// <summary>
        /// Constructs the SWUM for the given node, using this rule.
        /// </summary>
        /// <param name="node">The node to construct SWUM for.</param>
        public override void ConstructSwum(ProgramElementNode node)
        {
            if (node is MethodDeclarationNode)
            {
                var mdn = (MethodDeclarationNode)node;

                mdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
                if (mdn.ReturnType != null && mdn.ReturnType.Name.ToLower() == "void")
                {
                    ParseReactiveName(mdn); //this also sets the Action, Theme, and arguments
                }
                else
                {
                    this.PosTagger.TagNounPhrase(mdn.ParsedName);
                    mdn.CreateThemeFromPhrases(mdn.Preamble, mdn.ParsedName);
                    mdn.Action = mdn.ParsedName[0].GetNewWord("get", PartOfSpeechTag.Verb);
                    SetDefaultUnknownArguments(mdn);
                }
                mdn.SwumRuleUsed = this;
            }
        }
Esempio n. 10
0
 /// <summary>
 /// Constructs the SWUM for the given node, using this rule.
 /// </summary>
 /// <param name="node">The node to construct SWUM for.</param>
 public override void ConstructSwum(ProgramElementNode node)
 {
     if (node is MethodDeclarationNode)
     {
         var mdn = (MethodDeclarationNode)node;
         //Fill in SWUM
         mdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
         if (mdn.ParsedName.Size() == 1)
         {
             string firstWord = mdn.ParsedName[0].Text.ToLower();
             if (firstWord == "run" || firstWord == "main" || firstWord == "test")
             {
                 mdn.IsReactive = true;
                 //according to Emily, we don't want to parse it as reactive, just mark it that way
             }
         }
         ParseBaseVerbName(mdn);
         SetDefaultActionAndTheme(mdn);
         mdn.SwumRuleUsed = this;
     }
 }
Esempio n. 11
0
        /// <summary>
        /// Constructs the Software Word Use Model for the given node. 
        /// This method assumes that the node has already been tested to satisfy this Rule, using the InClass method.
        /// </summary>
        /// <param name="node">The node to construct SWUM for.</param>
        public override void ConstructSwum(ProgramElementNode node)
        {
            if (node is MethodDeclarationNode)
            {
                MethodDeclarationNode mdn = (MethodDeclarationNode)node;
                mdn.Parse(this.Splitter);
                this.PosTagger.TagNounPhrase(mdn.ParsedName);

                mdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
                mdn.Theme = mdn.ParsedName;
                mdn.AddUnknownArguments(mdn.FormalParameters);

                //TODO: from Emily, how to fill in Action?
                mdn.IsConstructor = true;
                mdn.SwumRuleUsed = this;
            }
            else
            {
                //TODO: return error?
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Constructs the SWUM for the given node, using this rule.
        /// </summary>
        /// <param name="node">The node to construct SWUM for.</param>
        public override void ConstructSwum(ProgramElementNode node)
        {
            if (node is MethodDeclarationNode)
            {
                var mdn = (MethodDeclarationNode)node;

                mdn.AssignStructuralInformation(this.Splitter, this.PosTagger);
                if (mdn.ParsedName[0].Tag != PartOfSpeechTag.Preposition)
                {
                    //this shouldn't be necessary, because prepositions should have been tagged in tagger.PreTag, which should have been called prior to this method
                    mdn.ParsedName[0].Tag = PartOfSpeechTag.Preposition;
                    Console.Error.WriteLine("LeadingPrepositionRule.ConstructSwum(): found node with untagged preposition: {0}", mdn);
                }
                if(mdn.ParsedName.Size() > 1) {
                    this.PosTagger.TagNounPhrase(mdn.ParsedName, 1, mdn.ParsedName.Size() - 1);
                }
                mdn.CreateThemeFromPhrases(mdn.Preamble, mdn.ParsedName);

                //TODO: from Emily, make name proper SecondaryArg

                string prep = mdn.ParsedName[0].Text.ToLower();
                if (prep == "to" || prep == "from")
                {
                    mdn.Action = mdn.ParsedName[0].GetNewWord("convert", PartOfSpeechTag.Verb);
                    SetDefaultUnknownArguments(mdn);
                }
                else if (prep == "on" || prep == "before" || prep == "after") //EventHandlerRule should be run first
                {
                    ParseReactiveName(mdn);
                }
                else
                {
                    SetDefaultUnknownArguments(mdn);
                }

                mdn.SwumRuleUsed = this;
            }
        }
Esempio n. 13
0
 /// <summary>
 /// Performs various actions that should occur prior to further tagging. 
 /// This method tags any digits in the name, identifies and removes any preamble, and tags any prepositions remaining in the name.
 /// </summary>
 /// <param name="node">The node to be tagged.</param>
 public abstract void PreTag(ProgramElementNode node);
Esempio n. 14
0
 /// <summary>
 /// Determines whether the supplied ProgramElementNode matches the conditions of this rule.
 /// </summary>
 /// <param name="node">The ProgramElementNode to test.</param>
 /// <returns>True if the node matches this rule, False otherwise.</returns>
 public override bool InClass(ProgramElementNode node)
 {
     return (node is FieldDeclarationNode);
 }
Esempio n. 15
0
 /// <summary>
 /// Does nothing; simply returns;
 /// </summary>
 /// <param name="node"></param>
 public override void PreTag(ProgramElementNode node)
 {
     return;
 }
Esempio n. 16
0
 /// <summary>
 /// Determines whether the supplied node meets the criteria for this rule.
 /// </summary>
 /// <param name="node">The node to test.</param>
 /// <returns>True if the node meets this rule, False otherwise.</returns>
 public override bool InClass(ProgramElementNode node)
 {
     return (node is MethodDeclarationNode) && ((MethodDeclarationNode)node).Context != null && ((MethodDeclarationNode)node).Context.IsConstructor;
 }
Esempio n. 17
0
 /// <summary>
 /// Constructs the Software Word Use Model on the given node, using this Rule.
 /// </summary>
 /// <param name="node">The node to construct the SWUM on.</param>
 public abstract void ConstructSwum(ProgramElementNode node);
Esempio n. 18
0
 /// <summary>
 /// Determines whether the supplied ProgramElementNode matches the conditions of this rule.
 /// </summary>
 /// <param name="node">The ProgramElementNode to test.</param>
 /// <returns>True if the node matches this rule, False otherwise.</returns>
 public abstract bool InClass(ProgramElementNode node);
Esempio n. 19
0
 /// <summary>
 /// Determines whether the given node satisfies this rule.
 /// 
 /// ** Note that calling this method has the effect of stripping any preamble from the given node, and tagging any digits and prepositions. **
 /// </summary>
 /// <param name="node">The node to test.</param>
 /// <returns>True if the node matches this rule, False otherwise.</returns>
 public override bool InClass(ProgramElementNode node)
 {
     if (node is MethodDeclarationNode)
     {
         MethodDeclarationNode mdn = (MethodDeclarationNode)node;
         mdn.Parse(this.Splitter);
         this.PosTagger.PreTag(mdn);
         return MakeClassification(mdn);
     }
     return false;
 }