private void WalkGoal(KnowledgeBase kb, KnowledgeBaseRule rule, object goal) { goal = Term.Deref(goal); var atom = goal as Symbol; if (atom != null) { var p = new PredicateIndicator(atom, 0); if (PrologPrimitives.IsDefined(p)) { return; } var predicate = kb.CheckForPredicateInfo(p); if (predicate == null) { rule.PrintWarning("undefined predicate {0}", p); } else { MarkReferenced(predicate); } } else { var s = goal as Structure; if (s != null) { WalkGoal(kb, rule, s); } else if (!(goal is LogicVariable) && !(goal is bool)) { rule.PrintWarning("malformed goal: {0}", goal); } } }
PredicateInfo CheckForPredicateInfoInThisKB(PredicateIndicator p) { PredicateInfo entry; if (!db.TryGetValue(p, out entry)) return null; return entry; }
public void DeclareUntraced(PredicateIndicator p) { if (CheckForPredicateInfoInThisKB(p) != null) EntryForStoring(p).Trace = false; else if (this.Parent != null) this.Parent.DeclareTraced(p); else throw new UndefinedPredicateException(p); }
public void DeclareHigherOrderArguments(PredicateIndicator p, int[] arguments) { foreach (var i in arguments) if (i>=p.Arity) throw new ArgumentException("Argument index larger than arity of predicate: "+i); else if (i < 0) throw new ArgumentException("Argument index cannot be less than zero: " + i); EntryForStoring(p).HigherOrderArguments = arguments; }
internal PredicateInfo EntryForStoring(PredicateIndicator p) { PredicateInfo entry; if (!db.TryGetValue(p, out entry)) { db[p] = entry = new PredicateInfo(p.Functor, p.Arity, this); } return entry; }
internal PredicateInfo CheckForPredicateInfo(PredicateIndicator p) { PredicateInfo info = CheckForPredicateInfoInThisKB(p); if (info != null) return info; foreach (KnowledgeBase import in imports) if ((info = import.CheckForPredicateInfo(p)) != null) return info; return null; }
static PredicateInfo GetPredicateInfo(KnowledgeBase kb, PredicateIndicator p) { PredicateInfo result; if ((result = kb.CheckForPredicateInfoInThisKB(p)) != null) return result; foreach (KnowledgeBase import in kb.imports) if ((result = GetPredicateInfo(import, p)) != null) return result; return null; }
/// <summary> /// True if the specified functor/arity is undefined. /// </summary> public bool Undefined(PredicateIndicator p) { if (PrologPrimitives.IsDefined(p)) return false; if (CheckForPredicateInfoInThisKB(p) != null) return false; foreach (KnowledgeBase import in imports) if (!import.Undefined(p)) return false; return true; }
PredicateInfo CheckForPredicateInfoInThisKB(PredicateIndicator p) { PredicateInfo entry; if (!db.TryGetValue(p, out entry)) { return(null); } return(entry); }
public string SourceFor(PredicateIndicator p) { // ReSharper disable once NotResolvedInText if (p.Functor == null) throw new ArgumentNullException("functor"); var s = new StringWriter(); var writer = new ISOPrologWriter(s); var predicateInfo = CheckForPredicateInfo(p); if (predicateInfo == null) throw new ArgumentException(string.Format("Unknown predicate: {0}.", p)); SourceFromPredicateInfo(p, predicateInfo, writer); return s.ToString(); }
internal PredicateInfo CheckForPredicateInfo(PredicateIndicator p) { PredicateInfo info = CheckForPredicateInfoInThisKB(p); if (info != null) { return(info); } foreach (KnowledgeBase import in imports) { if ((info = import.CheckForPredicateInfo(p)) != null) { return(info); } } return(null); }
static PredicateInfo GetPredicateInfo(KnowledgeBase kb, PredicateIndicator p) { PredicateInfo result; if ((result = kb.CheckForPredicateInfoInThisKB(p)) != null) { return(result); } foreach (KnowledgeBase import in kb.imports) { if ((result = GetPredicateInfo(import, p)) != null) { return(result); } } return(null); }
private static void SourceFromPredicateInfo(PredicateIndicator p, PredicateInfo predicateInfo, ISOPrologWriter writer) { foreach (var knowledgeBaseEntry in predicateInfo.Entries) { var rule = (KnowledgeBaseRule)knowledgeBaseEntry; var head = new Structure(p.Functor, rule.HeadArgs); Structure structure; if (rule.BodyGoals == null || rule.BodyGoals.Length == 0) { structure = head; } else { structure = new Structure(Symbol.Implication, head, Commafy(rule.BodyGoals)); } writer.Write(structure); writer.WriteString(".\n"); } }
/// <summary> /// True if the specified functor/arity is undefined. /// </summary> public bool Undefined(PredicateIndicator p) { if (PrologPrimitives.IsDefined(p)) { return(false); } if (CheckForPredicateInfoInThisKB(p) != null) { return(false); } foreach (KnowledgeBase import in imports) { if (!import.Undefined(p)) { return(false); } } return(true); }
private void WalkGoal(KnowledgeBase kb, KnowledgeBaseRule rule, object goal) { goal = Term.Deref(goal); var atom = goal as Symbol; if (atom != null) { var p = new PredicateIndicator(atom, 0); if (PrologPrimitives.IsDefined(p)) return; var predicate = kb.CheckForPredicateInfo(p); if (predicate == null) rule.PrintWarning("undefined predicate {0}", p); else MarkReferenced(predicate); } else { var s = goal as Structure; if (s != null) WalkGoal(kb, rule, s); else if (!(goal is LogicVariable) && !(goal is bool)) rule.PrintWarning("malformed goal: {0}", goal); } }
public void DeclareExternal(PredicateIndicator p) { EntryForStoring(p).External = true; }
public void Compile(PredicateIndicator p) { EntryForStoring(p).Compile(); }
public void Disassemble(PredicateIndicator p) { EntryForStoring(p).Disassemble(); }
/// <summary> /// True if there is a primitive with this functor and arity. /// </summary> internal static bool IsDefined(PredicateIndicator p) { int min; return MinimumArity.TryGetValue(p.Functor, out min) && p.Arity >= min && p.Arity <= MaximumArity[p.Functor]; }
internal List<KnowledgeBaseEntry> EntryListForStoring(PredicateIndicator p) { return EntryForStoring(p).Entries; }
public void DeclareShadow(PredicateIndicator p) { EntryForStoring(p).Shadow = true; }
public void DeclarePublic(PredicateIndicator p) { EntryForStoring(p).Public = true; }
public void DeclareRandomizable(PredicateIndicator p) { EntryForStoring(p).Randomizable = true; }
internal List <KnowledgeBaseEntry> EntryListForStoring(PredicateIndicator p) { return(EntryForStoring(p).Entries); }
public void Forget(PredicateIndicator p) { EntryListForStoring(p).Clear(); }
/// <summary> /// Thrown to signal that a predicate used as a goal does not appear in the database. /// </summary> public UndefinedPredicateException(PredicateIndicator p) { Predicate = p; }