예제 #1
0
    private void PrintKnowledge(IKnowledge knowledge, Func <bool, bool> filter)
    {
        Log("Knowledge: ");

        foreach (var state in GetFullState())
        {
            Log("\t" + PrintState(state) + ":");
            var fun = knowledge.Get(state);

            if (GetFullState().Any(s => filter(fun(s))))
            {
                if (GetFullState().All(s => fun(s)))
                {
                    Log("\t\t... -> True");
                }
                else if (GetFullState().All(s => fun(s) == false))
                {
                    Log("\t\t... -> False");
                }
                else
                {
                    foreach (var state2 in GetFullState())
                    {
                        var result = fun(state2);
                        if (filter(result))
                        {
                            Log("\t\t" + PrintState(state2) + " -> " + (result ? "True" : "False"));
                        }
                    }
                }
            }
        }
    }
예제 #2
0
        private void SurfaceVerify(IKnowledge source, IKnowledge obj, out string msg, out object output)
        {
            msg    = AGTutorMessage.VerifyWrong;
            output = null;

            var eqGoalExpr = obj as AGPropertyExpr;

            if (eqGoalExpr != null)
            {
                GoalVerify(source, eqGoalExpr.Goal, out msg, out output);
            }
            var shapeExpr = obj as AGShapeExpr;

            if (shapeExpr != null)
            {
                ShapeVerify(source, shapeExpr.ShapeSymbol, out msg, out output);
            }

            /*     var eqGoalLst = obj as List<object>;
             *   if (eqGoalLst != null)
             *   {
             *       foreach (var tempObj in eqGoalLst)
             *       {
             *           var gGoal = tempObj as AG;
             *           bool verified = GoalVerify(obj, gGoal, out msg, out output);
             *           if (verified) return;
             *       }
             *   }*/
        }
예제 #3
0
        public BehaviorGraphNode UpdateSolvingCache(IKnowledge userKnowledge, bool isAdd = true)
        {
            var node = SearchInnerLoopNode(userKnowledge);

            if (node == null)
            {
                return(null);
            }
            Debug.Assert(node.State.Level == BehaviorLevel.Inner);

            /*      if (node.OutEdges.Count != 0) return node;
             *    Debug.Assert(node.OutEdges.Count == 0);*/
            bool contained = SolvingCache.ContainsKey(node);

            //Debug.Assert(contained);
            if (!contained)
            {
                return(node);
            }
            if (isAdd)
            {
                SolvingCache[node] = true;
            }
            else
            {
                SolvingCache[node] = false;
            }
            return(node);
        }
예제 #4
0
        private string ExamFailsObserver(IKnowledge knowledge)
        {
            var result = new StringBuilder();

            this.trainers.Where(t => t.TrainerType == TrainerType.PreviousYears).ToList().ForEach(t => result.AppendLine(((IHelper)t).HelpMe(knowledge)));

            return(result.ToString());
        }
예제 #5
0
 public void Initialize()
 {
     MainOrganization.Models.SetOn(1);
     _knowledge = new Knowledge(MainOrganization.ArtifactNetwork, MainOrganization.Models, "1",
                                (byte)_floats1.Length);
     _database = new Database(MainOrganization.ArtifactNetwork, MainOrganization.Models, _communication, Database.ClassId);
     _database.CognitiveArchitecture.InternalCharacteristics.TimeToLive = 10;
     _bits1 = new Bits(_floats1, 0);
 }
예제 #6
0
 public Student(string name, IPet pet, StudentType studentType, OtherCompetence otherCompetance, IKnowledge knowledge)
     : base(name, Student.StudentBaseHp)
 {
     this.studentType = studentType;
     this.otherCompetence = otherCompetance;
     this.Knowledge = knowledge;
     this.pet = pet;
     this.IsAlive = true;
 }
예제 #7
0
    public void AddDayKnowledge(int day, IKnowledge knowledge)
    {
        if (KnowledgeDict.ContainsKey(day))
        {
            var prevKnowlede = KnowledgeDict[day];
            KnowledgeDict[day] = new Combine2Knowledge(prevKnowlede, knowledge);
            return;
        }

        KnowledgeDict.Add(day, knowledge);
    }
예제 #8
0
        public Belief(GraphMetaNetwork metaNetwork, IKnowledge knowledge, byte length, RandomGenerator model,
                      BeliefWeightLevel beliefWeightLevel) : this(metaNetwork, length, model, beliefWeightLevel)
        {
            if (knowledge == null)
            {
                throw new ArgumentNullException(nameof(knowledge));
            }

            Name        = knowledge.Name;
            KnowledgeId = knowledge.EntityId;
        }
예제 #9
0
        protected virtual string OnExamFail(IKnowledge knowledg)
        {
            Func <IKnowledge, string> handler = CantPassExam;

            if (handler != null)
            {
                return(handler(knowledg));
            }

            return(string.Empty);
        }
예제 #10
0
        public void Verify(IKnowledge source, IKnowledge obj, out string msg, out object output)
        {
            output = null;
            object outobj;

            SurfaceVerify(source, obj, out msg, out outobj); //Equation Eval Trace
            if (msg != null && msg.Equals(AGTutorMessage.VerifyCorrect))
            {
                return;
            }
            DeepVerify(source, obj, out msg, out outobj); //Relation Eval
        }
예제 #11
0
        // Construct a new knowledge base with a provided path to the installation folder.
        public GameKB(string installPath, IKnowledge gameKnowledge)
        {
            if (!Directory.Exists(installPath))
            {
                throw new ArgumentException("LibraryPath parameter must point to a valid path! " + installPath);
            }

            _installpath   = Path.GetFullPath(installPath);
            _gameKnowledge = gameKnowledge ?? throw new ArgumentNullException("GameKnowledge parameter cannot be null!");

            ConstructLibraryPaths();
        }
예제 #12
0
        public static GameKB CreateFromLibraryPath(IKnowledge gameKnowledge, string libPath)
        {
            string libPathPart = gameKnowledge.LibraryRelativePath;

            if (!libPath.EndsWith(libPathPart))
            {
                throw new InvalidOperationException("The provided library path does not match the provided game knowledge base!");
            }
            // The install path is the relative library path removed from the full lib path.
            string installPath = libPath.Remove(libPath.Length - libPathPart.Length);

            return(new GameKB(installPath, gameKnowledge));
        }
예제 #13
0
        public void Select(IKnowledge entity)
        {
            var path = _semanticNetworkNode.Find(entity).OfType <object>().ToList();

            if (path.Count > 0)
            {
                this.ExecuteWithItem(path, item =>
                {
                    item.IsSelected = true;
                    item.BringIntoView();
                });
            }
        }
예제 #14
0
        private bool GoalVerify(IKnowledge obj, EqGoal eqGoal, out string msg, out object output)
        {
            msg    = AGTutorMessage.VerifyWrong;
            output = null;

            List <Tuple <object, object> > trace = null;

            var agPropExpr = new AGPropertyExpr(obj.Expr, eqGoal);

            agPropExpr.IsSelected = true;
            agPropExpr.GenerateSolvingTrace();
            trace = agPropExpr.AutoTrace;

            BehaviorGraphNode node;

            if (trace == null || trace.Count == 0)
            {
                node = UserGraph.UpdateSolvingCache(agPropExpr);
                //node = UserGraph.SearchInnerLoopNode(eqGoal);

                if (node == null)
                {
                    return(false);
                }
            }
            if (trace != null)
            {
                bool matchResult = UserGraph.Match(trace);
                if (!matchResult)
                {
                    return(false);
                }
                //insert nodes
                UserGraph.Insert(trace);
                CurrentStateNode = UserGraph.SearchInnerLoopNode(obj); //update _currentStateNode;
            }
            else
            {
                CurrentStateNode = UserGraph.SearchInnerLoopNode(eqGoal);
            }

            /* var nextTuple1 = UserGraph.SearchNextInnerLoopNode(CurrentStateNode);
             * if (nextTuple1 == null) // query-end
             * {
             *   msg = AGTutorMessage.SolvedProblem;
             *   return true;
             * }
             */
            msg = AGTutorMessage.VerifyCorrect;
            return(true);
        }
예제 #15
0
        private void DeepVerify(IKnowledge source, IKnowledge obj, out string msg, out object output)
        {
            msg = AGTutorMessage.VerifyWrong;

            object result;
            var    shapeExpr = obj as AGShapeExpr;

            if (shapeExpr != null)
            {
                result = Reasoner.Instance.RelationValidate(shapeExpr.ShapeSymbol, out output);
            }
            else
            {
                result = Reasoner.Instance.RelationValidate(obj.Expr, out output);
            }

            if (result == null)
            {
                return;
            }

            var inputApproximateMatched = result as bool?;

            if (inputApproximateMatched != null)
            {
                if (inputApproximateMatched.Value)
                {
                    msg = AGTutorMessage.VerifyCorrect;
                }
                return;
            }

            var trace = result as List <Tuple <object, object> >;

            if (trace != null)
            {
                bool matchResult = UserGraph.Match(trace); //match and update
                if (matchResult)
                {
                    //insert nodes
                    UserGraph.Insert(trace);
                    CurrentStateNode = UserGraph.SearchInnerLoopNode(source); //update _currentStateNode;
                    //Debug.Assert(_currentStateNode != null);
                    msg = AGTutorMessage.VerifyCorrect;
                }
            }
        }
예제 #16
0
        private void LoadObjectGraph()
        {
            Debug.Assert(QueriedKnowledge != null);
            IKnowledge selectRenderAnswer = QueriedKnowledge.FindSelectedKnowledge();

            if (selectRenderAnswer == null)
            {
                return;
            }
            selectRenderAnswer.GenerateSolvingTrace();
            //if (selectRenderAnswer.AutoTrace == null) return;
            var behaviorGraph = new BehaviorGraph();

            if (selectRenderAnswer.AutoTrace != null)
            {
                behaviorGraph.Insert(selectRenderAnswer.AutoTrace);
            }
            ObjectGraph = behaviorGraph;
        }
예제 #17
0
            public async Task <(string?, IKnowledge)> Reply(IKnowledge knowledge, MuteCommandContext message)
            {
                if (IsComplete)
                {
                    return(null, knowledge);
                }

                // Get or construct an eliza engine from the knowledge chain
                // If the previous engine has finished a new one will be constructed
                ElizaEngineAdapter engine;

                (engine, knowledge) = knowledge.GetOrAdd(e => !e.Eliza.Finished, k => new ElizaEngineAdapter(k, _script));

                // Get a response from eliza and pass it back
                var response = engine.Eliza.ProcessInput(message);

                IsComplete = engine.Eliza.Finished;
                return(response, knowledge);
            }
예제 #18
0
        private bool ShapeVerify(IKnowledge obj, ShapeSymbol shape, out string msg, out object output)
        {
            msg    = AGTutorMessage.VerifyWrong;
            output = null;

            List <Tuple <object, object> > trace = null;

            var agShapeExpr = new AGShapeExpr(obj.Expr, shape);

            agShapeExpr.IsSelected = true;
            agShapeExpr.GenerateSolvingTrace();
            trace = agShapeExpr.AutoTrace;

            if (trace == null || trace.Count == 0)
            {
                return(false);
            }

            /*   var lastTuple = trace[trace.Count - 1] as Tuple<object, object>;
             * var lastLst = lastTuple.Item2 as List<object>;
             * Debug.Assert(lastLst != null);
             * Debug.Assert(lastLst.Count != 0);
             * var lastTs = lastLst[lastLst.Count - 1] as TraceStepExpr;*/
            bool matchResult = UserGraph.Match(trace); //match and update

            if (!matchResult)
            {
                return(false);
            }

            //insert nodes
            UserGraph.Insert(trace);
            CurrentStateNode = UserGraph.SearchInnerLoopNode(obj); //update _currentStateNode;
            //var nextTuple1 = UserGraph.SearchNextInnerLoopNode(CurrentStateNode);

            /*  if (nextTuple1 == null) // query-end
             * {
             *    msg = AGTutorMessage.SolvedProblem;
             *    return true;
             * }*/
            msg = AGTutorMessage.VerifyCorrect;
            return(true);
        }
예제 #19
0
 public Student(string name, IPet pet, StudentType studentType, OtherCompetence otherCompetance, IKnowledge knowledge)
     : base(name, Student.StudentBaseHp)
 {
     this.studentType     = studentType;
     this.otherCompetence = otherCompetance;
     this.Knowledge       = knowledge;
     this.pet             = pet;
     this.IsAlive         = true;
 }
예제 #20
0
 public static Belief CreateInstance(GraphMetaNetwork metaNetwork, IKnowledge knowledge, byte length, RandomGenerator model,
                                     BeliefWeightLevel beliefWeightLevel)
 {
     return(new Belief(metaNetwork, knowledge, length, model, beliefWeightLevel));
 }
예제 #21
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return($"{this.ToString()} needs to go for a walk!!! The student time to study has been decreased! You receive {Dog.KnowledgeBoost} knowledge!!");
 }
예제 #22
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return $"{this.ToString()} gives the student it's wisdom!!! The student receives {Turtle.KnowledgeBoost} knowledge!";
 }
예제 #23
0
 public string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return($"{base.Name} is here to help!The student receives {KnowledgeBoost} knowledge!!");
 }
예제 #24
0
 private void AddInsightKeyword(int persIndex, int day, string insightName, IKnowledge knowledge)
 {
     PersList[persIndex].AddInsightKnowledge(insightName, day, knowledge);
     Debug.Log("insight " + PersList[persIndex].Name + " " + insightName);
 }
예제 #25
0
 private void AddDayKnowledge(int persIndex, int day, IKnowledge knowledge)
 {
     PersList[persIndex].AddDayKnowledge(day, knowledge);
     Debug.Log("addKnowledge " + PersList[persIndex].Name + " day " + day);
 }
예제 #26
0
 private IKnowledge AddKnowledge(string varName, IKnowledge knowledge)
 {
     Debug.Log("knowledge " + varName);
     KnowledgeDict.Add(varName, knowledge);
     return(knowledge);
 }
예제 #27
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return $"{this.ToString()} blessed the student! The student receives {GoldFish.KnowledgeBoost} knowledge!";
 }
 public string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return $"{base.Name} is here to help!The student receives {KnowledgeBoost} knowledge!!";
 }
        private string ExamFailsObserver(IKnowledge knowledge)
        {
            var result = new StringBuilder();

            this.trainers.Where(t => t.TrainerType == TrainerType.PreviousYears).ToList().ForEach(t => result.AppendLine(((IHelper)t).HelpMe(knowledge)));

            return result.ToString();
        }
예제 #30
0
 public static String GetAnchor(this IKnowledge knowledge)
 {
     return($"#{knowledge.ID}#");
 }
예제 #31
0
 public abstract string HelpMe(IKnowledge knowledge);
예제 #32
0
 public (string, IKnowledge) Reply(IKnowledge knowledge, IUtterance message)
 {
     return(_message, null);
 }
예제 #33
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return($"{this.ToString()} gives the student it's wisdom!!! The student receives {Turtle.KnowledgeBoost} knowledge!");
 }
예제 #34
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return($"{this.ToString()} ate the homework!! The student receives {Cat.KnowledgeBoost} knowledge!!");
 }
예제 #35
0
 public ImplyStateInfo(IKnowledge a, IKnowledge b, List <State> fullState)
 {
     this.A         = a;
     this.B         = b;
     this.FullState = fullState;
 }
예제 #36
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return $"{this.ToString()} needs to go for a walk!!! The student time to study has been decreased! You receive {Dog.KnowledgeBoost} knowledge!!";
 }
예제 #37
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return($"{this.ToString()} blessed the student! The student receives {GoldFish.KnowledgeBoost} knowledge!");
 }
예제 #38
0
        protected virtual string OnExamFail(IKnowledge knowledg)
        {
            Func<IKnowledge, string> handler = CantPassExam;
            if (handler != null)
            {
                return handler(knowledg);
            }

            return string.Empty;
        }
예제 #39
0
 public override string HelpMe(IKnowledge knowledge)
 {
     knowledge.AddKnowledge(KnowledgeBoost);
     return $"{this.ToString()} ate the homework!! The student receives {Cat.KnowledgeBoost} knowledge!!";
 }