示例#1
0
        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);
                }
            }
        }
示例#2
0
        PredicateInfo CheckForPredicateInfoInThisKB(PredicateIndicator p)
        {
            PredicateInfo entry;
            if (!db.TryGetValue(p, out entry))
                return null;

            return entry;
        }
示例#3
0
 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);
 }
示例#4
0
 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;
 }
示例#5
0
 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;
 }
示例#6
0
 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;
 }
示例#7
0
 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;
 }
示例#8
0
 /// <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;
 }
示例#9
0
        PredicateInfo CheckForPredicateInfoInThisKB(PredicateIndicator p)
        {
            PredicateInfo entry;

            if (!db.TryGetValue(p, out entry))
            {
                return(null);
            }

            return(entry);
        }
示例#10
0
 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();
 }
示例#11
0
        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);
        }
示例#12
0
        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);
        }
示例#13
0
 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");
     }
 }
示例#14
0
 /// <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);
 }
示例#15
0
 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);
     }
 }
示例#16
0
 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;
 }
示例#17
0
 public void DeclareExternal(PredicateIndicator p)
 {
     EntryForStoring(p).External = true;
 }
示例#18
0
 public void Compile(PredicateIndicator p)
 {
     EntryForStoring(p).Compile();
 }
示例#19
0
 public void Disassemble(PredicateIndicator p)
 {
     EntryForStoring(p).Disassemble();
 }
示例#20
0
 /// <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];
 }
示例#21
0
 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");
     }
 }
示例#22
0
 internal List<KnowledgeBaseEntry> EntryListForStoring(PredicateIndicator p)
 {
     return EntryForStoring(p).Entries;
 }
示例#23
0
 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;
 }
示例#24
0
 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();
 }
示例#25
0
 public void Disassemble(PredicateIndicator p)
 {
     EntryForStoring(p).Disassemble();
 }
示例#26
0
 public void DeclareShadow(PredicateIndicator p)
 {
     EntryForStoring(p).Shadow = true;
 }
示例#27
0
 public void DeclarePublic(PredicateIndicator p)
 {
     EntryForStoring(p).Public = true;
 }
示例#28
0
 public void DeclareRandomizable(PredicateIndicator p)
 {
     EntryForStoring(p).Randomizable = true;
 }
示例#29
0
 internal List <KnowledgeBaseEntry> EntryListForStoring(PredicateIndicator p)
 {
     return(EntryForStoring(p).Entries);
 }
示例#30
0
 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);
 }
示例#31
0
 public void Forget(PredicateIndicator p)
 {
     EntryListForStoring(p).Clear();
 }
示例#32
0
 public void Forget(PredicateIndicator p)
 {
     EntryListForStoring(p).Clear();
 }
示例#33
0
 public void DeclareRandomizable(PredicateIndicator p)
 {
     EntryForStoring(p).Randomizable = true;
 }
示例#34
0
 /// <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;
 }
示例#35
0
 public void DeclareShadow(PredicateIndicator p)
 {
     EntryForStoring(p).Shadow = true;
 }
示例#36
0
 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;
 }
示例#37
0
 public void DeclareExternal(PredicateIndicator p)
 {
     EntryForStoring(p).External = true;
 }
示例#38
0
 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;
 }
示例#39
0
 public void DeclarePublic(PredicateIndicator p)
 {
     EntryForStoring(p).Public = true;
 }
示例#40
0
        PredicateInfo CheckForPredicateInfoInThisKB(PredicateIndicator p)
        {
            PredicateInfo entry;
            if (!db.TryGetValue(p, out entry))
                return null;

            return entry;
        }
示例#41
0
 public void Compile(PredicateIndicator p)
 {
     EntryForStoring(p).Compile();
 }
 /// <summary>
 /// Thrown to signal that a predicate used as a goal does not appear in the database.
 /// </summary>
 public UndefinedPredicateException(PredicateIndicator p)
 {
     Predicate = p;
 }
 /// <summary>
 /// Thrown to signal that a predicate used as a goal does not appear in the database.
 /// </summary>
 public UndefinedPredicateException(PredicateIndicator p)
 {
     Predicate = p;
 }