Beispiel #1
0
        public static DataInstance copy(string identifier, DataInstance old)
        {
            DataInstance output = new DataInstance(identifier);

            foreach (string key in old.fields.Keys.ToList())
            {
                output.setProperty(key, old.getProperty(key));
            }
            return(output);
        }
        public virtual string classify(DataInstance instance)
        {
            string value_of_instance = instance.getProperty(this.label);

            // Check if we should pass this instance down to another node..
            foreach (Node child in this.getNodeChildren())
            {
                if (value_of_instance == child.value_splitter)
                {
                    return(child.classify(instance));
                }
            }

            // Check if we should pass this instance down to one of our leafs.
            foreach (Leaf child in this.getLeafChildren())
            {
                if (value_of_instance == child.value_splitter)
                {
                    return(child.classifier);
                }
            }

            throw new Exception($"Unknown value {value_of_instance} for {this.label}");
        }