示例#1
0
 /// <summary> Configure will lookup the function and set it
 /// </summary>
 public virtual void configure(Rete.Rete engine, IRule util)
 {
     if (functionName != null && engine.findFunction(functionName) != null)
     {
         faction = engine.findFunction(functionName);
     }
     // now setup the BoundParameters if there are any
     for (int idx = 0; idx < parameters.Length; idx++)
     {
         if (parameters[idx] is BoundParam)
         {
             BoundParam bp = (BoundParam)parameters[idx];
             Binding    bd = util.getBinding(bp.VariableName);
             if (bd != null)
             {
                 bp.Row    = bd.LeftRow;
                 bp.Column = bd.LeftIndex;
             }
         }
         else if (parameters[idx] is FunctionParam2)
         {
             FunctionParam2 fp2 = (FunctionParam2)parameters[idx];
             fp2.configure(engine, util);
         }
         else if (parameters[idx] is ValueParam)
         {
             ValueParam vp = (ValueParam)parameters[idx];
             // if the value is a deffact, we need to check and make sure
             // the slots with BoundParam value are compiled properly
             if (vp.Value is Deffact)
             {
                 ((Deffact)vp.Value).compileBinding(util);
             }
         }
     }
     // in the case of Assert, we do further compilation
     if (faction is AssertFunction)
     {
         Deftemplate tmpl = (Deftemplate)engine.CurrentFocus.getTemplate(parameters[0].StringValue);
         Deffact     fact = (Deffact)tmpl.createFact((Object[])parameters[1].Value, -1);
         fact.compileBinding(util);
         parameters    = new ValueParam[1];
         parameters[0] = new ValueParam(Constants.OBJECT_TYPE, fact);
     }
 }
示例#2
0
        public virtual int analyze(IRule rule)
        {
            int result = Analysis_Fields.VALIDATION_PASSED;

            error   = new ErrorSummary();
            warning = new WarningSummary();
            checkForModule(rule);
            ICondition[] cnds = rule.Conditions;
            for (int idx = 0; idx < cnds.Length; idx++)
            {
                ICondition cnd = cnds[idx];
                if (cnd is ObjectCondition)
                {
                    ObjectCondition oc  = (ObjectCondition)cnd;
                    Deftemplate     dft = oc.Deftemplate;
                    if (dft != null)
                    {
                        IConstraint[] cntrs = oc.Constraints;
                        for (int idy = 0; idy < cntrs.Length; idy++)
                        {
                            IConstraint cons = cntrs[idy];
                            if (cons is LiteralConstraint)
                            {
                                Slot sl = dft.getSlot(cons.Name);
                                if (sl == null)
                                {
                                    error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist.");
                                    result = Analysis_Fields.VALIDATION_FAILED;
                                }
                            }
                            else if (cons is BoundConstraint)
                            {
                                BoundConstraint bc = (BoundConstraint)cons;
                                if (!bc.isObjectBinding)
                                {
                                    Slot sl = dft.getSlot(bc.Name);
                                    if (sl == null)
                                    {
                                        error.addMessage(INVALID_SLOT + " " + cons.Name + " slot does not exist.");
                                        result = Analysis_Fields.VALIDATION_FAILED;
                                    }
                                }
                            }
                            else if (cons is PredicateConstraint)
                            {
                                PredicateConstraint pc = (PredicateConstraint)cons;
                                IFunction           f  = engine.findFunction(pc.FunctionName);
                                if (f == null)
                                {
                                    addInvalidFunctionError(pc.FunctionName);
                                }
                            }
                        }
                    }
                    else
                    {
                        error.addMessage(INVALID_TEMPLATE + " " + oc.TemplateName + " template does not exist.");
                        result = Analysis_Fields.VALIDATION_FAILED;
                    }
                }
                else if (cnd is TestCondition)
                {
                    TestCondition tc = (TestCondition)cnd;
                    if (tc.Function == null)
                    {
                        error.addMessage(NO_FUNCTION);
                        result = Analysis_Fields.VALIDATION_FAILED;
                    }
                    else
                    {
                        IFunction f = tc.Function;
                        if (engine.findFunction(f.Name) == null)
                        {
                            addInvalidFunctionError(f.Name);
                            result = Analysis_Fields.VALIDATION_FAILED;
                        }
                    }
                }
                else if (cnd is ExistCondition)
                {
                }
            }
            // now we check the Right-hand side
            IAction[] acts = rule.Actions;
            for (int idx = 0; idx < acts.Length; idx++)
            {
                IAction act = acts[idx];
                if (act is FunctionAction)
                {
                    FunctionAction fa = (FunctionAction)act;
                    if (engine.findFunction(fa.FunctionName) == null)
                    {
                        addInvalidFunctionError(fa.FunctionName);
                        result = Analysis_Fields.VALIDATION_FAILED;
                    }
                }
            }
            return(result);
        }