Exemple #1
0
        public IEnumerable <AppraisalRule> Evaluate(IBaseEvent evt, IQueryable kb, Name perspective)
        {
            // Switching the SELF term for the correct name withint the event

            var auxEvt = evt.EventName.SwapTerms(perspective, Name.SELF_SYMBOL);
            var result = new List <AppraisalRule>();

            foreach (var r in this.Rules)
            {
                // Trying to find all possible initial substitutions;
                var initialSubSet = Unifier.Unify(r.EventName, auxEvt);


                if (initialSubSet == null)
                {
                    initialSubSet = new SubstitutionSet();
                }


                if (auxEvt.Match(r.EventName) || initialSubSet.Any())
                {
                    var finalSubSet = r.Conditions.Unify(kb, perspective, new List <SubstitutionSet>()
                    {
                        new SubstitutionSet(initialSubSet)
                    });
                    if (finalSubSet != null)
                    {
                        //TODO: Handle uncertainty in beliefs
                        foreach (var set in finalSubSet)
                        {
                            var a = new AppraisalRule(r);
                            a.EventName.MakeGround(set);
                            foreach (var variable in a.getAppraisalVariables())
                            {
                                variable.Value = variable.Value.MakeGround(set);
                                if (variable.Target != null && variable.Target != (Name)"-")
                                {
                                    variable.Target = variable.Target.MakeGround(set);
                                }
                            }
                            result.Add(a);
                        }
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        public void Appraisal(KB kb, IBaseEvent evt, IWritableAppraisalFrame frame)
        {
            AppraisalRule activeRule = Evaluate(evt, kb, kb.Perspective);

            if (activeRule != null)
            {
                foreach (var appVar in activeRule.getAppraisalVariables())
                {
                    float des;
                    if (!float.TryParse(appVar.Value.ToString(), out des))
                    {
                        throw new ArgumentException(appVar.Name + " can only be a float value");
                    }


                    if (appVar.Name == OCCAppraisalVariables.GOALSUCCESSPROBABILITY)
                    {
                        frame.SetAppraisalVariable(OCCAppraisalVariables.GOALSUCCESSPROBABILITY + " " + appVar.Target, des);
                    }

                    else if (appVar.Name == OCCAppraisalVariables.PRAISEWORTHINESS)
                    {
                        frame.SetAppraisalVariable(OCCAppraisalVariables.PRAISEWORTHINESS + " " + appVar.Target, des);
                    }

                    else
                    {
                        frame.SetAppraisalVariable(appVar.Name, des);
                    }

                    if (appVar.Target != null && appVar.Target != (Name)"-" && appVar.Target != (Name)"SELF")
                    {
                        frame.SetAppraisalVariable(OCCAppraisalVariables.DESIRABILITY_FOR_OTHER + "" + appVar.Target, des);
                    }
                }
            }
        }