本文整理汇总了C#中Structure.Argument方法的典型用法代码示例。如果您正苦于以下问题:C# Structure.Argument方法的具体用法?C# Structure.Argument怎么用?C# Structure.Argument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Structure
的用法示例。
在下文中一共展示了Structure.Argument方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: FromTerm
/// <summary>
/// Creates a KnowledgedBaseRule given a Term object for a :- expression.
/// </summary>
public static KnowledgeBaseRule FromTerm(Structure structure, bool checkSingletons, string source, int line)
{
if (structure == null) throw new ArgumentNullException("structure");
if (structure.IsFunctor(Symbol.Implication, 2))
{
var body = new List<Structure>();
UnwindCommaExpression(structure.Argument(1), body);
if (structure.Argument(0) == null)
throw new ArgumentException("head of rule is null");
Structure head = Term.Structurify(structure.Argument(0), "Head of :- must be a valid proposition or predicate.");
if (head == null)
throw new ArgumentException("Head of rule is not a term.");
return MakeRule(head, body, checkSingletons, source, line);
}
return MakeRule(structure, null, checkSingletons, source, line);
}
示例3: 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);
}
示例4: UpdateStructure
public static ELNode UpdateStructure(Structure term, KnowledgeBase knowledgeBase)
{
if (term.Functor == Symbol.Slash)
{
if (term.Arity == 1)
return knowledgeBase.ELRoot.StoreNonExclusive(Term.CopyInstantiation(term.Argument(0)));
return Update(term.Argument(0), knowledgeBase).StoreNonExclusive(Term.CopyInstantiation(term.Argument(1)));
}
if (term.Functor == Symbol.Colon)
{
return Update(term.Argument(0), knowledgeBase).StoreExclusive(Term.CopyInstantiation(term.Argument(1)), true);
}
throw new Exception("Malformed EL assertion: "+ISOPrologWriter.WriteToString(term));
}
示例5: Assert
/// <summary>
/// Add a term (fact or rule) to the KB.
/// </summary>
public void Assert(Structure structure, bool atEnd, bool checkSingletons)
{
if (structure == null) throw new ArgumentNullException("structure", "Term to add to KB may not be null.");
//structure = structure.Expand();
if (structure == null) throw new ArgumentNullException("structure");
Structure head = structure.IsFunctor(Symbol.Implication, 2)
? Term.Structurify(structure.Argument(0),
"Head of :- must be a valid proposition or predicate.")
: structure;
if (head.IsFunctor(Symbol.ColonColon, 2))
{
var argument = head.Argument(0);
var kb = argument as KnowledgeBase;
if (kb == null)
{
var o = argument as GameObject;
if (o != null)
kb = o.KnowledgeBase();
else
{
var c = argument as Component;
if (c != null)
kb = c.KnowledgeBase();
else
throw new ArgumentTypeException(
"assert",
"knowledgebase",
argument,
typeof(KnowledgeBase));
}
}
if (structure.IsFunctor(Symbol.Implication, 2))
kb.Assert(
new Structure(Symbol.Implication, head.Argument(1), structure.Argument(1)),
atEnd,
checkSingletons);
else
{
kb.Assert(structure.Argument(1), atEnd, checkSingletons);
}
}
else
{
if (PrologPrimitives.Implementations.ContainsKey(head.Functor))
throw new PrologException(
new Structure(
"error",
new Structure(
"permission_error",
Symbol.Intern("modify"),
Symbol.Intern("static_procedure"),
Term.PredicateIndicatorExpression(head))));
KnowledgeBaseRule assertion = KnowledgeBaseRule.FromTerm(
structure,
checkSingletons,
Prolog.CurrentSourceFile,
Prolog.CurrentSourceLineNumber);
PredicateInfo info = EntryForStoring(head.PredicateIndicator);
PredicateInfo parentInfo;
if (!info.Shadow && this.Parent != null
&& (parentInfo = this.Parent.CheckForPredicateInfoInThisKB(head.PredicateIndicator)) != null
&& !parentInfo.External)
throw new PrologException(
new Structure(
"error",
new Structure(
"permission_error",
Symbol.Intern("shadow"),
Term.PredicateIndicatorExpression(head))));
info.Assert(assertion, atEnd);
}
}
示例6: WalkGoal
private void WalkGoal(KnowledgeBase kb, KnowledgeBaseRule rule, Structure goal)
{
var predicateIndicator = goal.PredicateIndicator;
Symbol functor = goal.Functor;
int arity = goal.Arity;
switch (functor.Name)
{
case "once":
case "check":
case "randomize":
case "not":
case "\\+":
if (arity == 1)
{
WalkGoal(kb, rule, goal.Argument(0));
}
else
WarnUndefined(rule, functor, arity);
break;
case ",":
case ";":
case "->":
if (arity == 2)
{
WalkGoal(kb, rule, goal.Argument(0));
WalkGoal(kb, rule, goal.Argument(1));
}
else
WarnUndefined(rule, functor, arity);
break;
case "call":
case "maplist":
if (arity < 1)
WarnUndefined(rule, functor, arity);
else
{
object goalToCall = goal.Argument(0);
var goalToCallAsStructure = goalToCall as Structure;
if (goalToCallAsStructure != null)
{
var newArgs = new object[arity - 1 + goalToCallAsStructure.Arity];
goalToCallAsStructure.Arguments.CopyTo(newArgs, 0);
WalkGoal(kb, rule, new Structure(goalToCallAsStructure.Functor, newArgs));
}
else
{
var call = goalToCall as Symbol;
if (call != null)
{
this.WalkGoal(kb, rule, new Structure(call, new object[arity - 1]));
}
}
}
break;
case "arg_min":
case "arg_max":
if (arity == 3)
{
WalkGoal(kb, rule, goal.Argument(2));
}
else
WarnUndefined(rule, functor, arity);
break;
case "find_all":
if (arity == 3)
{
WalkGoal(kb, rule, goal.Argument(1));
}
else
WarnUndefined(rule, functor, arity);
break;
default:
if (PrologPrimitives.IsDefined(predicateIndicator))
{
var arglist = PrologPrimitives.Arglist(predicateIndicator.Functor);
for (int i = 0; i < Math.Min(predicateIndicator.Arity,arglist.Count); i++)
{
var argSym = arglist[i] as Symbol;
if (argSym != null)
{
var arg = argSym.Name;
if (arg[0] == ':')
WalkGoal(kb, rule, goal.Argument(i));
else if (arg == "..." && arglist[i - 1] is string && ((string)arglist[i - 1])[0] == ':')
{
// Predicate accepts a rest arg of goals
for (int j = i; j < predicateIndicator.Arity; j++)
WalkGoal(kb, rule, goal.Argument(j));
}
}
}
}
else
{
var predicate = kb.CheckForPredicateInfo(predicateIndicator);
//.........这里部分代码省略.........