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

            return entry;
        }
Exemple #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);
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #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;
 }
Exemple #9
0
        PredicateInfo CheckForPredicateInfoInThisKB(PredicateIndicator p)
        {
            PredicateInfo entry;

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

            return(entry);
        }
Exemple #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();
 }
Exemple #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);
        }
Exemple #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);
        }
Exemple #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");
     }
 }
Exemple #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);
 }
Exemple #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);
     }
 }
 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;
 }
 public void DeclareExternal(PredicateIndicator p)
 {
     EntryForStoring(p).External = true;
 }
 public void Compile(PredicateIndicator p)
 {
     EntryForStoring(p).Compile();
 }
Exemple #19
0
 public void Disassemble(PredicateIndicator p)
 {
     EntryForStoring(p).Disassemble();
 }
Exemple #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];
 }
 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");
     }
 }
 internal List<KnowledgeBaseEntry> EntryListForStoring(PredicateIndicator p)
 {
     return EntryForStoring(p).Entries;
 }
 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;
 }
 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();
 }
 public void Disassemble(PredicateIndicator p)
 {
     EntryForStoring(p).Disassemble();
 }
 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;
 }
Exemple #29
0
 internal List <KnowledgeBaseEntry> EntryListForStoring(PredicateIndicator p)
 {
     return(EntryForStoring(p).Entries);
 }
 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);
 }
Exemple #31
0
 public void Forget(PredicateIndicator p)
 {
     EntryListForStoring(p).Clear();
 }
 public void Forget(PredicateIndicator p)
 {
     EntryListForStoring(p).Clear();
 }
Exemple #33
0
 public void DeclareRandomizable(PredicateIndicator p)
 {
     EntryForStoring(p).Randomizable = true;
 }
 /// <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;
 }
Exemple #35
0
 public void DeclareShadow(PredicateIndicator p)
 {
     EntryForStoring(p).Shadow = true;
 }
 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;
 }
Exemple #37
0
 public void DeclareExternal(PredicateIndicator p)
 {
     EntryForStoring(p).External = true;
 }
 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;
 }
Exemple #39
0
 public void DeclarePublic(PredicateIndicator p)
 {
     EntryForStoring(p).Public = true;
 }
        PredicateInfo CheckForPredicateInfoInThisKB(PredicateIndicator p)
        {
            PredicateInfo entry;
            if (!db.TryGetValue(p, out entry))
                return null;

            return entry;
        }
Exemple #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;
 }