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


C# PrologContext.Prove方法代码示例

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


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

示例1: NotPlusImplementation

 private static IEnumerable<CutState> NotPlusImplementation(object[] args, PrologContext context)
 {
     if (args.Length != 1) throw new ArgumentCountException("\\+", args, "goal");
     using (var e = context.Prove(args[0], "Argument to \\+ must be a valid term to prove.").GetEnumerator())
     {
         if (!e.MoveNext() || e.Current == CutState.ForceFail)
             yield return CutState.Continue;
     }
 }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:9,代码来源:PrologPrimitives.cs

示例2: IfThenImplementation

        private static IEnumerable<CutState> IfThenImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 2) throw new ArgumentCountException("->", args, "if_condition", "then_result");

#pragma warning disable 414, 168, 219
            // ReSharper disable UnusedVariable
            foreach (var ignore in context.Prove(args[0], "Arguments to -> must be valid subgoals."))
                // ReSharper restore UnusedVariable
            {
                // ReSharper disable UnusedVariable
                foreach (var ignore2 in context.Prove(args[1], "Arguments to -> must be valid subgoals."))
                // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
                {
                    yield return CutState.Continue;
                }
                yield break;
            }
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:19,代码来源:PrologPrimitives.cs

示例3: NotImplementation

 private static IEnumerable<CutState> NotImplementation(object[] args, PrologContext context)
 {
     if (args.Length != 1) throw new ArgumentCountException("not", args, "goal");
     LogicVariable v = Term.FindUninstantiatedVariable(args[0]);
     if (v != null)
         throw new InstantiationException(v, "Argument to not must be a ground literal (i.e. contain no unbound variables).");
     using (var e = context.Prove(args[0], "Argument to not must be a valid term to prove.").GetEnumerator())
     {
         if (!e.MoveNext() || e.Current == CutState.ForceFail)
             yield return CutState.Continue;
     }
 }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:12,代码来源:PrologPrimitives.cs

示例4: RealOrImplementation

 private static IEnumerable<CutState> RealOrImplementation(object[] args, PrologContext context)
 {
     foreach (var status1 in context.Prove(args[0], "Arguments to ; (or) must be valid subgoals."))
     {
         if (status1 == CutState.ForceFail)
         {
             //yield return status1;
             yield break;
         }
         yield return CutState.Continue;
     }
     foreach (var status2 in context.Prove(args[1], "Arguments to ; (or) must be valid subgoals."))
     {
         if (status2 == CutState.ForceFail)
         {
             //yield return status2;
             yield break;
         }
         yield return CutState.Continue;
     }
 }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:21,代码来源:PrologPrimitives.cs

示例5: IfThenElseImplementation

        private static IEnumerable<CutState> IfThenElseImplementation(object test, object consequent, object alternative, PrologContext context)
        {
#pragma warning disable 414, 168, 219
            // ReSharper disable UnusedVariable
            foreach (var ignore in context.Prove(test, "Arguments to -> must be valid subgoals."))
                // ReSharper restore UnusedVariable
            {
                // ReSharper disable UnusedVariable
                foreach (var ignore2 in context.Prove(consequent, "Arguments to -> must be valid subgoals."))
                    // ReSharper restore UnusedVariable
                {
                    yield return CutState.Continue;
                }
                yield break;
            }
            // ReSharper disable UnusedVariable
            foreach (var ignore in context.Prove(alternative, "Arguments to -> must be valid subgoals."))
                // ReSharper restore UnusedVariable
            {
                yield return CutState.Continue;
            }
#pragma warning restore 414, 168, 219
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:23,代码来源:PrologPrimitives.cs

示例6: ForAllUniqueImplementation

        private static IEnumerable<CutState> ForAllUniqueImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 3)
                throw new ArgumentCountException("for_all_unique", args, "-Template", ":generator", ":goal");
            var template = Term.Deref(args[0]);
            foreach (var templateValue in SolutionList(context, template, Term.Deref(args[1]), int.MaxValue, true))
#pragma warning disable 414, 168, 219
                // ReSharper disable UnusedVariable
                foreach (var ignore in Term.Unify(template, templateValue))
                {
                    var gotOne = false;
                    foreach (var ignore2 in context.Prove(args[2], "Arguments for forall/2 must be valid goals."))
                        // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
                        gotOne = true;
                    if (!gotOne)
                        yield break;
                }
            yield return CutState.Continue;
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:20,代码来源:PrologPrimitives.cs

示例7: AndImplementation

 private static IEnumerable<CutState> AndImplementation(object[] args, PrologContext context)
 {
     if (args.Length != 2) throw new ArgumentCountException(", (and)", args, "goal1", "goal2");
     foreach (var status1 in context.Prove(args[0], "Arguments to , (and) must be valid subgoals."))
     {
         if (status1==CutState.ForceFail)
         {
             yield return status1;
             yield break;
         }
         foreach (var status2 in context.Prove(args[1], "Arguments to , (and) must be a valid subgoals."))
         {
             if (status2 == CutState.ForceFail)
             {
                 yield return status2;
                 yield break;
             }
             yield return CutState.Continue;
         }
     }
 }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:21,代码来源:PrologPrimitives.cs

示例8: BeginImplementation

 private static IEnumerable<CutState> BeginImplementation(object[] args, PrologContext context)
 {
     var enumerators = new IEnumerator<CutState>[args.Length];
     int i=0;
     try
     {
         for (; i<args.Length; i++)
         {
             var goal = args[i];
             var goalStructure = Term.Structurify(goal, "Argument to begin is not a valid goal.");
             if (goalStructure.IsFunctor(Symbol.Dot, 2))
                 FunctionalExpression.Eval(goalStructure, context);
             else
             {
                 var enumerator = context.Prove(goalStructure).GetEnumerator();
                 enumerators[i] = enumerator;
                 if (!enumerator.MoveNext() || enumerator.Current == CutState.ForceFail)
                     throw new GoalException(goal, "Goal failed");
             }
         }
         yield return CutState.Continue;
     }
     finally
     {
         while ((--i)>=0)
             enumerators[i].Dispose();
     }
 }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:28,代码来源:PrologPrimitives.cs

示例9: CallImplementation

        private static IEnumerable<CutState> CallImplementation(object[] args, PrologContext context)
        {
            switch (args.Length)
            {
                case 0:
                    throw new ArgumentCountException("call", args, "goal", "optionalAdditionalArguments", "...");

                case 1:
                    return IgnoreCuts(context.Prove(args[0], "Argument to call must be a valid subgoal."));

                default:
                    // More than 1 argument - add other arguments to the end of the predicate
                    {
                        object goal = Term.Deref(args[0]);
                        var t = goal as Structure;

                        if (t != null)
                        {
                            var goalArgs = new object[t.Arguments.Length + args.Length - 1];
                            t.Arguments.CopyTo(goalArgs, 0);
                            Array.Copy(args, 1, goalArgs, t.Arguments.Length, args.Length - 1);

                            return IgnoreCuts(context.KnowledgeBase.Prove(t.Functor, goalArgs, context, context.CurrentFrame));
                        }
                        var s = goal as Symbol;
                        if (s != null)
                        {
                            var goalArgs = new object[args.Length - 1];
                            Array.Copy(args, 1, goalArgs, 0, args.Length - 1);

                            return IgnoreCuts(context.KnowledgeBase.Prove(s, goalArgs, context, context.CurrentFrame));
                        }
                        throw new ArgumentException("Argument to call must be a valid subgoal.");
                    }
            }
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:36,代码来源:PrologPrimitives.cs

示例10: CheckImplementation

 private static IEnumerable<CutState> CheckImplementation(object[] args, PrologContext context)
 {
     if (args.Length != 1)
         throw new ArgumentCountException("check", args, "goal");
     using (var e = context.Prove(args[0], "Goal to check is not a valid Prolog goal.").GetEnumerator())
     {
         if (e.MoveNext())
             yield return CutState.Continue;
         else
             throw new InvalidOperationException("Check failed: " + ISOPrologWriter.WriteToString(args[0]));
     }
 }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:12,代码来源:PrologPrimitives.cs

示例11: CallWithStepLimitImplementation

        private static IEnumerable<CutState> CallWithStepLimitImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 2) throw new ArgumentCountException("call_with_step_limit", args, "max_steps", ":goal");
            object arg = Term.Deref(args[0]);
            var v = arg as LogicVariable;
            if (v != null)
                throw new InstantiationException(v, "first argument to call_with_step_limit/2 must be instantiated to an integer.");

            int newStepLimit = Convert.ToInt32(arg);
            int previousLimit = context.StepLimit;
            int previousRemaining = context.StepsRemaining;
            context.StepLimit = newStepLimit;
            context.StepsRemaining = newStepLimit;
#pragma warning disable 0168
                // ReSharper disable once UnusedVariable
                foreach (var ignore in context.Prove(args[1], "Argument to step_limit/2 must be a valid goal"))
#pragma warning restore 0168
                {
                    yield return CutState.Continue;
                }
            context.StepLimit = previousLimit;
            context.StepsRemaining = previousRemaining;
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:23,代码来源:PrologPrimitives.cs

示例12: ArgMinImplementation

        private static IEnumerable<CutState> ArgMinImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 3) throw new ArgumentCountException("arg_min", args, "template", "score", "goal");
            object template = Term.Deref(args[0]);
            object score = Term.Deref(args[1]);
            float bestScore = 0;
            object bestObj = null;
            bool gotOne = false;
#pragma warning disable 414, 168, 219
            // ReSharper disable UnusedVariable
            foreach (var ignore in context.Prove(args[2], "Goal argument to arg_min must be a valid Prolog goal."))
            // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
            {
                float newScore = Convert.ToSingle(Term.Deref(score));
                if (!gotOne || newScore < bestScore)
                {
                    gotOne = true;
                    bestScore = newScore;
                    bestObj = Term.CopyInstantiation(template);
                }
            }
            if (gotOne)
            {
#pragma warning disable 414, 168, 219
                // ReSharper disable UnusedVariable
                foreach (var ignore in Term.Unify(score, bestScore))
                    foreach (var ignore2 in Term.Unify(template, bestObj))
                        // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
                        yield return CutState.Continue;
            }
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:33,代码来源:PrologPrimitives.cs

示例13: SumallImplementation

        private static IEnumerable<CutState> SumallImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 3) throw new ArgumentCountException("sumall", args, "numberVar", "generator", "sum");
            var numberVar = Term.Deref(args[0]) as LogicVariable;
            if (numberVar == null)
                throw new ArgumentTypeException("sumall", "numberVar", args[0], typeof(LogicVariable));
            //object bag = null;
            double sum = 0;
#pragma warning disable 414, 168, 219
            // ReSharper disable UnusedVariable
            foreach (var ignore in context.Prove(args[1], "goal argument to findall must be a valid Prolog goal."))
            // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
            {
                sum += Convert.ToDouble(numberVar.Value);
            }
            return Term.UnifyAndReturnCutState(args[2], sum);
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:18,代码来源:PrologPrimitives.cs

示例14: SolutionList

        private static List<object> SolutionList(PrologContext context, object template, object goal, int maxSolutions, bool deleteDuplicates)
        {
            var bag = new List<object>();
#pragma warning disable 414, 168, 219
            // ReSharper disable UnusedVariable
            foreach (var ignore in context.Prove(goal, "goal argument to findall must be a valid Prolog goal."))
                // ReSharper restore UnusedVariable
#pragma warning restore 414, 168, 219
            {
                object instance = Term.CopyInstantiation(template);
                bag.Add(instance);
                if (--maxSolutions <= 0)
                    break;
            }
            if (deleteDuplicates)
                Term.Sort(bag, true);
            return bag;
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:18,代码来源:PrologPrimitives.cs

示例15: OnceImplementation

        private static IEnumerable<CutState> OnceImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 1) throw new ArgumentCountException("once", args, "goal");
#pragma warning disable 414, 168, 219
            // ReSharper disable UnusedVariable
            foreach (var ignore in context.Prove(args[0], "Argument to once/1 must be a valid subgoal."))
#pragma warning restore 414, 168, 219
            {
                // ReSharper restore UnusedVariable
                yield return CutState.Continue;
                yield break;
            }
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:13,代码来源:PrologPrimitives.cs


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