Exemplo n.º 1
0
        /// <summary>
        /// Save the object to XML.
        /// </summary>
        /// <param name="encogObject">The object to save.</param>
        /// <param name="xmlOut">The XML writer.</param>
        public void Save(IEncogPersistedObject encogObject, WriteXML xmlOut)
        {
            this.xmlOut = xmlOut;

            PersistorUtil.BeginEncogObject(encogObject.GetType().Name
                    , xmlOut, encogObject, true);

            this.tagger.Analyze(encogObject);

            foreach (FieldInfo childField in ReflectionUtil
                    .GetAllFields(encogObject.GetType()))
            {
                if (ReflectionUtil.ShouldAccessField(childField, true))
                {
                    Object childValue = childField.GetValue(encogObject);
                    xmlOut.BeginTag(childField.Name);
                    SaveField(childValue);
                    xmlOut.EndTag();
                }
            }

            xmlOut.EndTag();


        }
        /// <summary>
        /// Construct a directory entry for the specified object.
        /// </summary>
        /// <param name="obj">The Encog object.</param>
        public DirectoryEntry(IEncogPersistedObject obj)
        {
            String type = obj.GetType().Name;

            if (type.Equals("BasicNeuralDataSet"))
                type = EncogPersistedCollection.TYPE_TRAINING;

            this.type = type;
            this.description = obj.Description;
            this.name = obj.Name;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Construct a directory entry for the specified object.
        /// </summary>
        /// <param name="obj">The Encog object.</param>
        public DirectoryEntry(IEncogPersistedObject obj)
        {
            String type = obj.GetType().Name;

            if (type.Equals("BasicNeuralDataSet"))
            {
                type = EncogPersistedCollection.TYPE_TRAINING;
            }

            this.type        = type;
            this.description = obj.Description;
            this.name        = obj.Name;
        }
Exemplo n.º 4
0
        /// <summary>
        /// Save the object to XML.
        /// </summary>
        /// <param name="encogObject">The object to save.</param>
        /// <param name="xmlOut">The XML writer.</param>
        public void Save(IEncogPersistedObject encogObject, WriteXML xmlOut)
        {
            this.xmlOut = xmlOut;

            PersistorUtil.BeginEncogObject(encogObject.GetType().Name
                                           , xmlOut, encogObject, true);

            this.tagger.Analyze(encogObject);

            foreach (FieldInfo childField in ReflectionUtil
                     .GetAllFields(encogObject.GetType()))
            {
                if (ReflectionUtil.ShouldAccessField(childField, true))
                {
                    Object childValue = childField.GetValue(encogObject);
                    xmlOut.BeginTag(childField.Name);
                    SaveField(childValue);
                    xmlOut.EndTag();
                }
            }

            xmlOut.EndTag();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Analyze the specified object and build a reference map.
 /// </summary>
 /// <param name="encogObject">The object to analyze.</param>
 public void Analyze(IEncogPersistedObject encogObject)
 {
     this.depth = 0;
     AssignObjectTag(encogObject);
     foreach (FieldInfo childField in ReflectionUtil
              .GetAllFields(encogObject.GetType()))
     {
         if (ReflectionUtil.ShouldAccessField(childField, true))
         {
             Object childValue = childField.GetValue(encogObject);
             TagField(childValue);
         }
     }
 }
Exemplo n.º 6
0
        /// <summary>
        /// Analyze the specified object and build a reference map.
        /// </summary>
        /// <param name="encogObject">The object to analyze.</param>
        public void Analyze(IEncogPersistedObject encogObject)
        {

            this.depth = 0;
            AssignObjectTag(encogObject);
            foreach (FieldInfo childField in ReflectionUtil
                    .GetAllFields(encogObject.GetType()))
            {
                if (ReflectionUtil.ShouldAccessField(childField, true))
                {
                    Object childValue = childField.GetValue(encogObject);
                    TagField(childValue);
                }
            }

        }
Exemplo n.º 7
0
        /// <summary>
        /// Write an object.
        /// </summary>
        /// <param name="obj">The object to write.</param>
        public void WriteObject(IEncogPersistedObject obj)
        {
            IPersistor persistor = obj.CreatePersistor();

            if (persistor == null)
            {
                String str = "Can't find a persistor for object of type "
                             + obj.GetType().Name;
#if logging
                if (this.logger.IsErrorEnabled)
                {
                    this.logger.Error(str);
                }
#endif
                throw new PersistError(str);
            }
            persistor.Save(obj, this.xmlOut);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Write the beginning XML for an Encog object.
        /// </summary>
        /// <param name="objectType">The object type to persist.</param>
        /// <param name="xmlOut">The object that is being persisted.</param>
        /// <param name="obj">The XML writer.</param>
        /// <param name="top">Is this a top-level object, that needs a name
        /// and description?</param>
        public static void BeginEncogObject(String objectType,
                                            WriteXML xmlOut, IEncogPersistedObject obj,
                                            bool top)
        {
            if (top)
            {
                if (obj.Name != null)
                {
                    xmlOut.AddAttribute("name", obj.Name);
                }

                if (obj.Description != null)
                {
                    xmlOut.AddAttribute("description", obj.Description);
                }
                else
                {
                    xmlOut.AddAttribute("description", "");
                }
            }
            xmlOut.AddAttribute("native", obj.GetType().Name);
            xmlOut.AddAttribute("id", "1");
            xmlOut.BeginTag(objectType);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Write the beginning XML for an Encog object.
        /// </summary>
        /// <param name="objectType">The object type to persist.</param>
        /// <param name="xmlOut">The object that is being persisted.</param>
        /// <param name="obj">The XML writer.</param>
        /// <param name="top">Is this a top-level object, that needs a name
        /// and description?</param>
        public static void BeginEncogObject(String objectType,
                 WriteXML xmlOut, IEncogPersistedObject obj,
                 bool top)
        {
            if (top)
            {
                if (obj.Name != null)
                {
                    xmlOut.AddAttribute("name", obj.Name);
                }
                
                if (obj.Description != null)
                {
                    xmlOut.AddAttribute("description", obj.Description);
                }
                else
                {
                    xmlOut.AddAttribute("description", "");
                }

            }
            xmlOut.AddAttribute("native", obj.GetType().Name);
            xmlOut.AddAttribute("id", "1");
            xmlOut.BeginTag(objectType);
        }
Exemplo n.º 10
0
        /// <summary>
        /// Write an object.
        /// </summary>
        /// <param name="obj">The object to write.</param>
        public void WriteObject(IEncogPersistedObject obj)
        {
            IPersistor persistor = obj.CreatePersistor();
            if (persistor == null)
            {
                String str = "Can't find a persistor for object of type "
                       + obj.GetType().Name;
#if logging
                if (this.logger.IsErrorEnabled)
                {
                    this.logger.Error(str);
                }
#endif
                throw new PersistError(str);
            }
            persistor.Save(obj, this.xmlOut);
        }