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


C# Prolog.PrologContext类代码示例

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


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

示例1: TryChildQuery

        public static bool TryChildQuery(
            out ELNode foundNode,
            out ELNodeEnumerator enumerator,
            object parentExpression,
            object keyExpression,
            bool isExclusive,
            PrologContext context)
        {
            // Decode the parent expression
            ELNode parentNode;
            ELNodeEnumerator parentEnumerator;
            if (!TryQuery(parentExpression, context, out parentNode, out parentEnumerator))
            {
                // Parent failed, so we fail
                enumerator = null;
                foundNode = null;
                return false;
            }

            //
            // Decode the key argument
            //
            var key = keyExpression;
            var v = key as LogicVariable;

            return isExclusive?TryExclusiveQuery(out foundNode, out enumerator, parentNode, parentEnumerator, key, v)
                : TryNonExclusiveQuery(out foundNode, out enumerator, parentNode, key, v, parentEnumerator);
        }
开发者ID:jcc333,项目名称:MKULTRA,代码行数:28,代码来源:ELProlog.cs

示例2: TryQuery

        public static bool TryQuery(object term, PrologContext context, out ELNode foundNode, out ELNodeEnumerator enumerator)
        {
            // Dereference any top-level variables.
            var t = Term.Deref(term);

            // Dereference indexicals
            var i = t as Indexical;
            if (i != null)
                t = i.GetValue(context);

            // A game object means the gameobject's EL KB.
            var g = t as GameObject;
            if (g != null)
                t = g.KnowledgeBase().ELRoot;

            // If it's already an ELNode, use that.
            var n = t as ELNode;
            if (n != null)
            {
                foundNode = n;
                enumerator = null;
                return true;
            }

            // Otherwise, it's an expression, so evaluate it.
            var s = t as Structure;
            if (s != null)
                return TryQueryStructure(s, context, out foundNode, out enumerator);

            var v = t as LogicVariable;
            if (v != null && !v.IsBound)
                throw new Exception("EL query root is an unbound variable: " + v);
            throw new Exception("Malformed EL query: " + ISOPrologWriter.WriteToString(term));
        }
开发者ID:jcc333,项目名称:MKULTRA,代码行数:34,代码来源:ELProlog.cs

示例3: SetImplementation

        internal static IEnumerable<CutState> SetImplementation(object[] args, PrologContext context)
        {
            if (args.Length != 2) throw new ArgumentCountException("set", args, new object[] { "Variable", "NewValue"});

            object value = Term.CopyInstantiation(args[1]);
            if (value is LogicVariable) throw new UninstantiatedVariableException((LogicVariable)args[1], "Value argument should be a data object, not an uninstantiated (unbound) variable.");
            var functor = Term.Deref(args[0]) as Symbol;
            if (functor == null) throw new ArgumentTypeException("set", "functor", args[0], typeof (Symbol));

            List<KnowledgeBaseEntry> entries = context.KnowledgeBase.EntryListForStoring(new PredicateIndicator(functor, 1));

            switch (entries.Count)
            {
                case 0:
                    entries.Add(new KnowledgeBaseVariable(value));
                    return CutStateSequencer.Succeed();

                case 1:
                    var v = entries[0] as KnowledgeBaseVariable;
                    if (v==null)
                        throw new ArgumentException("Functor is not a variable; it has another entry defined for it.");
                    v.CurrentValue = value;
                    return CutStateSequencer.Succeed();

                default:
                    throw new ArgumentException("Functor is not a variable; it has multiple entries defined for it.");
            }
        }
开发者ID:rzubek,项目名称:UnityProlog,代码行数:28,代码来源:KnowledgeBaseVariable.cs

示例4: TryQueryStructure

        public static bool TryQueryStructure(
            Structure term,
            PrologContext context,
            out ELNode foundNode,
            out ELNodeEnumerator enumerator)
        {
            //
            // Dispatch based on the functor and arity.
            //

            // Handle root queries, i.e. /Key
            if (term.IsFunctor(Symbol.Slash, 1))
                return TryRootQuery(term, context, out foundNode, out enumerator);

            if (!IsELTerm(term))
                throw new Exception("Malformed EL query: " + ISOPrologWriter.WriteToString(term));

            if (term.IsFunctor(SBindNodeOperator, 2))
            {
                var variableToBind = term.Argument(1) as LogicVariable;
                if (variableToBind == null)
                    throw new ArgumentException("RHS of >> must be an uninstantiated variable: "+ ISOPrologWriter.WriteToString(term.Argument(1)));
                foundNode = null;
                return TryNodeBindingQuery(out enumerator, term.Argument(0), variableToBind, context);
            }

            return TryChildQuery(
                out foundNode,
                out enumerator,
                term.Argument(0),
                term.Argument(1),
                term.Functor == Symbol.Colon,
                context);
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:34,代码来源:ELProlog.cs

示例5: MetaMetaUnify

        internal override Metastructure MetaMetaUnify(Metastructure theirMetaStructure, PrologContext context)
        {
            var s = theirMetaStructure as Suspension;
            if (s == null) throw new ArgumentTypeException("MetaMetaUnify", "theirMetaStructure", theirMetaStructure, typeof(Suspension));
            if (context != s.context) throw new ArgumentException("Can't unify suspended goals across PrologContexts.");

            context.WakeUpGoal(CombineGoals(DelayedGoal, s.DelayedGoal));
            return MakeSuspension(null, CombineGoals(FrozenGoal, s.FrozenGoal));
        }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:9,代码来源:Metastructure.cs

示例6: TryNodeBindingQuery

 public static bool TryNodeBindingQuery(
     out ELNodeEnumerator enumerator,
     object nodeExpression,
     LogicVariable variableToBind,
     PrologContext context)
 {
     // Decode the node expression
     ELNode foundNode;
     ELNodeEnumerator nodeEnumerator;
     if (!TryQuery(nodeExpression, context, out foundNode, out nodeEnumerator))
     {
         // Parent failed, so we fail
         enumerator = null;
         return false;
     }
     enumerator = (foundNode != null)
         ? (ELNodeEnumerator)new ELNodeEnumeratorBindFixedNodeToVariable(foundNode, variableToBind)
         : new ELNodeEnumeratorBindEnumeratedNodesToVariable(nodeEnumerator, variableToBind);
     return true;
 }
开发者ID:jcc333,项目名称:MKULTRA,代码行数:20,代码来源:ELProlog.cs

示例7: MapListImplementation

 private static IEnumerable<CutState> MapListImplementation(object[] args, PrologContext context)
 {
     if (args.Length != 3)
         throw new ArgumentCountException("maplist", args, "predicate", "list1", "list2");
     object predicate = Term.Deref(args[0]);
     var functor = predicate as Symbol;
     object[] arguments;
     if (functor != null)
     {
         arguments = NoArgs;
     }
     else
     {
         var t = predicate as Structure;
         if (t != null)
         {
             functor = t.Functor;
             arguments = t.Arguments;
         }
         else
             throw new ArgumentTypeException("maplist", "predicate", predicate, typeof (Symbol));
     }
     return MapListInternal(functor, arguments, args[1], args[2], context);
 }
开发者ID:rzubek,项目名称:MKULTRA,代码行数:24,代码来源:PrologPrimitives.cs

示例8: 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

示例9: TryRootQuery

        private static bool TryRootQuery(Structure term, PrologContext context, out ELNode foundNode, out ELNodeEnumerator enumerator)
        {
            // Expression is /Key.
            var arg0 = term.Argument(0);

            // This is a "/constant" expression, i.e. a top-level lookup.
            if (arg0 is LogicVariable)
            {
                throw new NotImplementedException("Lookups of the form /Variable are not supported.");
            }
            enumerator = null;
            return context.KnowledgeBase.ELRoot.TryLookup(arg0, out foundNode);
        }
开发者ID:jcc333,项目名称:MKULTRA,代码行数:13,代码来源:ELProlog.cs

示例10: 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

示例11: RetractAll

 internal static void RetractAll(object term, PrologContext context)
 {
     ELNode foundNode;
     ELNodeEnumerator enumerator;
     if (!TryQuery(term, context, out foundNode, out enumerator))
         return;
     if (foundNode != null)
         foundNode.DeleteSelf();
     else
         while (enumerator.MoveNext()) enumerator.Current.DeleteSelf();
 }
开发者ID:jcc333,项目名称:MKULTRA,代码行数:11,代码来源:ELProlog.cs

示例12: AlphaConvert

 /// <summary>
 /// Recopy the term to replace variables.  If term contains no variables, no recopying is done.
 /// </summary>
 /// <param name="oldVars">Variables to be replaced</param>
 /// <param name="newVars">The corresponding variables that are replacing the oldVars</param>
 /// <param name="context">PrologContext to evaluating indexicals</param>
 /// <param name="evalIndexicals">If true, any indexicals will be replaced with their values.</param>
 /// <returns>Converted term or original term if not conversion necessary</returns>
 public abstract object AlphaConvert(
     List<LogicVariable> oldVars,
     LogicVariable[] newVars,
     PrologContext context,
     bool evalIndexicals);
开发者ID:rzubek,项目名称:UnityProlog,代码行数:13,代码来源:AlphaConvertibleTerm.cs

示例13: Prove

        internal override IEnumerable<CutState> Prove(object[] args, PrologContext context, ushort parentFrame)
        {
            object[] goal1Args = null;
            object[] goal2Args = null;
            var newVars = new LogicVariable[FreeVariables.Count];
            object[] newArgs = Term.AlphaConvertArglist(HeadArgs, FreeVariables, newVars, context, true);
            // ReSharper disable UnusedVariable
            #pragma warning disable 414, 168, 219
            foreach (bool ignore in Term.UnifyArraysFast(args, newArgs, context))
            #pragma warning restore 414, 168, 219
            {
                if (goal1Args == null)
                    goal1Args = Term.AlphaConvertArglist(BodyGoals[0].Arguments, FreeVariables, newVars, context, false);

            #pragma warning disable 414, 168, 219
                foreach (CutState ignoreFreeze in context.ProveAllWokenGoals())
                    // ReSharper restore UnusedVariable
                    foreach (CutState state1 in context.KnowledgeBase.Prove(BodyGoals[0].Functor, goal1Args, context, parentFrame))
            #pragma warning restore 414, 168, 219
                    {
                    if (state1 == CutState.ForceFail) yield return CutState.ForceFail;
                    if (goal2Args == null)
                        goal2Args = Term.AlphaConvertArglist(BodyGoals[1].Arguments, FreeVariables, newVars, context, false);

                    foreach (CutState state2 in context.KnowledgeBase.Prove(BodyGoals[1].Functor, goal2Args, context, parentFrame))
                        yield return state2;
                }
            }
        }
开发者ID:ianhorswill,项目名称:UnityProlog,代码行数:29,代码来源:KnowledgeBaseRule.cs

示例14: MetaTermUnify

 /// <summary>
 /// Called after the variable bound to this Metastructure is unified with a non-variable term.
 /// </summary>
 /// <param name="value">The term to which to unify</param>
 /// <param name="contextOfBinding">Context in which to execute suspended goals.</param>
 public void MetaTermUnify(object value, PrologContext contextOfBinding)
 {
     Debug.Assert(contextOfBinding == Context, "Delayed goal woken in a different context than it was created in.");
     contextOfBinding.WakeUpGoal(CombineGoals(DelayedGoal, FrozenGoal));
 }
开发者ID:ianhorswill,项目名称:UnityProlog,代码行数:10,代码来源:Metastructure.cs

示例15: Metastructure

 /// <summary>
 /// Create a new set of suspended goals.
 /// </summary>
 /// <param name="delayedGoal">Goal to run upon unification with any value.</param>
 /// <param name="frozenGoal">Goal to run upon unification with a non-variable term.</param>
 /// <param name="prologContext">Context in which to run goals.</param>
 public Metastructure(Structure delayedGoal, Structure frozenGoal, PrologContext prologContext)
 {
     DelayedGoal = delayedGoal;
     FrozenGoal = frozenGoal;
     Context = prologContext;
 }
开发者ID:ianhorswill,项目名称:UnityProlog,代码行数:12,代码来源:Metastructure.cs


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