コード例 #1
0
        public void getGenreOfSong(String Lyrics)
        {
            NaiveBayesClassifier NB;
            RegexDataParser RDP = new RegexDataParser();
            UtilityFunctions utilityFunction = new UtilityFunctions();
            Hashtable Vocabulary = utilityFunction.TableToHashSumAdded((new FetchFromDB()).getVocabulary());

                NB = new NaiveBayesClassifier(freqTables);
                Lyrics = RDP.StripTagsRegexCompiled(Lyrics);
                String[] lyric = Lyrics.Split(' ');
                List<string> containinginVocab = new List<string>();
                for (int l = 0; l < lyric.Length; l++)
                {
                    if (Vocabulary.ContainsKey(lyric[l]))
                        containinginVocab.Add(lyric[l]);
                }
                Double[] classification = NB.ApplyBayes(containinginVocab.ToArray());
                int indx = NB.getMaxConfidence(classification);
                MessageBox.Show("Classified as :" + rawTables[indx], "COMP 6781: NLP", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
コード例 #2
0
 public void testFromDB()
 {
     NaiveBayesClassifier NB;
         RegexDataParser RDP;
         FetchFromDB fetchFromDb;
         UtilityFunctions utilityFunction = new UtilityFunctions();
         Hashtable Vocabulary = utilityFunction.TableToHashSumAdded((new FetchFromDB()).getVocabulary());
         DBProgressBar.ForeColor = Color.Blue;
         DBProgressBar.Value = 0;
         DBProgressBar.Visible = true;
         for (int i = 0; i < freqTables.Length; i++)
         {
             NB = new NaiveBayesClassifier(freqTables);
             RDP = new RegexDataParser();
             fetchFromDb = new FetchFromDB();
             DataTable dataTable = fetchFromDb.getTrainingDataFor(rawTables[i], 0);
             foreach (DataRow row in dataTable.Rows) // Loop over the rows.
                 foreach (var item in row.ItemArray) // Loop over the items.
                 {
                     String Lyrics = RDP.StripTagsRegexCompiled(item.ToString());
                     String[] lyric = Lyrics.Split(' ');
                     List<string> containinginVocab = new List<string>();
                     for (int l = 0; l < lyric.Length; l++)
                     {
                         if (Vocabulary.ContainsKey(lyric[l]))
                             containinginVocab.Add(lyric[l]);
                     }
                     Double[] classification = NB.ApplyBayes(containinginVocab.ToArray());
                     int indx = NB.getMaxConfidence(classification);
                     confusionMatrix[i, indx] = confusionMatrix[i, indx] + 1;
                 }
             dataTable = null;
             DBProgressBar.Value = DBProgressBar.Value + 100 / freqTables.Length;
         }
         Double[] rowFrequency = utilityFunction.getRowCount(confusionMatrix);
         Double[,] PercentageMatrix = new Double[rawTables.Length, rawTables.Length];
         for (int i = 0; i < 5; i++)
             for (int j = 0; j < 5; j++)
                 PercentageMatrix[i, j] = (confusionMatrix[i, j] * 100) / rowFrequency[i];
         String[] Genres = { "Rap", "Country", "Religion", "Rock", "Reggae" };
         InsertIntoDB insertMatrix = new InsertIntoDB();
         insertMatrix.insertConfusionMatrix(PercentageMatrix, Genres);
         ReportForm rf = new ReportForm();
         rf.Show();
 }