コード例 #1
0
        /// <summary>
        /// Gets the information the user wishes to analyse and prepares it for the network to analyse
        /// </summary>
        /// <param name="file">the file the user wishes to analyse</param>
        public void GetAnalysedText(FileObj file)
        {
            FileReadWrite frw           = new FileReadWrite();
            CategoryObj   analysingText = new CategoryObj(frw.GetStopWords(), frw.GetSuffixes());

            analysingText.Name = file.FileName;
            analysingText.AddText(file.FileContent);
            _analysingText = analysingText;
        }
コード例 #2
0
        /// <summary>
        /// Trains the network
        /// </summary>
        public void Train()
        {
            FileReadWrite frw = new FileReadWrite();

            //get the training files
            FileObj[]          files      = frw.GetTrainingData();
            List <CategoryObj> categories = new List <CategoryObj>();
            bool exists = false;

            //classifies the categories using the files
            foreach (FileObj f in files)
            {
                string category = ""; //name of the new category

                //creates the category name
                foreach (char c in f.FileName)
                {
                    if (c != '0' && c != '1' && c != '2' && c != '3' && c != '4' && c != '5' && c != '6' && c != '7' && c != '8' && c != '9' && c != '.')
                    {
                        category += c;
                    }
                    else
                    {
                        break;
                    }
                }
                exists = false;
                //checks if information can be added to an existing category
                foreach (CategoryObj cat in categories)
                {
                    if (cat.Name == category)
                    {
                        exists = true;
                        cat.AddText(f.FileContent);
                    }
                }
                //makes a new category if the category doesn't already exist
                if (!exists)
                {
                    CategoryObj newCategory = new CategoryObj(frw.GetStopWords(), frw.GetSuffixes());
                    newCategory.Name = category;
                    newCategory.AddText(f.FileContent);

                    categories.Add(newCategory);
                }
            }
            //adds the list of categorys tot he known information
            _knownInformation = categories;
        }