//Analyzer _nBayesAnalyzer;
        //public Analyzer nBayesAnalyzer
        //{
        //    get
        //    {
        //        if (_nBayesAnalyzer == null)
        //        {
        //            _nBayesAnalyzer = new Analyzer();
        //        }
        //        return _nBayesAnalyzer;
        //    }
        //}

        //Index _nBayesBlackIndex;
        //public Index nBayesBlackIndex
        //{
        //    get
        //    {
        //            ReadFile();
        //        return _nBayesBlackIndex;
        //    }
        //}

        //Index _nBayesWhiteIndex;
        //public Index nBayesWhiteIndex
        //{
        //    get
        //    {
        //            ReadFile();
        //        return _nBayesWhiteIndex;
        //    }
        //}

        //private void AddWordToIndex(string name, Index index)
        //{
        //    index.Add(Entry.FromString(name));

        //    string[] splittedNames = SplitNameByCapital(name);
        //    foreach (string s in splittedNames)
        //    {
        //        index.Add(Entry.FromString(s));
        //    }
        //}

        public override void ParseLines()
        {
            string profileName = null;

            _blackCustomRules = new List<string>();
            _whiteCustomRules = new List<string>();
            _defaultRuleEnabled = new Dictionary<int, bool>();
            _whiteList = new Dictionary<string, bool>();
            _blackList = new Dictionary<string, bool>();

            Type randomFileType = typeof(RandomFile);

            foreach (string line in this.Lines)
            {
                if (line.StartsWith("[") && line.EndsWith("]"))
                {
                    profileName = line.Substring(1, line.Length - 2);
                }
                else if (profileName == "WhiteList")
                {
                    AddWhiteWord(line);
                }
                else if (profileName == "BlackList")
                {
                    AddBlackWord(line);
                }
                else if (profileName == "BlackCustomRules")
                {
                    _blackCustomRules.Add(line);
                }
                else if (profileName == "WhiteCustomRules")
                {
                    _whiteCustomRules.Add(line);
                }
                else if (profileName == "Settings")
                {
                    string[] s = line.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (s.Length == 2)
                    {
                        string propertyName = s[0];
                        string propertyValue = s[1];

                        Match m = regexDefaultRules.Match(propertyName);
                        if (m.Success)
                        {
                            _defaultRuleEnabled.Add(Convert.ToInt32(m.Groups[1].Value), Convert.ToBoolean(propertyValue));
                        }
                        else
                        {
                            PropertyInfo pi = randomFileType.GetProperty(propertyName);
                            if (pi != null)
                            {
                                if (propertyName.EndsWith("Enabled"))
                                {
                                    bool b;
                                    if (bool.TryParse(propertyValue, out b))
                                    {
                                        pi.SetValue(this, b, null);
                                    }
                                }
                                else if (propertyName.EndsWith("Length"))
                                {
                                    pi.SetValue(this, Convert.ToInt32(propertyValue), null);
                                }
                                else if (propertyName.EndsWith("Percentage"))
                                {
                                    double d;
                                    if (double.TryParse(propertyValue, out d))
                                    {
                                        pi.SetValue(this, d, null);
                                    }
                                    else if (double.TryParse(propertyValue, NumberStyles.AllowDecimalPoint, new CultureInfo("en-US"), out d))
                                    {
                                        pi.SetValue(this, d, null);
                                    }
                                }
                                else
                                {
                                    pi.SetValue(this, propertyValue, null);
                                }
                            }
                        }
                    }
                }

            }//end foreach

            
            //init default rules
            for (int i = 0; i < 1; i++)
            {
                if (!_defaultRuleEnabled.ContainsKey(i))
                {
                    _defaultRuleEnabled.Add(i, true);
                }
            }

            if(_validNameMaxLength < 0)
                _validNameMaxLength = defaultValidNameMaxLength;
            if (_randomNameMinLength < 0)
                _randomNameMinLength = defaultRandomNameMinLength;
            if (_abnormalMinPercentage < 0)
                _abnormalMinPercentage = defaultAbnormalPercentage;

            if (_dictionaryEnabled && File.Exists(this.DictionaryFile))
            {
                TextFile tf = new TextFile(DictionaryFile);
                foreach (string line in tf.Lines)
                {
                    AddWhiteWord(line);
                }
            }

            //if (nBayesEnabled)
            //{
            //    _nBayesWhiteIndex = Index.CreateMemoryIndex();
            //    foreach (string word in WhiteList.Keys)
            //    {
            //        AddWordToIndex(word, _nBayesWhiteIndex);
            //    }
            //    if (DictionaryEnabled && File.Exists(DictionaryFile))
            //    {
            //        TextFile tf = new TextFile(DictionaryFile);
            //        foreach (string line in tf.Lines)
            //        {
            //            AddWordToIndex(line, _nBayesWhiteIndex);
            //        }
            //    }

            //    _nBayesBlackIndex = Index.CreateMemoryIndex();
            //    foreach (string word in BlackList.Keys)
            //    {
            //        AddWordToIndex(word, _nBayesBlackIndex);
            //    }
            //}
        }
        //Analyzer _nBayesAnalyzer;
        //public Analyzer nBayesAnalyzer
        //{
        //    get
        //    {
        //        if (_nBayesAnalyzer == null)
        //        {
        //            _nBayesAnalyzer = new Analyzer();
        //        }
        //        return _nBayesAnalyzer;
        //    }
        //}

        //Index _nBayesBlackIndex;
        //public Index nBayesBlackIndex
        //{
        //    get
        //    {
        //            ReadFile();
        //        return _nBayesBlackIndex;
        //    }
        //}

        //Index _nBayesWhiteIndex;
        //public Index nBayesWhiteIndex
        //{
        //    get
        //    {
        //            ReadFile();
        //        return _nBayesWhiteIndex;
        //    }
        //}

        //private void AddWordToIndex(string name, Index index)
        //{
        //    index.Add(Entry.FromString(name));

        //    string[] splittedNames = SplitNameByCapital(name);
        //    foreach (string s in splittedNames)
        //    {
        //        index.Add(Entry.FromString(s));
        //    }
        //}

        public override void ParseLines()
        {
            string profileName = null;

            _blackCustomRules   = new List <string>();
            _whiteCustomRules   = new List <string>();
            _defaultRuleEnabled = new Dictionary <int, bool>();
            _whiteList          = new Dictionary <string, bool>();
            _blackList          = new Dictionary <string, bool>();

            Type randomFileType = typeof(RandomFile);

            foreach (string line in this.Lines)
            {
                if (line.StartsWith("[") && line.EndsWith("]"))
                {
                    profileName = line.Substring(1, line.Length - 2);
                }
                else if (profileName == "WhiteList")
                {
                    AddWhiteWord(line);
                }
                else if (profileName == "BlackList")
                {
                    AddBlackWord(line);
                }
                else if (profileName == "BlackCustomRules")
                {
                    _blackCustomRules.Add(line);
                }
                else if (profileName == "WhiteCustomRules")
                {
                    _whiteCustomRules.Add(line);
                }
                else if (profileName == "Settings")
                {
                    string[] s = line.Split(new char[] { '=' }, StringSplitOptions.RemoveEmptyEntries);
                    if (s.Length == 2)
                    {
                        string propertyName  = s[0];
                        string propertyValue = s[1];

                        Match m = regexDefaultRules.Match(propertyName);
                        if (m.Success)
                        {
                            _defaultRuleEnabled.Add(Convert.ToInt32(m.Groups[1].Value), Convert.ToBoolean(propertyValue));
                        }
                        else
                        {
                            PropertyInfo pi = randomFileType.GetProperty(propertyName);
                            if (pi != null)
                            {
                                if (propertyName.EndsWith("Enabled"))
                                {
                                    bool b;
                                    if (bool.TryParse(propertyValue, out b))
                                    {
                                        pi.SetValue(this, b, null);
                                    }
                                }
                                else if (propertyName.EndsWith("Length"))
                                {
                                    pi.SetValue(this, Convert.ToInt32(propertyValue), null);
                                }
                                else if (propertyName.EndsWith("Percentage"))
                                {
                                    double d;
                                    if (double.TryParse(propertyValue, out d))
                                    {
                                        pi.SetValue(this, d, null);
                                    }
                                    else if (double.TryParse(propertyValue, NumberStyles.AllowDecimalPoint, new CultureInfo("en-US"), out d))
                                    {
                                        pi.SetValue(this, d, null);
                                    }
                                }
                                else
                                {
                                    pi.SetValue(this, propertyValue, null);
                                }
                            }
                        }
                    }
                }
            }//end foreach


            //init default rules
            for (int i = 0; i < 1; i++)
            {
                if (!_defaultRuleEnabled.ContainsKey(i))
                {
                    _defaultRuleEnabled.Add(i, true);
                }
            }

            if (_validNameMaxLength < 0)
            {
                _validNameMaxLength = defaultValidNameMaxLength;
            }
            if (_randomNameMinLength < 0)
            {
                _randomNameMinLength = defaultRandomNameMinLength;
            }
            if (_abnormalMinPercentage < 0)
            {
                _abnormalMinPercentage = defaultAbnormalPercentage;
            }

            if (_dictionaryEnabled && File.Exists(this.DictionaryFile))
            {
                TextFile tf = new TextFile(DictionaryFile);
                foreach (string line in tf.Lines)
                {
                    AddWhiteWord(line);
                }
            }

            //if (nBayesEnabled)
            //{
            //    _nBayesWhiteIndex = Index.CreateMemoryIndex();
            //    foreach (string word in WhiteList.Keys)
            //    {
            //        AddWordToIndex(word, _nBayesWhiteIndex);
            //    }
            //    if (DictionaryEnabled && File.Exists(DictionaryFile))
            //    {
            //        TextFile tf = new TextFile(DictionaryFile);
            //        foreach (string line in tf.Lines)
            //        {
            //            AddWordToIndex(line, _nBayesWhiteIndex);
            //        }
            //    }

            //    _nBayesBlackIndex = Index.CreateMemoryIndex();
            //    foreach (string word in BlackList.Keys)
            //    {
            //        AddWordToIndex(word, _nBayesBlackIndex);
            //    }
            //}
        }