/// <summary> the class overrides the method to include the additional /// attributes. /// </summary> public override String toPPString() { StringBuilder buf = new StringBuilder(); buf.Append("(" + deftemplate.Name); if (slots.Length > 0) { buf.Append(" "); } for (int idx = 0; idx < slots.Length; idx++) { if (slots[idx].Value is BoundParam) { BoundParam bp = (BoundParam)slots[idx].Value; buf.Append("(" + slots[idx].Name + " ?" + bp.VariableName + ") "); } else { buf.Append("(" + slots[idx].Name + " " + ConversionUtils.formatSlot(slots[idx].Value) + ") "); } } // append the temporal attributes buf.Append("(" + TemporalFact_Fields.EXPIRATION + " " + expirationTime + ")"); buf.Append("(" + TemporalFact_Fields.SERVICE_TYPE + " " + serviceType + ")"); buf.Append("(" + TemporalFact_Fields.SOURCE + " " + sourceURL + ")"); buf.Append("(" + TemporalFact_Fields.VALIDITY + " " + validity + ") "); buf.Append(")"); return(buf.ToString()); }
/* * public virtual ObjectTypeNode findObjectTypeNode(String templateName) * { * IEnumerator itr = inputnodes.keySet().GetEnumerator(); * Template tmpl = null; * while (itr.MoveNext()) * { * tmpl = (Template)itr.Current; * if (tmpl.Name.Equals(templateName)) * { * break; * } * } * if (tmpl != null) * { * return (ObjectTypeNode)inputnodes.Get(tmpl); * } * else * { * log.Debug(Messages.getString("RuleCompiler.deftemplate.error")); //$NON-NLS-1$ * return null; * } * } */ /// <summary> /// method compiles a literalConstraint /// </summary> /// <param name="cnstr">The CNSTR.</param> /// <param name="templ">The templ.</param> /// <param name="rule">The rule.</param> /// <returns></returns> public virtual BaseAlpha2 compileConstraint(LiteralConstraint cnstr, ITemplate templ, Rule.IRule rule) { BaseAlpha2 current = null; if (templ.getSlot(cnstr.Name) != null) { Slot sl = (Slot)templ.getSlot(cnstr.Name).Clone(); Object sval = ConversionUtils.convert(sl.ValueType, cnstr.Value); sl.Value = sval; if (rule.RememberMatch) { current = new AlphaNode(engine.nextNodeId()); } else { current = new NoMemANode(engine.nextNodeId()); } current.Slot = sl; current.Operator = Constants.EQUAL; current.incrementUseCount(); // we increment the node use count when when create a new // AlphaNode for the LiteralConstraint templ.getSlot(sl.Id).incrementNodeCount(); } return(current); }
/// <summary> /// Remove the node from the succesors /// </summary> /// <param name="n">The n.</param> /// <returns></returns> public virtual bool removeNode(BaseNode n) { bool rem = false; if (containsNode(successorNodes, n)) { successorNodes = ConversionUtils.remove(successorNodes, n); rem = true; } return(rem); }
/// <summary> /// Add the node to the list of successors /// </summary> /// <param name="n">The n.</param> /// <returns></returns> protected internal virtual bool addNode(BaseNode n) { bool add = false; if (!containsNode(successorNodes, n)) { successorNodes = ConversionUtils.add(successorNodes, n); add = true; } return(add); }
/// <summary> Method will return the fact in a string format. /// </summary> /// <returns> /// /// </returns> public virtual String toFactString() { StringBuilder buf = new StringBuilder(); buf.Append("f-" + id + " (" + deftemplate.Name); if (slots.Length > 0) { buf.Append(" "); } for (int idx = 0; idx < slots.Length; idx++) { buf.Append("(" + slots[idx].Name + " " + ConversionUtils.formatSlot(slots[idx].Value) + ") "); } buf.Append(")"); return(buf.ToString()); }
/// <summary> Method will generate a pretty printer format of the Deftemplate /// /// </summary> /// <returns> /// /// </returns> public virtual String toPPString() { StringBuilder buf = new StringBuilder(); buf.Append("(" + templateName + Constants.LINEBREAK); for (int idx = 0; idx < slots.Length; idx++) { buf.Append(" (" + slots[idx].Name + " (type " + ConversionUtils.getTypeName(slots[idx].ValueType) + ") )" + Constants.LINEBREAK); } if (defclass != null) { buf.Append("[" + defclass + "] "); } buf.Append(")"); return(buf.ToString()); }
public override String toPPString() { StringBuilder buf = new StringBuilder(); buf.Append("?" + varName + " (" + leftrow + ")("); buf.Append(leftIndex); if (function != null) { buf.Append(") " + function.Name + " (0)("); } else { buf.Append(") " + ConversionUtils.getPPOperator(operator_Renamed) + " (0)("); } buf.Append(rightIndex); buf.Append(") ?" + rightVariable); return(buf.ToString()); }
/// <summary> /// create the deftemplate for the defclass /// </summary> /// <param name="tempName">Name of the temp.</param> /// <returns></returns> public virtual Deftemplate createDeftemplate(String tempName) { Slot[] st = new Slot[PROPS.Length]; for (int idx = 0; idx < st.Length; idx++) { if (PROPS[idx].PropertyType.IsArray) { st[idx] = new MultiSlot(PROPS[idx].Name); st[idx].Id = idx; } else { st[idx] = new Slot(PROPS[idx].Name); st[idx].ValueType = ConversionUtils.getTypeCode(PROPS[idx].PropertyType); // set the column id for the slot st[idx].Id = idx; } } Deftemplate temp = new Deftemplate(tempName, OBJECT_CLASS.FullName, st); return(temp); }
public virtual String toPPString() { StringBuilder buf = new StringBuilder(); buf.Append("(" + deftemplate.Name); if (slots.Length > 0) { buf.Append(" "); } for (int idx = 0; idx < slots.Length; idx++) { if (slots[idx].Value is BoundParam) { BoundParam bp = (BoundParam)slots[idx].Value; buf.Append("(" + slots[idx].Name + " ?" + bp.VariableName + ") "); } else { buf.Append("(" + slots[idx].Name + " " + ConversionUtils.formatSlot(slots[idx].Value) + ") "); } } buf.Append(")"); return(buf.ToString()); }
/// <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); }
/// <summary> Method returns the pretty printer formatted string of the node's /// condition. For now, the method just replaces the operator. It might /// be nice to replace the slot id with the slot name. /// </summary> /// <returns> /// /// </returns> public override String toPPString() { return("node-" + nodeID + "> slot(" + slot.Name + ") " + ConversionUtils.getPPOperator(operator_Renamed) + " " + ConversionUtils.formatSlot(slot.Value) + " - useCount=" + useCount); }
/// <summary> Method returns the string format of the node's condition. later on /// this should be cleaned up. /// </summary> public override String ToString() { return("slot(" + slot.Id + ") " + ConversionUtils.getPPOperator(operator_Renamed) + " " + slot.Value.ToString() + " - useCount=" + useCount); }