本文整理汇总了C#中Structure.IsFunctor方法的典型用法代码示例。如果您正苦于以下问题:C# Structure.IsFunctor方法的具体用法?C# Structure.IsFunctor怎么用?C# Structure.IsFunctor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Structure
的用法示例。
在下文中一共展示了Structure.IsFunctor方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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);
}
}