当前位置: 首页>>代码示例>>C#>>正文


C# Name.MakeGround方法代码示例

本文整理汇总了C#中Name.MakeGround方法的典型用法代码示例。如果您正苦于以下问题:C# Name.MakeGround方法的具体用法?C# Name.MakeGround怎么用?C# Name.MakeGround使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Name的用法示例。


在下文中一共展示了Name.MakeGround方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FindSubst

        private static bool FindSubst(Name n1, Name n2, bool allowPartialTerms, SubstitutionSet bindings)
        {
            n1 = n1.MakeGround(bindings);
            n2 = n2.MakeGround(bindings);
            var t = GetTerms(n1, n2, allowPartialTerms);
            if (t == null)
                return false;

            foreach (var p in t)
            {
                Substitution candidate = null;
                bool isVar1 = p.Item1.IsVariable;
                bool isVar2 = p.Item2.IsVariable;

                // Case 1: x = t, where t is not a variable and x is a variable, and create substitution x/t
                if (isVar1 != isVar2)
                {
                    Name variable = (isVar1 ? p.Item1 : p.Item2);
                    Name value = isVar1 ? p.Item2 : p.Item1;
                    if (value.ContainsVariable(variable))		//Occurs check to prevent cyclical evaluations
                        return false;

                    candidate = new Substitution(variable, value);
                }
                else if (isVar1) //isVar1 == isVar2 == true
                {
                    //Case 2: x = x, where x is a variable, ignore it. otherwise add the substitution
                    if (!(p.Item1 == p.Item2))
                        candidate = new Substitution(p.Item1, p.Item2);
                }
                else //isVar1 == isVar2 == false
                {
                    // Case 3: t1 = t2, where t1,t2 are not variables.
                    // If they don't contain variables, compare them to see if they are equal. If they are not equal the unification fails.
                    if (p.Item1.IsGrounded && p.Item2.IsGrounded)
                    {
                        if (p.Item1 == p.Item2)
                            continue;
                        return false;
                    }

                    //If one or both contain variables, unify the terms
                    if (!FindSubst(p.Item1, p.Item2,allowPartialTerms, bindings))
                        return false;
                }

                if (candidate != null)
                {
                    // Step 4: check to see if the newly created substitution conflicts with any of the already created substitution.
                    // If it does, the unification fails.
                    if (!bindings.AddSubstitution(candidate))
                        return false;
                }
            }
            return true;
        }
开发者ID:GAIPS-INESC-ID,项目名称:FAtiMA-Toolkit,代码行数:56,代码来源:Unifier.cs


注:本文中的Name.MakeGround方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。