Ejemplo n.º 1
0
 private string GetValue(string var, Unifier u)
 {
     if (Util.IsVariable(var))
     {
         return(u.Get(var));
     }
     else
     {
         return(var);
     }
 }
Ejemplo n.º 2
0
        /// <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) + " )");
        }