Ejemplo n.º 1
0
        /// <summary>
        /// Load Node from XmlNode
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static SimpleRule loadFromXmlNode(XmlNode node)
        {
            SimpleRule root = new SimpleRule();

            // TODO : Add extention reading

            if (node.Attributes["id"] == null)
            {
                throw new PmmlException("Attribute 'id' is required in 'SimpleRule'.");
            }
            root.fid = node.Attributes["id"].Value;

            /*if (node.Attributes["operator"] == null)
             *      throw new PmmlException("Attribute 'operator' is required in 'SimplePredicate'.");
             * root.foperator = node.Attributes["operator"].Value;
             *
             * if (!("isMissing".Equals(root.foperator) || "isNotMissing".Equals(root.foperator)))
             * {
             *      if (node.Attributes["value"] == null)
             *              throw new PmmlException(string.Format("Attribute 'value' is required in 'SimplePredicate' if 'operator' is '{0}'.", root.foperator));
             *      root.fvalue = node.Attributes["value"].Value;
             * }*/

            root.fscore = node.Attributes["score"].Value;

            foreach (XmlNode item in node.ChildNodes)
            {
                if ("extension".Equals(item.Name.ToLowerInvariant()))
                {
                    // TODO : implement extension
                    //root.Nodes.Add(Node.loadFromXmlNode(item));
                }
                else if ("simplepredicate".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Predicate = SimplePredicate.loadFromXmlNode(item);
                }
                else if ("compoundpredicate".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Predicate = CompoundPredicate.loadFromXmlNode(item);
                }
                else if ("scoredistribution".Equals(item.Name.ToLowerInvariant()))
                {
                    root.ScoreDistributions.Add(ScoreDistribution.loadFromXmlNode(item));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return(root);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Load Node from XmlNode
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static RuleSet loadFromXmlNode(XmlNode node)
        {
            RuleSet root = new RuleSet(new TruePredicate());

            if (node.Attributes["id"] != null)
            {
                root.id = node.Attributes["id"].Value;
            }

            if (node.Attributes["defaultScore"] != null)
            {
                root.fdefaultscore = node.Attributes["defaultScore"].Value;
            }

            if (node.Attributes["recordCount"] != null)
            {
                root.recordCount = Convert.ToDecimal(node.Attributes["recordCount"].Value, CultureInfo.InvariantCulture);
            }

            root.ruleSelectionMethods = new List <RuleSelectionMethod>();
            root.scoreDistributions   = new List <ScoreDistribution>();
            foreach (XmlNode item in node.ChildNodes)
            {
                if ("extension".Equals(item.Name.ToLowerInvariant()))
                {
                    // TODO : implement extension
                    //root.Nodes.Add(Node.loadFromXmlNode(item));
                }
                else if ("ruleselectionmethod".Equals(item.Name.ToLowerInvariant()))
                {
                    root.RuleSelectionMethods.Add(RuleSelectionMethod.loadFromXmlNode(item));
                }
                else if ("scoredistribution".Equals(item.Name.ToLowerInvariant()))
                {
                    root.ScoreDistributions.Add(ScoreDistribution.loadFromXmlNode(item));
                }
                else if ("simplerule".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Rules.Add(SimpleRule.loadFromXmlNode(item));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return(root);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load Node from XmlNode
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        public static Node loadFromXmlNode(XmlNode node)
        {
            Node root = new Node(new TruePredicate());

            if (node.Attributes["id"] != null)
            {
                root.id = node.Attributes["id"].Value;
            }

            if (node.Attributes["score"] != null)
            {
                root.score = node.Attributes["score"].Value;
            }

            if (node.Attributes["recordCount"] != null)
            {
                root.recordCount = Convert.ToDecimal(node.Attributes["recordCount"].Value, CultureInfo.InvariantCulture);
            }

            root.scoreDistributions = new List <ScoreDistribution>();
            foreach (XmlNode item in node.ChildNodes)
            {
                if ("extension".Equals(item.Name.ToLowerInvariant()))
                {
                    // TODO : implement extension
                    //root.Nodes.Add(Node.loadFromXmlNode(item));
                }
                else if ("node".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Nodes.Add(Node.loadFromXmlNode(item));
                }
                else if ("simplepredicate".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Predicate = SimplePredicate.loadFromXmlNode(item);
                }
                else if ("true".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Predicate = new TruePredicate();
                }
                else if ("false".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Predicate = new FalsePredicate();
                }
                else if ("compoundpredicate".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Predicate = CompoundPredicate.loadFromXmlNode(item);
                }
                else if ("simplesetpredicate".Equals(item.Name.ToLowerInvariant()))
                {
                    root.Predicate = SimpleSetPredicate.loadFromXmlNode(item);
                }
                else if ("scoredistribution".Equals(item.Name.ToLowerInvariant()))
                {
                    root.ScoreDistributions.Add(ScoreDistribution.loadFromXmlNode(item));
                }
                else
                {
                    throw new NotImplementedException();
                }
            }

            return(root);
        }