Beispiel #1
0
        /// <summary>
        /// P_node_activations the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="tok">The tok.</param>
        /// <param name="w">The w.</param>
        private void p_node_activation(ProductionNode node, Token tok, WME w)
        {
            Token new_token = make_token(node, tok, w);
            node.Items.AddToFront(new_token);

            int lhsCnt = node.Production.Lhs.Count - 1;

            foreach (RightHandSideCondition rhsCondition in node.Production.Rhs)
            {
                WME newfact = new WME();
                for (int f = 0; f < 3; f++)
                {
                    Term term = rhsCondition.Fields[f];
                    if (term.TermType == TermType.Variable)
                    {
                        for (int i = lhsCnt; i >= 0; i--)
                        {
                            Condition lhsCondition = node.Production.Lhs[i];
                            if (lhsCondition.ConditionType == ConditionType.Positive)
                            {
                                int pos = lhsCondition.Contains(term);
                                if (pos >= 0)
                                {
                                    Token tok2 = new_token.GetTokenUp(lhsCnt - i);
                                    newfact.Fields[f] = tok2.WME[pos];
                                    i = -1;
                                }
                            }
                        }
                    }
                    else
                    {
                        newfact.Fields[f] = term;
                    }
                }
                Activation newact = new Activation(newfact, rhsCondition.ConditionType);
                if (node.Production.InferredFacts.Contains(newact) == false)
                {
                    node.Production.InferredFacts.Add(newact);
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// Adds a production.
 /// </summary>
 /// <remarks>
 /// We are now ready to give the add-production procedure, which takes a production (actually,
 /// just the conditions of the production | the match algorithm doesn't care what the actions are)
 /// and adds it to the network. It follows the basic procedure given at the beginning of this section,
 /// and uses the helper functions we have just defined. The last two lines of the procedure are a
 /// bit vague, because the implementation of production nodes tends to vary from one system to
 /// another. It is important to note that we build the net top-down, and each time we build a
 /// new join node, we insert it at the head of its alpha memory's list of successors; these two facts
 /// guarantee that descendents are on each alpha memory's list before any of their ancestors, just
 /// as we required in Section 2.4.1 in order to avoid duplicate tokens.
 /// </remarks>
 /// <param name="prod">The Production.</param>
 public void AddProduction(Production prod)
 {
     ProductionNode new_production = new ProductionNode();
     new_production.Production = prod;
     AddProduction(new_production, prod.Lhs);
     prod.ProductionNode = new_production;
 }