An abstract node within the SWUM model
        /// <summary>
        /// Creates a new EquivalenceNode containing the passed node and the specified nodes from the UnknownArguments list.
        /// The arguments are removed from the UnknownArguments list after being added to the EquivalenceNode.
        /// </summary>
        /// <param name="equivalentNode">The first node to add to the EquivalenceNode, i.e. the node that the unknown arguments are equivalent with.</param>
        /// <param name="equivalentUnknownArgs">The UnknownArguments to include in the equivalence.</param>
        /// <returns>An EquivalenceNode containing the passed node and the specified nodes from the UnknownArguments list.</returns>
        /// <exception cref="System.ArgumentNullException">equivalentNode is null.</exception>
        /// <exception cref="System.ArgumentNullException">equivalentUnknownArgs is null.</exception>
        public virtual EquivalenceNode CreateEquivalenceFromUnknownArguments(Node equivalentNode, IEnumerable<Node> equivalentUnknownArgs) {
            if(equivalentNode == null) { throw new ArgumentNullException("equivalentNode"); }
            if(equivalentUnknownArgs == null) { throw new ArgumentNullException("equivalentUnknownArgs"); }

            EquivalenceNode equivNode = new EquivalenceNode(equivalentNode);
            //add specified UnknownArguments to the equivalence
            foreach(var equivArg in equivalentUnknownArgs) {
                if(!this.UnknownArguments.Contains(equivArg)) {
                    throw new InvalidOperationException(string.Format("Node is not present in the UnknownArguments collection: {0}", equivArg));
                }
                equivNode.AddEquivalentNode(equivArg);
            }
            //remove equivalent arguments from the UnknownArguments list
            this.UnknownArguments.RemoveAll(n => equivalentUnknownArgs.Contains(n));

            return equivNode;
        }
 /// <summary>
 /// Creates a new ArgumentNode from the given parameters, and adds it to the SecondaryArguments list.
 /// </summary>
 /// <param name="argument">The node that is serving as the argument.</param>
 /// <param name="preposition">The preposition describing the argument's relation to the method.</param>
 public void AddSecondaryArgument(Node argument, WordNode preposition) {
     if(this.SecondaryArguments == null) {
         this.SecondaryArguments = new List<ArgumentNode>();
     }
     ArgumentNode an = new ArgumentNode(argument, preposition);
     this.SecondaryArguments.Add(an);
 }
        /// <summary>
        /// Creates a new EquivalenceNode containing the passed node and the specified nodes from the UnknownArguments list.
        /// The arguments are removed from the UnknownArguments list after being added to the EquivalenceNode.
        /// </summary>
        /// <param name="equivalentNode">The first node to add to the EquivalenceNode, i.e. the node that the unknown arguments are equivalent with.</param>
        /// <param name="equivalentUnknownArgs">An array of booleans indicating which unknown arguments to include in the equivalence. 
        /// This array must be the same length as the UnknownArguments list.
        /// For each element in the array, a value of True means to include the corresponding unknown argument, False means to not include it.</param>
        /// <returns>An EquivalenceNode containing the passed node and the specified nodes from the UnknownArguments list.</returns>
        /// <exception cref="System.ArgumentNullException">equivalentNode is null.</exception>
        /// <exception cref="System.ArgumentException">The length of equivalentUnknownArgs is not the same as the UnknownArguments property of the MethodDeclarationNode.</exception>
        public virtual EquivalenceNode CreateEquivalenceFromUnknownArguments(Node equivalentNode, bool[] equivalentUnknownArgs) {
            if(equivalentNode == null) { throw new ArgumentNullException("equivalentNode"); }
            if(equivalentUnknownArgs.Length != UnknownArguments.Count) {
                throw new ArgumentException("Length of equivalentUnknownArgs array not equal to length of UnknownArguments", "equivalentUnknownArgs");
            }

            //grab the specified UnknownArguments and put in a list
            List<Node> equivArgs = new List<Node>();
            for(int argIndex = 0; argIndex < equivalentUnknownArgs.Length; argIndex++) {
                if(equivalentUnknownArgs[argIndex]) {
                    equivArgs.Add(this.UnknownArguments[argIndex]);
                }
            }
            return CreateEquivalenceFromUnknownArguments(equivalentNode, equivArgs);
        }
 /// <summary>
 /// Adds the given argument to the UnknownArguments list.
 /// </summary>
 /// <param name="argument">A Node corresponding to the argument to add.</param>
 public void AddUnknownArgument(Node argument) {
     if(this.UnknownArguments == null) {
         this.UnknownArguments = new List<Node>();
     }
     this.UnknownArguments.Add(argument);
 }
Beispiel #5
0
 /// <summary>
 /// Creates a new ArgumentNode.
 /// </summary>
 /// <param name="argument">The node being passed as an argument.</param>
 /// <param name="preposition">A prepostion describing the argument's relationship to its method.</param>
 public ArgumentNode(Node argument, WordNode preposition) {
     this.Argument = argument;
     this.Preposition = preposition;
 }
Beispiel #6
0
 /// <summary>
 /// Adds a node to the list of equivalent nodes.
 /// </summary>
 /// <param name="n">The node to add.</param>
 public void AddEquivalentNode(Node n) {
     if(EquivalentNodes == null) {
         EquivalentNodes = new List<Node>();
     }
     EquivalentNodes.Add(n);
 }
Beispiel #7
0
 /// <summary>
 /// Creates a new EquivalenceNode.
 /// </summary>
 /// <param name="n">The initial node to add to the list of equivalent nodes.</param>
 public EquivalenceNode(Node n) {
     AddEquivalentNode(n);
 }
Beispiel #8
0
 /// <summary>
 /// Parse <param name="nd"></param> to a string using in the summary
 /// </summary>
 /// <param name="nd"></param>
 /// <returns></returns>
 private string ParseSwumNodeToString(Node nd)
 {
     if (nd is EquivalenceNode) {
         var firstOrDefault = ((EquivalenceNode)nd).EquivalentNodes.FirstOrDefault();
         if (firstOrDefault != null)
             return firstOrDefault.ToPlainString();
     }
     //we could do more than that.
     return nd.ToPlainString();
 }