예제 #1
0
        public static RegExReaderData GuessFormat(StreamReader sr)
        {
            string          buffer;
            int             i = 0;
            List <string>   strs;
            string          number = @"\+\-\deE\.";
            RegExReaderData rx     = new RegExReaderData(@"\s*[" + number + @"]+([^" + number + @"]+)[" + number + @"]", new string[] { });


            List <string> guesses = new List <string>();

            while ((strs = rx.GetNextStrings(sr)) != null)
            {
                if (strs.Count > 0)
                {
                    guesses.Add(strs[0]);
                }

                i++;
                if (i > 50)
                {
                    break;
                }
            }

            Dictionary <string, int> frequency = new Dictionary <string, int>();

            foreach (string s in guesses)
            {
                if (!frequency.ContainsKey(s))
                {
                    frequency.Add(s, 0);
                }

                frequency[s]++;
            }

            string mostcommon = ";";
            int    max        = 0;

            foreach (string key in frequency.Keys)
            {
                if (frequency[key] > max)
                {
                    max        = frequency[key];
                    mostcommon = key;
                }
            }

            RegExReaderData reg = new RegExReaderData(mostcommon);

            return(reg);
        }
예제 #2
0
        public static RegExReaderData GuessFormat(string file)
        {
            RegExReaderData rx = null;

            if (File.Exists(file))
            {
                using (StreamReader sr = new StreamReader(file))
                {
                    rx = GuessFormat(sr);
                }
            }
            return(rx);
        }
        static void LoadDataSets()
        {
            RegExReaderData rs = new RegExReaderData(';', new string[] { });

            Type[] types = rs.GetType().Assembly.GetTypes();
            datasets = new List <RegExReaderData>();
            foreach (Type t in types)
            {
                if (t.IsSubclassOf(typeof(RegExReaderData)))
                {
                    datasets.Add((RegExReaderData)Activator.CreateInstance(t));
                }
            }
        }
        public static RegExReaderData GetReaderData(string readerdata)
        {
            RegExReaderData rerder = null;

            foreach (RegExReaderData rerd in datasets)
            {
                if (rerd.Name == readerdata)
                {
                    rerder = rerd;
                    break;
                }
            }
            if (Directory.Exists(dir))
            {
                string[] files = Directory.GetFiles(dir, "*.ftf");

                string name;
                string myname;
                string regex;
                string ignore;
                foreach (string s in files)
                {
                    name = Path.GetFileNameWithoutExtension(s);
                    if (name == readerdata)
                    {
                        using (StreamReader sr = new StreamReader(s))
                        {
                            myname      = sr.ReadLine();
                            regex       = Encoding.Unicode.GetString(Convert.FromBase64String(sr.ReadLine()));
                            ignore      = sr.ReadLine();
                            rerder      = new RegExReaderData(regex, ignore.Split(' '));
                            rerder.Name = name;
                        }
                    }
                }
            }

            return(rerder);
        }
 public ORBRegExReader(string filename, bool hasheader, RegExReaderData RegExReaderData)
     : base(filename, hasheader)
 {
     this.RegExReaderData = RegExReaderData;
 }