/// <summary> /// 创建一个新实例. /// </summary> //public Operator() //{ // this.m_cond = c; // this.m_pre = new Conjunction(); // this.m_add = new Conjunction(); // this.m_del = new Conjunction(); // this.m_allUnifiers = new List<string>(); // this.m_validUnifiers = new List<string>(); //} /// <summary> /// 创建一个新实例. /// </summary> public Operator(OperatorHead h, Condition c, Conjunction p, Conjunction a, Conjunction d) { this.m_opHead = h; this.m_cond = c; this.m_pre = p; this.m_add = a; this.m_del = d; this.m_allUnifiers = new List <string>(); this.m_validUnifiers = new List <string>(); }
/// <summary> /// foamliu, 2009/01/21, 替换并构建 Action 的签名. /// /// 例如: /// 下面这个 Op 的头: /// Move (Block ?obj, Block ?from, Block ?to) /// /// 在 un 为如下的情况下: /// * -------------------------- /// * var | value /// * -------------------------- /// * ?obj | b1 /// * ?from | b2 /// * ?to | b3 /// * -------------------------- /// /// 替换的结果是: /// Move ( b1, Block b2, Block b3 ) /// </summary> /// <param name="m_opHead"></param> /// <param name="un"></param> /// <returns></returns> public static string Substitute(OperatorHead m_opHead, Unifier un) { StringBuilder sb = new StringBuilder(); sb.Append(m_opHead.OpName + " ( "); if (m_opHead.ParaList.Vars.Count == 0) { // 没有参数 sb.Append(" )"); // 这里不需要后处理. return(sb.ToString()); } else { foreach (string var in m_opHead.ParaList.Vars) { if (Util.IsVariable(var)) { // 是变量, 取对应值. sb.Append(un.Get(var) + ", "); } else { // 不是变量, 直接加上去. sb.Append(var + ", "); } //sb.Append(var + ", "); } } // 去掉最后的 ", ", 再加上 " )" string s = sb.ToString(); return(s.Substring(0, s.Length - 2) + " )"); }