/// <summary>
        /// Takes a GIS model and a file and writes the model to that file.
        /// </summary>
        /// <param name="model">
        /// The GisModel which is to be persisted.
        /// </param>
        /// <param name="fileName">
        /// The name of the file in which the model is to be persisted.
        /// </param>
        public void Persist(GisModel model, string fileName)
        {
            Initialize(model);
            PatternedPredicate[] predicates = GetPredicates();

            if (	File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            using (mDataConnection = new SQLiteConnection("Data Source=" + fileName + ";New=True;Compress=False;Synchronous=Off;UTF8Encoding=True;Version=3"))
            {
                mDataConnection.Open();
                mDataCommand = mDataConnection.CreateCommand();
                CreateDataStructures();

                using (mDataTransaction = mDataConnection.BeginTransaction())
                {
                    mDataCommand.Transaction = mDataTransaction;

                    CreateModel(model.CorrectionConstant, model.CorrectionParameter);
                    InsertOutcomes(model.GetOutcomeNames());
                    InsertPredicates(predicates);
                    InsertPredicateParameters(model.GetOutcomePatterns(), predicates);

                    mDataTransaction.Commit();
                }
                mDataConnection.Close();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Takes a GIS model and a file and writes the model to that file.
        /// </summary>
        /// <param name="model">
        /// The GisModel which is to be persisted.
        /// </param>
        /// <param name="fileName">
        /// The name of the file in which the model is to be persisted.
        /// </param>
        public void Persist(GisModel model, string fileName)
        {
            Initialize(model);
            PatternedPredicate[] predicates = GetPredicates();

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            using (mDataConnection = new SqliteConnection("Data Source=" + fileName + ";New=True;Compress=False;Synchronous=Off;UTF8Encoding=True;Version=3"))
            {
                mDataConnection.Open();
                mDataCommand = mDataConnection.CreateCommand();
                CreateDataStructures();

                using (mDataTransaction = mDataConnection.BeginTransaction())
                {
                    mDataCommand.Transaction = mDataTransaction;

                    CreateModel(model.CorrectionConstant, model.CorrectionParameter);
                    InsertOutcomes(model.GetOutcomeNames());
                    InsertPredicates(predicates);
                    InsertPredicateParameters(model.GetOutcomePatterns(), predicates);

                    mDataTransaction.Commit();
                }
                mDataConnection.Close();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Writes the predicate data to the file in a more efficient format to that implemented by
        /// GisModelWriter.
        /// </summary>
        /// <param name="model">
        /// The GIS model containing the predicate data to be persisted.
        /// </param>
        protected override void WritePredicates(GisModel model)
        {
            int[][] outcomePatterns         = model.GetOutcomePatterns();
            PatternedPredicate[] predicates = GetPredicates();

            //write the number of outcome patterns
            WriteInt32(outcomePatterns.Length);

            //write the number of predicates
            WriteInt32(predicates.Length);

            int currentPredicate = 0;

            for (int currentOutcomePattern = 0; currentOutcomePattern < outcomePatterns.Length; currentOutcomePattern++)
            {
                //write how many outcomes in this pattern
                WriteInt32(outcomePatterns[currentOutcomePattern].Length);

                //write the outcomes in this pattern (the first value contains the number of predicates in the pattern
                //rather than an outcome)
                for (int currentOutcome = 0; currentOutcome < outcomePatterns[currentOutcomePattern].Length; currentOutcome++)
                {
                    WriteInt32(outcomePatterns[currentOutcomePattern][currentOutcome]);
                }

                //write predicates for this pattern
                while (currentPredicate < predicates.Length && predicates[currentPredicate].OutcomePattern == currentOutcomePattern)
                {
                    WriteString(predicates[currentPredicate].Name);
                    for (int currentParameter = 0; currentParameter < predicates[currentPredicate].ParameterCount; currentParameter++)
                    {
                        WriteDouble(predicates[currentPredicate].GetParameter(currentParameter));
                    }
                    currentPredicate++;
                }
            }
        }
        /// <summary>
        /// Writes the predicate data to the file in a more efficient format to that implemented by
        /// GisModelWriter.
        /// </summary>
        /// <param name="model">
        /// The GIS model containing the predicate data to be persisted.
        /// </param>
        protected override void WritePredicates(GisModel model)
        {
            int[][] outcomePatterns = model.GetOutcomePatterns();
            PatternedPredicate[] predicates = GetPredicates();

            //write the number of outcome patterns
            WriteInt32(outcomePatterns.Length);

            //write the number of predicates
            WriteInt32(predicates.Length);

            int currentPredicate = 0;

            for (int currentOutcomePattern = 0; currentOutcomePattern < outcomePatterns.Length; currentOutcomePattern++)
            {
                //write how many outcomes in this pattern
                WriteInt32(outcomePatterns[currentOutcomePattern].Length);

                //write the outcomes in this pattern (the first value contains the number of predicates in the pattern
                //rather than an outcome)
                for (int currentOutcome = 0; currentOutcome < outcomePatterns[currentOutcomePattern].Length; currentOutcome++)
                {
                    WriteInt32(outcomePatterns[currentOutcomePattern][currentOutcome]);
                }

                //write predicates for this pattern
                while (currentPredicate < predicates.Length && predicates[currentPredicate].OutcomePattern == currentOutcomePattern)
                {
                    WriteString(predicates[currentPredicate].Name);
                    for (int currentParameter = 0; currentParameter < predicates[currentPredicate].ParameterCount; currentParameter++)
                    {
                        WriteDouble(predicates[currentPredicate].GetParameter(currentParameter));
                    }
                    currentPredicate++;
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Writes the predicate information to the model file.
 /// </summary>
 /// <param name="model">The GIS model to write the data from.</param>
 protected virtual void WritePredicates(GisModel model)
 {
     WriteOutcomePatterns(model.GetOutcomePatterns());
     WritePredicateNames();
     WriteParameters();
 }