Beispiel #1
0
        public SuffixSensitivePerceptronModelWriter(AbstractModel model, string fileName) : base(model)
        {
            string file;
            Stream output;

            if (fileName.EndsWith(".gz"))
            {
                #if ZIPLIB
                output = new GZipOutputStream(new FileStream(fileName, FileMode.Create));
                #else
                output = new GZipStream(new FileStream(fileName, FileMode.Create), CompressionMode.Compress);
                #endif
                file = fileName.Substring(0, fileName.Length - 3);
            }
            else
            {
                file   = fileName;
                output = new FileStream(fileName, FileMode.Create);
            }

            if (file.EndsWith(".bin"))
            {
                suffixAppropriateWriter = new BinaryPerceptronModelWriter(model, output);
            }
            else
            {
                // default is ".txt"
                suffixAppropriateWriter = new PlainTextPerceptronModelWriter(model, output);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Constructor which takes a GISModel and a File and invokes the
        /// GISModelWriter appropriate for the suffix.
        /// </summary>
        /// <param name="model"> The GISModel which is to be persisted. </param>
        /// <param name="f"> The File in which the model is to be stored. </param>
        public SuffixSensitivePerceptronModelWriter(AbstractModel model, Jfile f) : base(model)
        {
            OutputStream output;
            string       filename = f.Name;

            // handle the zipped/not zipped distinction
            if (filename.EndsWith(".gz", StringComparison.Ordinal))
            {
                output   = new GZIPOutputStream(new FileOutputStream(f));
                filename = filename.Substring(0, filename.Length - 3);
            }
            else
            {
                output = new DataOutputStream(new FileOutputStream(f));
            }

            // handle the different formats
            if (filename.EndsWith(".bin", StringComparison.Ordinal))
            {
                suffixAppropriateWriter = new BinaryPerceptronModelWriter(model, new DataOutputStream(output));
            }
            else // default is ".txt"
            {
                suffixAppropriateWriter = new PlainTextPerceptronModelWriter(model,
                                                                             new BufferedWriter(new OutputStreamWriter(output)));
            }
        }