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); }
public virtual void lookUpFunction() { func = engine.findFunction(funcName); }
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); }
public virtual void lookUpFunction(Rete engine) { actualFunction = engine.findFunction(funcName); }
/// <summary> /// Compiles the constraint. /// </summary> /// <param name="cnstr">The CNSTR.</param> /// <param name="templ">The templ.</param> /// <param name="rule">The rule.</param> /// <param name="position">The position.</param> /// <returns></returns> public virtual BaseAlpha2 compileConstraint(PredicateConstraint cnstr, ITemplate templ, Rule.IRule rule, int position) { BaseAlpha2 current = null; // for now we expect the user to write the predicate in this // way (> ?bind value), where the binding is first. this // needs to be updated so that we look at the order of the // parameters and set the node appropriately // we only create an AlphaNode if the predicate isn't // joining 2 bindings. if (!cnstr.PredicateJoin) { if (ConversionUtils.isPredicateOperatorCode(cnstr.FunctionName)) { int oprCode = ConversionUtils.getOperatorCode(cnstr.FunctionName); Slot sl = (Slot)templ.getSlot(cnstr.Name).Clone(); Object sval = ConversionUtils.convert(sl.ValueType, cnstr.Value); sl.Value = sval; // create the alphaNode if (rule.RememberMatch) { current = new AlphaNode(engine.nextNodeId()); } else { current = new NoMemANode(engine.nextNodeId()); } current.Slot = sl; current.Operator = oprCode; current.incrementUseCount(); // we increment the node use count when when create a new // AlphaNode for the LiteralConstraint templ.getSlot(sl.Id).incrementNodeCount(); } else { // the function isn't a built in predicate function that // returns boolean true/false. We look up the function IFunction f = engine.findFunction(cnstr.FunctionName); if (f != null) { // we create the alphaNode if a function is found and // the return type is either boolean primitive or object if (f.ReturnType == Constants.BOOLEAN_PRIM_TYPE || f.ReturnType != Constants.BOOLEAN_OBJECT) { // TODO - need to implement it } else { // the function doesn't return boolean, so we have to notify // the listeners the condition is not valid CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.FUNCTION_INVALID); ce.Message = INVALID_FUNCTION + " " + f.ReturnType; //$NON-NLS-1$ notifyListener(ce); } } else { // we need to notify listeners the function wasn't found CompileMessageEventArgs ce = new CompileMessageEventArgs(this, EventType.FUNCTION_NOT_FOUND); ce.Message = FUNCTION_NOT_FOUND + " " + cnstr.FunctionName; notifyListener(ce); } } } Binding bind = new Binding(); bind.VarName = cnstr.VariableName; bind.LeftRow = position; bind.LeftIndex = templ.getSlot(cnstr.Name).Id; bind.RowDeclared = position; // we only Add the binding to the map if it doesn't already exist if (rule.getBinding(cnstr.VariableName) == null) { rule.addBinding(cnstr.VariableName, bind); } return(current); }