public AnswerTreeNode(DatumSchema schema, string answer, Datum[] data, int level)
 {
     Level = level;
     if (schema.AnswerValidator(answer))
     {
         /* for (int i = 0; i < Level; i++)
          *  Console.Write(" |");
          * Console.WriteLine(" Answer: {0}", answer); */
         Answer = answer;
         for (int i = 0; i < data.Length; i++)
         {
             if (data[i].Answer != Answer)
             {
                 throw new InvalidOperationException(String.Format(
                                                         "The datum {0} does not have the answer {1}.", data[i], Answer));
             }
         }
         Data = data;
         Working.Printf("Every element in the current data subset (\\{{{0}\\}}) now " +
                        "all share the same answer of \\texttt{{{1}}}. Hence, " +
                        "that is the answer that should be declared given this " +
                        "node of the decision tree has been reached.",
                        String.Join(", ", Data.Select(d => d.ToString())),
                        Answer);
     }
     else
     {
         throw new InvalidOperationException(String.Format(
                                                 "The answer {0} is not valid with the given schema.", answer));
     }
 }
 public AnswerTreeNode(DatumSchema schema, string answer, Datum[] data, int level)
 {
     Level = level;
     if(schema.AnswerValidator(answer))
     {
         /* for (int i = 0; i < Level; i++)
             Console.Write(" |");
         Console.WriteLine(" Answer: {0}", answer); */
         Answer = answer;
         for(int i = 0; i < data.Length; i++)
         {
             if(data[i].Answer != Answer)
             {
                 throw new InvalidOperationException(String.Format(
                     "The datum {0} does not have the answer {1}.", data[i], Answer));
             }
         }
         Data = data;
         Working.Printf("Every element in the current data subset (\\{{{0}\\}}) now " +
                        "all share the same answer of \\texttt{{{1}}}. Hence, " +
                        "that is the answer that should be declared given this " +
                        "node of the decision tree has been reached.",
                        String.Join(", ", Data.Select(d => d.ToString())),
                        Answer);
     }
     else
     {
         throw new InvalidOperationException(String.Format(
             "The answer {0} is not valid with the given schema.", answer));
     }
 }
 public Datum(DatumSchema schema, string answer, params string[] values)
 {
     Schema = schema;
     if(values.Length == Schema.Attributes.Length)
     {
         Values = new Dictionary<Attribute, string>();
         for(int i = 0; i < values.Length; i++)
         {
             Values[Schema.Attributes[i]] = values[i];
         }
     }
     if (schema.AnswerValidator(answer))
     {
         Answer = answer;
     }
 }
 public Datum(DatumSchema schema, string answer, params string[] values)
 {
     Schema = schema;
     if (values.Length == Schema.Attributes.Length)
     {
         Values = new Dictionary <Attribute, string>();
         for (int i = 0; i < values.Length; i++)
         {
             Values[Schema.Attributes[i]] = values[i];
         }
     }
     if (schema.AnswerValidator(answer))
     {
         Answer = answer;
     }
 }
Beispiel #5
0
        public static DataSet FromXml(XElement element)
        {
            XElement    schemaElement = element.Element("Schema");
            DatumSchema schema        = DatumSchema.FromXml(schemaElement);

            XElement dataElement = element.Element("Data");

            Datum[] data = dataElement
                           .Elements("Datum")
                           .Select(datumElement =>
            {
                try
                {
                    string answer            = datumElement.Attribute("Answer").Value;
                    string[] attributeValues = new string[schema.Attributes.Length];

                    for (int i = 0; i < attributeValues.Length; i++)
                    {
                        string attributeName      = schema.Attributes[i].Name;
                        var attributeValueElement = datumElement.Elements(attributeName);
                        if (attributeValueElement.Count() == 0)
                        {
                            throw new IOException(String.Format(
                                                      "The element at line {0} in the input data does not contain " +
                                                      "an attribute value for {1}.",
                                                      (datumElement as IXmlLineInfo).LineNumber,
                                                      attributeName));
                        }
                        string value       = attributeValueElement.First().Value;
                        attributeValues[i] = value;
                    }

                    return(new Datum(schema, answer, attributeValues));
                }
                catch (Exception ex)
                {
                    throw new IOException(String.Format(
                                              "An exception occurred parsing the datum at line {0}.",
                                              (datumElement as IXmlLineInfo).LineNumber), ex);
                }
            }).ToArray();

            return(new DataSet(schema, data));
        }
Beispiel #6
0
 public QuestionTreeNode(
     DatumSchema schema,
     IEnumerable <Datum> data,
     Attribute[] decidableAttributes,
     int level = 0,
     IImmutableDictionary <Attribute, string> knownValues = null)
 {
     Level       = level;
     Schema      = schema;
     Data        = data.ToArray();
     KnownValues = knownValues ?? ImmutableDictionary <Attribute, string> .Empty;
     foreach (Attribute attribute in decidableAttributes)
     {
         if (!schema.Attributes.Contains(attribute))
         {
             throw new InvalidOperationException(String.Format(
                                                     "The attribute {0} is not contained within the given schema.",
                                                     attribute));
         }
     }
     DecidableAttributes = decidableAttributes;
     Compute();
 }
Beispiel #7
0
 public DataSet(DatumSchema schema, params Datum[] data)
 {
     Schema = schema;
     Data   = data;
 }
 public DataSet(DatumSchema schema, params Datum[] data)
 {
     Schema = schema;
     Data = data;
 }
 public AnswerTreeNode(DatumSchema schema, string answer, IEnumerable<Datum> data, int level)
     : this(schema, answer, data.ToArray(), level)
 {
 }
 public AnswerTreeNode(DatumSchema schema, string answer, IEnumerable <Datum> data, int level)
     : this(schema, answer, data.ToArray(), level)
 {
 }