/// <summary> /// Takes a GisModel and a stream and writes the model to that stream. /// </summary> /// <param name="model"> /// The GisModel which is to be persisted. /// </param> /// <param name="writer"> /// The StreamWriter which will be used to persist the model. /// </param> public void Persist(GisModel model, StreamWriter writer) { using (mOutput = writer) { base.Persist(model); } }
/// <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(); } }
/// <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 full path and name of the file in which the model is to be persisted. /// </param> public void Persist(GisModel model, string fileName) { using (_output = new FileStream(fileName, FileMode.Create)) { base.Persist(model); } }
/// <summary> /// Takes a GIS model and a Stream and /// writes the model to that Stream. /// </summary> /// <param name="model"> /// The GIS model which is to be persisted. /// </param> /// <param name="dataOutputStream"> /// The Stream which will be used to persist the model. /// </param> public void Persist(GisModel model, Stream dataOutputStream) { using (_output = dataOutputStream) { base.Persist(model); } }
/// <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) { using (mOutput = new StreamWriter(fileName, false, System.Text.Encoding.UTF7)) { base.Persist(model); } }
/// <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(); } }
/// <summary> /// Writes the model to persistent storage, using the <code>writeX()</code> methods /// provided by extending classes. /// /// <p>This method delegates to worker methods for each part of this /// sequence. If you are creating a writer that conforms largely to this /// sequence but varies at one or more points, override the relevant worker /// method(s) to achieve the required format.</p> /// /// <p>If you are creating a writer for a format which does not follow this /// sequence at all, override this method and ignore the /// other WriteX methods provided in this abstract class.</p> /// </summary> /// <param name="model"> /// GIS model whose data is to be persisted. /// </param> protected void Persist(GisModel model) { Initialize(model); WriteModelType("GIS"); WriteCorrectionConstant(model.CorrectionConstant); WriteCorrectionParameter(model.CorrectionParameter); WriteOutcomes(model.GetOutcomeNames()); WritePredicates(model); }
private static void ConvertBinaryGisFileToPlainText(string inputFilePath, string outputFilePath) { var reader = new BinaryGisModelReader(inputFilePath); var model = new GisModel(reader); var writer = new PlainTextGisModelWriter(); writer.Persist(model, outputFilePath); }
static void Statistics(GisModel model, string testFilePath) { var results = new List <Tuple <string, bool, double> >(); // create detector from model var invalidEmailDetector = new MaximumEntropyInvalidEmailDetector(model); // read all test (email + invalid flag) lines var allLines = File.ReadAllLines(testFilePath); foreach (var line in allLines) { var parts = line.Split('\t'); var email = parts.First(); var isInvalid = parts.Last() == "1"; // store the result of the detection as well as the actual validity of the email var invalidProbability = invalidEmailDetector.GetInvalidProbability(email); results.Add(new Tuple <string, bool, double>(email, isInvalid, invalidProbability)); } // pretend to send the emails, and stop when we sent to many emails that bounced var nbOfEmailsSent = 0; var nbOfEmailsSentWhichWouldBounce = 0; var maxNbOfBouncePerDay = 25; foreach (var result in results.OrderBy(tup => tup.Item3)) { if (nbOfEmailsSentWhichWouldBounce < maxNbOfBouncePerDay) { nbOfEmailsSent++; if (result.Item2) { nbOfEmailsSentWhichWouldBounce++; } } Console.WriteLine("{0} ({1})", result.Item1, result.Item2 ? "INVALID": "OK"); } Console.WriteLine("Email that could have been sent: {0}", nbOfEmailsSent); Console.WriteLine("========"); // Quick summary of the detection var probaOfInvalidity = 0.2497; var nbOfSamples = results.Count; Console.WriteLine("Nb of samples: {0}", nbOfSamples); var nbOfCorrectResults = results.Count(tup => tup.Item2 == tup.Item3 > probaOfInvalidity); Console.WriteLine("Nb of correct results: {0}", nbOfCorrectResults); var nbOfNotDetected = results.Count(tup => tup.Item2 && !(tup.Item3 > probaOfInvalidity)); Console.WriteLine("Nb of not detected: {0}", nbOfNotDetected); var nbOfFalsePositive = results.Count(tup => !tup.Item2 && (tup.Item3 > probaOfInvalidity)); Console.WriteLine("Nb of false positive: {0}", nbOfFalsePositive); }
/// <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) { #if DNF using (mOutput = new StreamWriter(fileName, false, System.Text.Encoding.UTF7)) #else using (var stream = new FileStream(fileName, FileMode.Create)) #endif { base.Persist(model); } }
public void Init(FastLineRenderer defaultRenderer, FastLineRenderer selectionRenderer) { Ogr.RegisterAll(); model = new GisModel(); viewer = new GisViewer(); viewer.Init(); fastrenderer = new GisRenderer(); fastrenderer.Init(defaultRenderer, 0.02f); ss = new GisSelectionSet(); ss.Init(selectionRenderer, 0.2f); GisOperatingToolSet.SetHost(this); optool = new GisOperatingToolSet(); optool.Init(viewer); }
/// <summary> /// Organises the data available in the GIS model into a structure that is easier to /// persist from. /// </summary> /// <param name="model"> /// The GIS model to be persisted. ///</param> protected virtual void Initialize(GisModel model) { //read the predicates from the model Dictionary <string, PatternedPredicate> predicates = model.GetPredicates(); //build arrays of predicates and predicate names from the dictionary mPredicates = new PatternedPredicate[predicates.Count]; string[] predicateNames = new String[predicates.Count]; predicates.Values.CopyTo(mPredicates, 0); predicates.Keys.CopyTo(predicateNames, 0); //give each PatternedPredicate in the array the name taken from the dictionary keys for (int currentPredicate = 0; currentPredicate < predicates.Count; currentPredicate++) { mPredicates[currentPredicate].Name = predicateNames[currentPredicate]; } //sort the PatternedPredicate array based on the outcome pattern that each predicate uses Array.Sort(mPredicates, new OutcomePatternIndexComparer()); }
/// <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> /// Takes a GisModel and a Stream and writes the model to that stream. /// </summary> /// <param name="model"> /// The GIS model which is to be persisted. /// </param> /// <param name="dataOutputStream"> /// The Stream which will be used to persist the model. /// </param> public void Persist(GisModel model, Stream dataOutputStream) { using (mOutput = dataOutputStream) { base.Persist(model); } }
/// <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(); }