Example #1
0
 public virtual void lookUpFunction(Rete engine)
 {
     actualFunction = engine.findFunction(funcName);
 }
Example #2
0
 public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
 {
     String sval = new String("".ToCharArray());
     if (params_Renamed != null)
     {
         if (params_Renamed.Length == 1)
         {
             if (params_Renamed[0] is ValueParam)
             {
                 ValueParam n = (ValueParam) params_Renamed[0];
                 sval = n.StringValue;
                 IFunction aFunction = engine.findFunction(sval);
                 if (aFunction != null)
                     sval = aFunction.toPPString(null, 0);
                 else
                     sval = toPPString(null, 0);
             }
             else if (params_Renamed[0] is BoundParam)
             {
                 BoundParam bp = (BoundParam) params_Renamed[0];
                 sval = bp.StringValue;
                 IFunction aFunction = engine.findFunction(sval);
                 if (aFunction != null)
                     sval = aFunction.toPPString(null, 0);
                 else
                     sval = toPPString(null, 0);
             }
             else if (params_Renamed[0] is FunctionParam2)
             {
                 FunctionParam2 n = (FunctionParam2) params_Renamed[0];
                 n.Engine = engine;
                 n.lookUpFunction();
                 IReturnVector rval = (IReturnVector) n.Value;
                 sval = rval.firstReturnValue().StringValue;
                 IFunction aFunction = engine.findFunction(sval);
                 if (aFunction != null)
                     sval = aFunction.toPPString(null, 0);
                 else
                     sval = toPPString(null, 0);
             }
         }
         else
             sval = toPPString(null, 0);
     }
     DefaultReturnVector ret = new DefaultReturnVector();
     DefaultReturnValue rv = new DefaultReturnValue(Constants.STRING_TYPE, sval);
     ret.addReturnValue(rv);
     return ret;
 }
Example #3
0
        public virtual IReturnVector executeFunction(Rete engine, IParameter[] params_Renamed)
        {
            DefaultReturnVector ret = new DefaultReturnVector();
            bool add = false;
            if (engine.findFunction(name) == null)
            {
                // first we Get the actual function from the shell function
                IFunction[] functions = new IFunction[this.functions.Count];
                IParameter[][] parameters = new IParameter[this.functions.Count][];
                for (int i = 0; i < functions.Length; ++i)
                {
                    ShellFunction sf = (ShellFunction) this.functions[i];
                    functions[i] = engine.findFunction(sf.Name);
                    parameters[i] = sf.Parameters;
                }
                InterpretedFunction intrfunc = new InterpretedFunction(name, this.parameters, functions, parameters);
                intrfunc.configureFunction(engine);
                engine.declareFunction(intrfunc);
                add = true;
            }

            DefaultReturnValue rv = new DefaultReturnValue(Constants.BOOLEAN_OBJECT, add);
            ret.addReturnValue(rv);
            return ret;
        }
Example #4
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);
     }
 }