Пример #1
0
        public override Classification Classify(DataRecord Record)
        {
            Classification classification = new Classification();

            foreach (Rule r in Rules)
            {
                bool satisfied = true;
                foreach (Rule.RuleComponent rc in r.Components)
                {
                    if (satisfied)
                    {
                        bool localSatisfied = false;
                        for (int rcIndex = 0; rcIndex < rc.Comparators.Length; ++rcIndex)
                        {
                            if (!localSatisfied)
                            {
                                switch (rc.Comparators[rcIndex])
                                {
                                case Rule.EComparator.Equal:
                                    decimal lhs, rhs;
                                    if (decimal.TryParse(Record.GetAttributeValue(rc.LHSAttribute), out lhs))
                                    {
                                        if (decimal.TryParse(rc.RHSValues[rcIndex], out rhs))
                                        {
                                            localSatisfied = lhs == rhs;
                                            break;
                                        }
                                    }
                                    localSatisfied = Record.GetAttributeValue(rc.LHSAttribute) == rc.RHSValues[rcIndex];
                                    break;

                                case Rule.EComparator.GreaterThan:
                                    localSatisfied = Decimal.Parse(Record.GetAttributeValue(rc.LHSAttribute)) > Decimal.Parse(rc.RHSValues[rcIndex]);
                                    break;

                                case Rule.EComparator.LessThan:
                                    localSatisfied = Decimal.Parse(Record.GetAttributeValue(rc.LHSAttribute)) < Decimal.Parse(rc.RHSValues[rcIndex]);
                                    break;

                                case Rule.EComparator.GreaterThanInclusive:
                                    localSatisfied = Decimal.Parse(Record.GetAttributeValue(rc.LHSAttribute)) >= Decimal.Parse(rc.RHSValues[rcIndex]);
                                    break;

                                case Rule.EComparator.LessThanInclusive:
                                    localSatisfied = Decimal.Parse(Record.GetAttributeValue(rc.LHSAttribute)) <= Decimal.Parse(rc.RHSValues[rcIndex]);
                                    break;
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                        satisfied = localSatisfied;
                    }
                    else
                    {
                        break;
                    }
                }
                if (satisfied)
                {
                    classification.AddMatch(r.Classification, r.GetRule());
                    satisfied = false;
                }
            }
            if (classification.Classifications.Length == 0)
            {
                classification.AddMatch(DefaultClassification, "None");
            }
            return(classification);
        }