コード例 #1
0
 private void WalkRule(KnowledgeBase kb, KnowledgeBaseRule rule)
 {
     foreach (Structure goal in rule.BodyGoals)
     {
         WalkGoal(kb, rule, goal);
     }
 }
コード例 #2
0
ファイル: KnowledgeBase.cs プロジェクト: mantoun/MKULTRA
 public KnowledgeBase(string kbName, GameObject gameObject, KnowledgeBase parent, params KnowledgeBase[] otherImports)
 {
     if (kbName == null)
     {
         throw new ArgumentNullException("kbName");
     }
     Name            = kbName;
     this.Parent     = parent;
     this.GameObject = gameObject;
     this.ELRoot     = new ELNode(null, Symbol.Intern("root"));
     //if (parent == null) throw new ArgumentNullException("parent");
     if (otherImports == null)
     {
         throw new ArgumentNullException("otherImports");
     }
     foreach (var import in otherImports)
     {
         if (import == null)
         {
             throw new ArgumentNullException("otherImports");
         }
     }
     if (parent != null)
     {
         imports.Add(parent);
     }
     imports.AddRange(otherImports);
 }
コード例 #3
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);
                }
            }
        }
コード例 #4
0
ファイル: KB.cs プロジェクト: monadicus/UnityProlog
        private void MakeKB()
        {
            var parent   = transform.parent;
            KB  parentKB = null;

            if (parent != null)
            {
                parentKB = parent.GetComponent <KB>();
            }

            kb = IsGlobal?
                 KnowledgeBase.Global
                : new KnowledgeBase(
                gameObject.name,
                gameObject,
                parentKB == null ? GameObject.Find(GlobalKBGameObjectName).KnowledgeBase()
                                       : parentKB.KnowledgeBase);

            // Add UID counter.
            ELNode.Store(kb.ELRoot / Symbol.Intern("next_uid") % 0);

            try
            {
                foreach (var file in SourceFiles)
                {
                    kb.Consult(ExpandFileName(file));
                }
            }
            catch (Exception)
            {
                Debug.Break(); // Pause the game
                throw;
            }
        }
コード例 #5
0
ファイル: PredicateInfo.cs プロジェクト: rzubek/UnityProlog
 /// <summary>
 /// Creates a blank DB entry for the specified functor
 /// </summary>
 public PredicateInfo(Symbol functorName, int arity, KnowledgeBase kb)
 {
     Name = functorName;
     Arity = arity;
     Entries = new List<KnowledgeBaseEntry>();
     KnowledgeBase = kb;
 }
コード例 #6
0
 void KBChanged(KnowledgeBase newKB)
 {
     var eli = FindObjectOfType<ELInspector>();
     if (eli != null)
         eli.SetKB(newKB);
     WindowTitle = "Prolog console: " + newKB.Name;
 }
コード例 #7
0
 /// <summary>
 /// Creates a blank DB entry for the specified functor
 /// </summary>
 public PredicateInfo(Symbol functorName, int arity, KnowledgeBase kb)
 {
     Name          = functorName;
     Arity         = arity;
     Entries       = new List <KnowledgeBaseEntry>();
     KnowledgeBase = kb;
 }
コード例 #8
0
ファイル: KB.cs プロジェクト: jcc333/MKULTRA
        private void MakeKB()
        {
            var parent = transform.parent;
            KB parentKB = null;
            if (parent != null)
            {
                parentKB = parent.GetComponent<KB>();
            }

            kb = IsGlobal?
                KnowledgeBase.Global
                : new KnowledgeBase(
                    gameObject.name,
                    gameObject,
                    parentKB == null ? GameObject.Find(GlobalKBGameObjectName).KnowledgeBase() : parentKB.KnowledgeBase);

            // Add UID counter.
            ELNode.Store(kb.ELRoot/Symbol.Intern("next_uid")%0);

            try
            {
                foreach (var file in SourceFiles)
                    kb.Consult(file);
            }
            catch (Exception)
            {
                Debug.Break(); // Pause the game
                throw;
            }
        }
コード例 #9
0
 /// <summary>
 /// Scans all rules for references to undefined predicates.
 /// </summary>
 public void WalkKB(KnowledgeBase kb)
 {
     foreach (var predicate in kb.Predicates)
     {
         if (predicate != null && predicate.Entries != null)
         {
             if (predicate.Public || predicate.Shadow)
             {
                 MarkReferenced(predicate);
             }
             bool firstOne = true;
             foreach (var kbEntry in predicate.Entries)
             {
                 var rule = kbEntry as KnowledgeBaseRule;
                 if (rule != null)
                 {
                     if (firstOne)
                     {
                         MarkDefined(predicate, rule);
                         firstOne = false;
                     }
                     WalkRule(kb, rule);
                     if (predicate.HigherOrderArguments != null)
                     {
                         foreach (var arg in predicate.HigherOrderArguments)
                         {
                             WalkGoal(kb, rule, rule.HeadArgs[arg]);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: PrologChecker.cs プロジェクト: jcc333/MKULTRA
 /// <summary>
 /// Scans all rules for references to undefined predicates.
 /// </summary>
 public void WalkKB(KnowledgeBase kb)
 {
     foreach (var predicate in kb.Predicates)
         if (predicate != null && predicate.Entries != null)
         {
             if (predicate.Public || predicate.Shadow)
                 MarkReferenced(predicate);
             bool firstOne = true;
             foreach (var kbEntry in predicate.Entries)
             {
                 var rule = kbEntry as KnowledgeBaseRule;
                 if (rule != null)
                 {
                     if (firstOne)
                     {
                         MarkDefined(predicate, rule);
                         firstOne = false;
                     }
                     WalkRule(kb, rule);
                     if (predicate.HigherOrderArguments != null)
                         foreach (var arg in predicate.HigherOrderArguments)
                             WalkGoal(kb, rule, rule.HeadArgs[arg]);
                 }
             }
         }
 }
コード例 #11
0
 public Compiler(Structure head, Structure[] body, KnowledgeBase kb)
 {
     this.head          = head;
     bodyGoals          = body;
     this.knowledgeBase = kb;
     env = new CompileTimeEnvironment(head.Arity);
     Compile();
 }
コード例 #12
0
        void KBChanged(KnowledgeBase newKB)
        {
            var eli = FindObjectOfType <ELInspector>();

            if (eli != null)
            {
                eli.SetKB(newKB);
            }
            WindowTitle = "Prolog console: " + newKB.Name;
        }
コード例 #13
0
ファイル: KnowledgeBase.cs プロジェクト: rzubek/UnityProlog
 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;
 }
コード例 #14
0
ファイル: ELProlog.cs プロジェクト: mantoun/MKULTRA
        //
        // these write a single nodes, so they don't need to loop like queries do.
        //

        /// <summary>
        /// Write TERM to EL KB, creating any nodes that need to be cerated.
        /// </summary>
        /// <param name="term">Prolog-format term to store into KB</param>
        /// <param name="knowledgeBase">KB in which to assert the term.</param>
        /// <returns></returns>
        public static ELNode Update(object term, KnowledgeBase knowledgeBase)
        {
            term = Term.Deref(term);
            var s = term as Structure;
            if (s != null)
                return UpdateStructure(s, knowledgeBase);
            var n = term as ELNode;
            if (n != null)
                return n;

            throw new Exception("Malformed EL assertion: " + ISOPrologWriter.WriteToString(term));
        }
コード例 #15
0
ファイル: PrologContext.cs プロジェクト: jcc333/MKULTRA
 /// <summary>
 /// Creates a PrologContext that can for at most the specified number of steps.
 /// </summary>
 public PrologContext(KnowledgeBase kb, int stepLimit)
 {
     StepsRemaining = stepLimit;
     goalStack = new List<GoalStackFrame>();
     goalStackCurrentRules = new List<KnowledgeBaseEntry>();
     GoalStackDepth = 0;
     KnowledgeBase = kb;
     traceVariables = new LogicVariable[256];
     traceValues = new object[256];
     tracePointer = 0;
     IndexicalBindingStack = new List<KeyValuePair<Symbol, object>>();
 }
コード例 #16
0
 /// <summary>
 /// Creates a PrologContext that can for at most the specified number of steps.
 /// </summary>
 public PrologContext(KnowledgeBase kb, int stepLimit)
 {
     StepsRemaining        = stepLimit;
     goalStack             = new List <GoalStackFrame>();
     goalStackCurrentRules = new List <KnowledgeBaseEntry>();
     GoalStackDepth        = 0;
     KnowledgeBase         = kb;
     traceVariables        = new LogicVariable[256];
     traceValues           = new object[256];
     tracePointer          = 0;
     IndexicalBindingStack = new List <KeyValuePair <Symbol, object> >();
     isFree = true;
 }
コード例 #17
0
ファイル: ELProlog.cs プロジェクト: mantoun/MKULTRA
 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));
 }
コード例 #18
0
        /// <summary>
        /// Gets a context that is currently free to use.  Should be relased afterward using ReleaseContext().
        /// </summary>
        /// <returns>A free PrologContext</returns>
        public static PrologContext Allocate(KnowledgeBase kb, object thisValue)
        {
            var c = Pool.Allocate();

            if (!c.isFree)
            {
                throw new InvalidOperationException("Allocated PrologContext is still in use!");
            }
            c.isFree        = false;
            c.KnowledgeBase = kb;
            c.Reset(thisValue);
            c.Output = Console.Out;
            return(c);
        }
コード例 #19
0
 /// <summary>
 /// Resets the context (clears stack, etc.) and starts a proof of the specified goal.
 /// </summary>
 /// <param name="goal">Goal to attempt to prove</param>
 /// <returns>Enumerator for solutions</returns>
 public IEnumerable <bool> ResetStackAndProve(Structure goal)
 {
     Reset(this.This);
     foreach (var state in KnowledgeBase.Prove(goal.Functor, goal.Arguments, this, 0))
     {
         if (state == CutState.ForceFail)
         {
             yield break;
         }
         else
         {
             yield return(false);
         }
     }
 }
コード例 #20
0
 public KnowledgeBase(string kbName, GameObject gameObject, KnowledgeBase parent, params KnowledgeBase[] otherImports)
 {
     if (kbName == null) throw new ArgumentNullException("kbName");
     Name = kbName;
     this.Parent = parent;
     this.GameObject = gameObject;
     this.ELRoot = new ELNode(null, Symbol.Intern("root"));
     //if (parent == null) throw new ArgumentNullException("parent");
     if (otherImports == null) throw new ArgumentNullException("otherImports");
     foreach (var import in otherImports)
         if (import == null) throw new ArgumentNullException("otherImports");
     if (parent != null)
         imports.Add(parent);
     imports.AddRange(otherImports);
 }
コード例 #21
0
        /// <summary>
        /// Resets the context (clears stack, etc.) and starts a proof of the specified goal.
        /// </summary>
        /// <param name="goal">Goal to attempt to prove</param>
        /// <returns>Enumerator for solutions</returns>
        public IEnumerable <bool> ResetStackAndProve(object goal)
        {
            Reset(this.This);
            Structure s = Term.Structurify(goal, "Invalid goal.");

            foreach (var state in KnowledgeBase.Prove(s.Functor, s.Arguments, this, 0))
            {
                if (state == CutState.ForceFail)
                {
                    yield break;
                }
                else
                {
                    yield return(false);
                }
            }
        }
コード例 #22
0
ファイル: KnowledgeBase.cs プロジェクト: mantoun/MKULTRA
        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);
        }
コード例 #23
0
ファイル: PrologChecker.cs プロジェクト: rzubek/MKULTRA
 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);
     }
 }
コード例 #24
0
        /// <summary>
        /// Proves the specified goal, throwing an exception with badGoalErrorMessage if the goal is ill-formed.
        /// </summary>
        internal IEnumerable <CutState> Prove(object goal, string badGoalErrorMessage)
        {
            Structure s = Term.Structurify(goal, badGoalErrorMessage);

            return(KnowledgeBase.Prove(s.Functor, s.Arguments, this, CurrentFrame));
        }
コード例 #25
0
 /// <summary>
 /// Proves the goal in the specified structure.
 /// </summary>
 internal IEnumerable <CutState> Prove(Structure goal)
 {
     return(KnowledgeBase.Prove(goal.Functor, goal.Arguments, this, CurrentFrame));
 }
コード例 #26
0
 /// <summary>
 /// Creates a PrologContext with PrologContext.DefaultStepLimit
 /// </summary>
 private PrologContext(KnowledgeBase kb)
     : this(kb, DefaultStepLimit)
 {
 }
コード例 #27
0
ファイル: PrologContext.cs プロジェクト: jcc333/MKULTRA
 /// <summary>
 /// Creates a PrologContext with PrologContext.DefaultStepLimit
 /// </summary>
 private PrologContext(KnowledgeBase kb)
     : this(kb, DefaultStepLimit)
 {
 }
コード例 #28
0
ファイル: ELInspector.cs プロジェクト: recardona/UnityProlog
 public void SetKB(KnowledgeBase kb)
 {
     root = kb.ELRoot;
     displayChildren.Add(root);
     WindowTitle = kb.Name + " KB";
 }
コード例 #29
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;
 }
コード例 #30
0
ファイル: KnowledgeBase.cs プロジェクト: mantoun/MKULTRA
 static KnowledgeBase()
 {
     Global = new KnowledgeBase("global", null, null);
     PrologPrimitives.InstallPrimitives();
 }
コード例 #31
0
ファイル: ELProlog.cs プロジェクト: jcc333/MKULTRA
        //
        // these write a single nodes, so they don't need to loop like queries do.
        //
        /// <summary>
        /// Write TERM to EL KB, creating any nodes that need to be cerated.
        /// </summary>
        /// <param name="term">Prolog-format term to store into KB</param>
        /// <param name="knowledgeBase">KB in which to assert the term.</param>
        /// <returns></returns>
        public static ELNode Update(object term, KnowledgeBase knowledgeBase)
        {
            term = Term.Deref(term);
            var s = term as Structure;
            if (s != null)
                return UpdateStructure(s, knowledgeBase);
            var n = term as ELNode;
            if (n != null)
                return n;

            throw new Exception("Malformed EL assertion: " + ISOPrologWriter.WriteToString(term));
        }
コード例 #32
0
ファイル: PrologContext.cs プロジェクト: jcc333/MKULTRA
 /// <summary>
 /// Gets a context that is currently free to use.  Should be relased afterward using ReleaseContext().
 /// </summary>
 /// <returns>A free PrologContext</returns>
 public static PrologContext GetFreePrologContext(KnowledgeBase kb, object thisValue)
 {
     if (FreeContexts.Count > 0)
     {
         var c = FreeContexts.Pop();
         if (!c.isFree)
             throw new InvalidOperationException("Allocated PrologContext is still in use!");
         c.isFree = false;
         c.KnowledgeBase = kb;
         c.Reset(thisValue);
         c.Output = Console.Out;
         return c;
     }
     return new PrologContext(kb) { This = thisValue };
 }
コード例 #33
0
 static KnowledgeBase()
 {
     Global = new KnowledgeBase("global", null, null);
     PrologPrimitives.InstallPrimitives();
 }
コード例 #34
0
 /// <summary>
 /// Gets a context that is currently free to use.  Should be relased afterward using ReleaseContext().
 /// </summary>
 /// <returns>A free PrologContext</returns>
 public static PrologContext Allocate(KnowledgeBase kb, object thisValue)
 {
     var c = Pool.Allocate();
     if (!c.isFree)
         throw new InvalidOperationException("Allocated PrologContext is still in use!");
     c.isFree = false;
     c.KnowledgeBase = kb;
     c.Reset(thisValue);
     c.Output = Console.Out;
     return c;
 }
コード例 #35
0
ファイル: PrologPrimitives.cs プロジェクト: rzubek/MKULTRA
 private static IEnumerable<CutState> RandomizeInternal(KnowledgeBase kb, PrologContext context, Structure t)
 {
     bool savedRandomize = context.Randomize;
     context.Randomize = true;
     foreach (var state in kb.Prove(t.Functor, t.Arguments, context, context.CurrentFrame))
         if (state==CutState.ForceFail)
             yield break;
         else
             yield return state;
     context.Randomize = savedRandomize;
 }
コード例 #36
0
ファイル: ELInspector.cs プロジェクト: jcc333/MKULTRA
 public void SetKB(KnowledgeBase kb)
 {
     root = kb.ELRoot;
     displayChildren.Add(root);
 }
コード例 #37
0
ファイル: PrologChecker.cs プロジェクト: jcc333/MKULTRA
        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);
                        if (predicate == null)
                            WarnUndefined(rule, functor, arity);
                        else
                        {
                            MarkReferenced(predicate);
                            if (predicate.HigherOrderArguments != null)
                                foreach (int argIndex in predicate.HigherOrderArguments)
                                    WalkGoal(kb, rule, goal.Argument(argIndex));
                        }
                    }
                    break;
            }
        }
コード例 #38
0
        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 "begin":
                foreach (var arg in goal.Arguments)
                {
                    WalkGoal(kb, rule, arg);
                }
                break;

            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);
                    if (predicate == null)
                    {
                        WarnUndefined(rule, functor, arity);
                    }
                    else
                    {
                        MarkReferenced(predicate);
                        if (predicate.HigherOrderArguments != null)
                        {
                            foreach (int argIndex in predicate.HigherOrderArguments)
                            {
                                WalkGoal(kb, rule, goal.Argument(argIndex));
                            }
                        }
                    }
                }
                break;
            }
        }
コード例 #39
0
ファイル: ELProlog.cs プロジェクト: jcc333/MKULTRA
 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));
 }
コード例 #40
0
ファイル: PrologChecker.cs プロジェクト: jcc333/MKULTRA
 private void WalkRule(KnowledgeBase kb, KnowledgeBaseRule rule)
 {
     foreach (Structure goal in rule.BodyGoals)
         WalkGoal(kb, rule, goal);
 }
コード例 #41
0
 public void SetKB(KnowledgeBase kb)
 {
     root = kb.ELRoot;
     displayChildren.Add(root);
     WindowTitle = kb.Name + " KB";
 }
コード例 #42
0
 public void SetKB(KnowledgeBase kb)
 {
     root = kb.ELRoot;
     displayChildren.Add(root);
 }