Ejemplo n.º 1
0
 /// <summary>
 /// Construct Fact. 
 /// </summary>
 /// <param name="ID"></param>
 /// <param name="Value"></param>
 //[System.Diagnostics.DebuggerHidden]
 public Fact(string ID, int priority, object value, Type valueType)
     : base(ID,priority)
 {
     //naked
     IEvidenceValue x = new Naked(value, valueType);
     EvidenceValue = x;
 }
Ejemplo n.º 2
0
        public ActionExpression(string ID, string operatingId, string equation, int priority)
            : base(ID, priority)
        {
            this.equation = equation;
            this.operatingId = operatingId;

            //determine the dependent facts
            ExpressionEvaluator e = new ExpressionEvaluator();
            e.Parse(equation); //this method is slow, do it only when needed

            string[] dependents = ExpressionEvaluator.RelatedEvidence(e.Infix);
            dependentEvidence = dependents;

            //assing a value
            Naked naked = new Naked(null, typeof(string));
            this.EvidenceValue = naked;

            //this is expensive and static, so compute now
            evaluator = new ExpressionEvaluator();
            evaluator.Parse(equation); //this method is slow, do it only when needed
            evaluator.InfixToPostfix(); //this method is slow, do it only when needed
            evaluator.GetEvidence += delegate(object sender, EvidenceLookupArgs args)
            {
                return RaiseEvidenceLookup(sender, args);
            };
        }
Ejemplo n.º 3
0
        public Rule(string ID, string equation, List<EvidenceSpecifier> actions, int priority, bool chainable)
            : base(ID, priority)
        {
            if (actions == null || actions.Count < 1)
                throw new Exception("Rules must have at least one action.");
            foreach (EvidenceSpecifier action in actions)
            {
                if (!action.truthality && chainable)
                    throw new Exception("Chainable rules are not allowed to contain actions whos result is false.");
            }

            this.actions = actions;
            this.chainable = chainable;
            this.equation = equation;
            ArrayList al = new ArrayList();
            foreach (EvidenceSpecifier es in actions)
            {
                al.Add(es.evidenceID);
            }
            this.clauseEvidence = (string[])al.ToArray(typeof(string));

            //this is expensive and static, so compute now
            ExpressionEvaluator e = new ExpressionEvaluator();
            e.Parse(equation); //this method is slow, do it only when needed
            e.InfixToPostfix(); //this method is slow, do it only when needed
            this.postfixExpression = e.Postfix; //this method is slow, do it only when needed

            //determine the dependent facts
            string[] dependents = ExpressionEvaluator.RelatedEvidence(e.Postfix);
            dependentEvidence = dependents;

            //change event could set its value when a model is attached
            Naked naked = new Naked(false, typeof(bool));
            base.EvidenceValue = naked;
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        //[System.Diagnostics.DebuggerHidden]
        public object Clone()
        {
            Naked xml = new Naked(value, valueType);

            return(xml);
        }
Ejemplo n.º 5
0
        private Symbol ParseToSymbol(string s)
        {
            Symbol sym = new Symbol();
            if (IsOpenParanthesis(s))
            {
                sym.name = s;
                sym.type = Type.OpenBracket;
            }
            else if (IsCloseParanthesis(s))
            {
                sym.name = s;
                sym.type = Type.CloseBracket;
            }
            else if (IsFunction(s)) //isfunction must come b4 isvariable because its an exact match where the other isnt
            {
                sym.name = s;
                sym.type = Type.Function;
            }
            else if (IsOperator(s))
            {
                sym.name = s;
                sym.type = Type.Operator;
            }
            else if (IsBoolean(s))
            {
                Naked naked = new Naked(Boolean.Parse(s), typeof(bool));
                sym.name = s;
                sym.value = naked;
                sym.type = Type.Value;
            }
            else if (IsFact(s))
            {

                if (s.IndexOf(".") >= 0)
                {
                    sym.expressionStr = s;

                    s = s.Substring(0,
                        s.IndexOf("."));
                }

                sym.name = s;
                sym.type = Type.Fact;
            }
            else if (IsInt32(s))
            {
                Naked naked = new Naked(Int32.Parse(s), typeof(int));
                sym.name = s;
                sym.value = naked;
                sym.type = Type.Value;
            }
            else if (IsDecimal(s))
            {
                Naked naked = new Naked(Decimal.Parse(s), typeof(decimal));
                sym.name = s;
                sym.value = naked;
                sym.type = Type.Value;
            }
            else if (IsNumber(s))
            {
                Naked naked = new Naked(Double.Parse(s), typeof(double));
                sym.name = s;
                sym.value = naked;
                sym.type = Type.Value;
            }
            else if (IsString(s))
            {
                Naked naked = new Naked(s.Substring(1, s.Length - 2), typeof(string));
                sym.name = s;
                sym.value = naked;
                sym.type = Type.Value;
            }
            else
            {
                //who knows what it is so throw an exception
                throw new Exception("Invalid tokin: " + s);
            }
            return sym;
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 //[System.Diagnostics.DebuggerHidden]
 public object Clone()
 {
     Naked xml = new Naked(value, valueType);
     return xml;
 }