示例#1
0
        //загрузка Format Data из файла
        private Tuple <PatternsType, KeysType, AnswersType> FormatLoad(string filePath)
        {
            string message = "Данные загружены из ";

            message += filePath + "\r\n";
            PatternsType patts = new PatternsType();
            KeysType     keys  = new KeysType();
            AnswersType  answs = new AnswersType();

            #region Read Answers
            int    posLastSlesh = filePath.LastIndexOf('\\');
            string answersPath  = filePath.Substring(0, posLastSlesh);
            answersPath += "\\answers.txt";
            answs        = LoadVec.LoadFloatVecWithKey(answersPath);
            #endregion
            #region Read Patterns
            string[] readText = File.ReadAllLines(filePath);
            foreach (string s in readText)
            {
                if (s.Trim() != "")
                {
                    string[]     elemsStr = s.Split(new char[] { ',' });
                    List <float> vec      = new List <float>(elemsStr.Length - 1);
                    string       key      = elemsStr[0];
                    for (int i = 1; i < elemsStr.Length; i++)
                    {
                        float floatEl;
                        bool  ok = float.TryParse(elemsStr[i], out floatEl);
                        if (ok)
                        {
                            vec.Add(floatEl);
                        }
                        else
                        {
                            FormConsole.PrintlnAndScroll("error try parse");
                            return(new Tuple <PatternsType, KeysType, AnswersType>(null, null, null));
                        }
                    }
                    patts.Add(vec);
                    keys.Add(key);
                }
            }
            #endregion
            FormConsole.PrintlnAndScroll(message);
            return(new Tuple <PatternsType, KeysType, AnswersType>(patts, keys, answs));
        }