本文整理汇总了C#中Prolog.LogicVariable类的典型用法代码示例。如果您正苦于以下问题:C# LogicVariable类的具体用法?C# LogicVariable怎么用?C# LogicVariable使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LogicVariable类属于Prolog命名空间,在下文中一共展示了LogicVariable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrologContext
/// <summary>
/// Creates a PrologContext that can for at most the specified number of steps.
/// </summary>
public PrologContext(KnowledgeBase kb, int stepLimit)
{
StepsRemaining = stepLimit;
goalStack = new List<GoalStackFrame>();
goalStackCurrentRules = new List<KnowledgeBaseEntry>();
GoalStackDepth = 0;
KnowledgeBase = kb;
traceVariables = new LogicVariable[256];
traceValues = new object[256];
tracePointer = 0;
IndexicalBindingStack = new List<KeyValuePair<Symbol, object>>();
isFree = true;
}
示例2: 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;
}
示例3: MetaVarUnify
/// <summary>
/// Called after the variable bound to this Metastructure is unified with an unbound variable
/// that is not (itself) bound to a Metastructure.
/// </summary>
/// <param name="them">The logic variable with which to unify</param>
/// <param name="filter">Test for whether the merging succeeded. Generally a woken goal.</param>
/// <returns>The Metastructure to bind to the newly aliased variables.</returns>
public Metastructure MetaVarUnify(LogicVariable them, out IEnumerable<CutState> filter)
{
filter = Prover(DelayedGoal);
return MakeSuspension(null, FrozenGoal);
}
示例4: TryNonExclusiveQuery
private static bool TryNonExclusiveQuery(out ELNode foundNode, out ELNodeEnumerator enumerator, ELNode parentNode, object key, LogicVariable v, ELNodeEnumerator parentEnumerator)
{
if (parentNode != null)
{
return TryNonExclusiveQueryDeterministicParent(out foundNode, out enumerator, parentNode, key, v);
}
return TryNonExclusiveQueryEnumeratedParent(out foundNode, out enumerator, key, v, parentEnumerator);
}
示例5: BindsVar
public override bool BindsVar(LogicVariable v)
{
return parentEnumerator.BindsVar(v);
}
示例6: SolveFor
/// <summary>
/// Finds the value of result in the first solution when proving goal within this Component's GameObject's knowledge base.
/// </summary>
/// <param name="gameObject">GameObject whose KB should be queried.</param>
/// <param name="result">Value of the variable to solve for</param>
/// <param name="functor">Functor of the goal.</param>
/// <param name="args">Arguments for the goal.</param>
/// <returns>Value found for the variable.</returns>
public static object SolveFor(this GameObject gameObject, LogicVariable result, string functor, params object[] args)
{
return gameObject.SolveFor(result, new Structure(functor, args));
}
示例7: TryNonExclusiveQueryEnumeratedParent
private static bool TryNonExclusiveQueryEnumeratedParent(
out ELNode foundNode,
out ELNodeEnumerator enumerator,
object key,
LogicVariable v,
ELNodeEnumerator parentEnumerator)
{
// Enumerated parent path
// NonUniqueParent/Something
foundNode = null;
if (v == null)
{
// NonUniqueParent/Key
// Enumerate parent, then do deterministic lookup for child.
enumerator = new ELNodeEnumeratorFixedChildFromParentEnumerator(parentEnumerator, key);
return true;
}
if (parentEnumerator.BindsVar(v))
{
// We're doing a search for a variable that's aready bound.
enumerator = new ELNodeEnumeratorPreboundVariable(parentEnumerator, v, false);
return true;
}
// NonUniqueParent/Variable
// Enumerate both parent and child.
enumerator = new ELNodeEnumeratorLogicVariableFromParentEnumerator(parentEnumerator, v);
return true;
}
示例8: Prove
internal override IEnumerable<CutState> Prove(object[] args, PrologContext context, ushort parentFrame)
{
object[] goal1Args = null;
object[] goal2Args = null;
object[] goal3Args = null;
object[] goal4Args = null;
object[] goal5Args = null;
object[] goal6Args = null;
object[] goal7Args = null;
object[] goal8Args = null;
var newVars = new LogicVariable[FreeVariables.Count];
object[] newArgs = Term.AlphaConvertArglist(HeadArgs, FreeVariables, newVars, context, true);
// ReSharper disable UnusedVariable
foreach (bool ignore in Term.UnifyArraysFast(args, newArgs, context))
{
if (goal1Args == null)
goal1Args = Term.AlphaConvertArglist(BodyGoals[0].Arguments, FreeVariables, newVars, context, false);
foreach (CutState ignoreFreeze in context.ProveAllWokenGoals())
// ReSharper restore UnusedVariable
foreach (CutState state1 in context.KnowledgeBase.Prove(BodyGoals[0].Functor, goal1Args, context, parentFrame))
{
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))
{
if (state2 == CutState.ForceFail) yield return CutState.ForceFail;
if (goal3Args == null)
goal3Args = Term.AlphaConvertArglist(BodyGoals[2].Arguments, FreeVariables, newVars, context, false);
foreach (CutState state3 in context.KnowledgeBase.Prove(BodyGoals[2].Functor, goal3Args, context, parentFrame))
{
if (state3 == CutState.ForceFail) yield return CutState.ForceFail;
if (goal4Args == null)
goal4Args = Term.AlphaConvertArglist(BodyGoals[3].Arguments, FreeVariables, newVars, context, false);
foreach (CutState state4 in context.KnowledgeBase.Prove(BodyGoals[3].Functor, goal4Args, context, parentFrame))
{
if (state4 == CutState.ForceFail) yield return CutState.ForceFail;
if (goal5Args == null)
goal5Args = Term.AlphaConvertArglist(BodyGoals[4].Arguments, FreeVariables, newVars, context, false);
foreach (CutState state5 in context.KnowledgeBase.Prove(BodyGoals[4].Functor, goal5Args, context, parentFrame))
{
if (state5 == CutState.ForceFail) yield return CutState.ForceFail;
if (goal6Args == null)
goal6Args = Term.AlphaConvertArglist(BodyGoals[5].Arguments, FreeVariables, newVars, context, false);
foreach (CutState state6 in context.KnowledgeBase.Prove(BodyGoals[5].Functor, goal6Args, context, parentFrame))
{
if (state6 == CutState.ForceFail) yield return CutState.ForceFail;
if (goal7Args == null)
goal7Args = Term.AlphaConvertArglist(BodyGoals[6].Arguments, FreeVariables, newVars, context, false);
foreach (CutState state7 in context.KnowledgeBase.Prove(BodyGoals[6].Functor, goal7Args, context, parentFrame))
{
if (state7 == CutState.ForceFail) yield return CutState.ForceFail;
if (goal8Args == null)
goal8Args = Term.AlphaConvertArglist(BodyGoals[7].Arguments, FreeVariables, newVars, context, false);
foreach (CutState state8 in context.KnowledgeBase.Prove(BodyGoals[7].Functor, goal8Args, context, parentFrame))
{
yield return state8;
}
}
}
}
}
}
}
}
}
}
示例9: ELNodeEnumeratorEnumerateParentAndBindVariable
public ELNodeEnumeratorEnumerateParentAndBindVariable(ELNodeEnumerator parentEnumerator, LogicVariable variable)
{
this.parentEnumerator = parentEnumerator;
this.variable = variable;
}
示例10: InstantiationException
/// <summary>
/// Indicates a variable that should/shouldn't be bound isn't/is bound
/// </summary>
public InstantiationException(LogicVariable offendingVariable, string message)
: base(message)
{
Variable = offendingVariable;
}
示例11: ELNodeEnumeratorBindFixedNodeToVariable
public ELNodeEnumeratorBindFixedNodeToVariable(ELNode node, LogicVariable variableToBind)
{
this.node = node;
this.variableToBind = variableToBind;
}
示例12: ELNodeEnumeratorBindEnumeratedNodesToVariable
public ELNodeEnumeratorBindEnumeratedNodesToVariable(ELNodeEnumerator nodeEnumerator, LogicVariable variableToBind)
{
this.nodeEnumerator = nodeEnumerator;
this.variableToBind = variableToBind;
if (nodeEnumerator.BindsVar(variableToBind))
throw new InvalidOperationException("Variable appears on both the LHS and RHS of >>: "+ variableToBind.Name);
}
示例13: ELNodeEnumeratorBindAndUnbindVariable
public ELNodeEnumeratorBindAndUnbindVariable(ELNode child, LogicVariable v)
{
this.child = child;
this.variable = v;
}
示例14: 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);
示例15: TryNonExclusiveQueryDeterministicParent
private static bool TryNonExclusiveQueryDeterministicParent(
out ELNode foundNode,
out ELNodeEnumerator enumerator,
ELNode parentNode,
object key,
LogicVariable v)
{
// Deterministic parent path
// The expression is UniqueParent/Something
if (parentNode.IsExclusive)
{
throw new ELNodeExclusionException("Non-exclusive query of an exclusive node", parentNode, key);
}
if (v == null)
{
// fully deterministic path
// UniqueParent/Key corresponds to at most one ELNode.
enumerator = null;
return parentNode.TryLookup(key, out foundNode);
}
// UniqueParent/Variable, so do a singly-nested iteration.
foundNode = null;
enumerator = new ELNodeEnumeratorLogicVariableFromNode(parentNode, v);
return true;
}