Esempio n. 1
0
        public static void TestSong(List <string> lyrics)
        {
            // these genre variables will hold the total word matches of the song
            int hiphop = 0, country = 0, rock = 0, pop = 0;

            SongsDataContext            db         = new SongsDataContext();
            Table <ExclusiveWord>       exclusives = db.GetTable <ExclusiveWord>();
            Dictionary <string, string> genrecount = new Dictionary <string, string>();

            // object d is an anonymous type with fields word and genre - matching the columns of the Exclusive Words table.
            var d = (from x in exclusives
                     select new { x.word, x.genre });

            // storing these column values into a dictionary format
            foreach (var piece in d)
            {
                genrecount.Add(piece.word, piece.genre);
            }

            // counting how many words of the song matches each genre's key words
            for (int i = 0; i < lyrics.Count; i++)
            {
                if (genrecount.ContainsKey(lyrics[i]))
                {
                    if (genrecount[lyrics[i]] == "hiphop")
                    {
                        hiphop++;
                    }
                    else if (genrecount[lyrics[i]] == "country")
                    {
                        country++;
                    }
                    else if (genrecount[lyrics[i]] == "rock")
                    {
                        rock++;
                    }
                    else if (genrecount[lyrics[i]] == "pop")
                    {
                        pop++;
                    }
                }
            }
            // shows how close the song is to each genre
            Console.WriteLine($"The song has {pop} pop matches, {hiphop} hip hop matches,\n" +
                              $"{rock} rock matches, and {country} country matches");
        }
Esempio n. 2
0
        // saving rock lyrics to table 'rock'
        public static void SaveRock100(List <KeyValuePair <string, int> > insertList)
        {
            SongsDataContext db    = new SongsDataContext();
            Table <Rock>     Songs = db.GetTable <Rock>();

            var remove = from r in Songs
                         select r;

            db.Rocks.DeleteAllOnSubmit(remove);

            foreach (KeyValuePair <string, int> lyric in insertList)
            {
                Rock insertPair = new Rock()
                {
                    word = lyric.Key, frequency = lyric.Value
                };
                db.Rocks.InsertOnSubmit(insertPair);
            }
            db.SubmitChanges();
        }
Esempio n. 3
0
        // saving the top 100 overall songs to table 'top100'
        public static void SaveTop100(List <KeyValuePair <string, int> > insertList)
        {
            SongsDataContext db    = new SongsDataContext();
            Table <Top100>   Songs = db.GetTable <Top100>();

            var remove = from r in Songs
                         select r;

            db.Top100s.DeleteAllOnSubmit(remove);

            foreach (KeyValuePair <string, int> lyric in insertList)
            {
                Top100 insertPair = new Top100()
                {
                    word = lyric.Key, frequency = lyric.Value
                };
                db.Top100s.InsertOnSubmit(insertPair);
            }
            db.SubmitChanges();
            Console.WriteLine("complete");
        }
Esempio n. 4
0
        // save country top lyrics to table 'country'
        public static void SaveCountry100(List <KeyValuePair <string, int> > insertList)
        {
            SongsDataContext db    = new SongsDataContext();
            Table <Country>  Songs = db.GetTable <Country>();

            // deleting all info in the country table before saving the new info
            var remove = from r in Songs
                         select r;

            db.Countries.DeleteAllOnSubmit(remove);

            // saving each value into the table where the key is the word and the value is the genre
            foreach (KeyValuePair <string, int> lyric in insertList)
            {
                Country insertPair = new Country()
                {
                    word = lyric.Key, frequency = lyric.Value
                };
                db.Countries.InsertOnSubmit(insertPair);
            }
            db.SubmitChanges();
        }
 public SongsController(SongsDataContext context, IMapper mapper, MapperConfiguration config)
 {
     _context = context;
     _mapper  = mapper;
     _config  = config;
 }
Esempio n. 6
0
 public SongsController(SongsDataContext context)
 {
     _context = context;
 }
Esempio n. 7
0
        // Method to save all the exclusively used words for each genre in the table 'exclusive words'
        public static void SaveExclusives()
        {
            SongsDataContext      db             = new SongsDataContext();
            Table <ExclusiveWord> exclusiveWords = db.GetTable <ExclusiveWord>();

            // creating hashsets made up of the top 100 words used in each genre and saved in their respective table
            Table <Pop>      PopSongs = db.GetTable <Pop>();
            HashSet <string> popHash  = new HashSet <string>((from x in PopSongs
                                                              orderby x.frequency descending
                                                              select x.words).Take <string>(100));

            Table <HipHop>   HipHopSongs = db.GetTable <HipHop>();
            HashSet <string> hiphopHash  = new HashSet <string>((from x in HipHopSongs
                                                                 orderby x.frequency descending
                                                                 select x.word).Take <string>(100));

            Table <Country>  CountrySongs = db.GetTable <Country>();
            HashSet <string> countryHash  = new HashSet <string>((from x in CountrySongs
                                                                  orderby x.frequency descending
                                                                  select x.word).Take <string>(100));

            Table <Rock>     RockSongs = db.GetTable <Rock>();
            HashSet <string> rockHash  = new HashSet <string>((from x in RockSongs
                                                               orderby x.frequency descending
                                                               select x.word).Take <string>(100));

            // creating hashsets with of each genre that holds only words that were only found in the top 100 songs of that genre
            HashSet <string> tempHash = new HashSet <string>(hiphopHash);

            tempHash.ExceptWith(rockHash);
            tempHash.ExceptWith(popHash);
            tempHash.ExceptWith(countryHash);
            HashSet <string> exclusiveHipHop = new HashSet <string>(tempHash);

            tempHash = new HashSet <string>(rockHash);

            tempHash.ExceptWith(hiphopHash);
            tempHash.ExceptWith(popHash);
            tempHash.ExceptWith(countryHash);
            HashSet <string> exclusiveRock = new HashSet <string>(tempHash);

            tempHash = new HashSet <string>(countryHash);

            tempHash.ExceptWith(hiphopHash);
            tempHash.ExceptWith(popHash);
            tempHash.ExceptWith(rockHash);
            HashSet <string> exclusiveCountry = new HashSet <string>(tempHash);

            tempHash = new HashSet <string>(popHash);

            tempHash.ExceptWith(hiphopHash);
            tempHash.ExceptWith(rockHash);
            tempHash.ExceptWith(countryHash);
            HashSet <string> exclusivePop = new HashSet <string>(tempHash);

            // deleting all previous entries in the exclusive words table to prepare for inputing new more current entries
            var remove = from r in exclusiveWords
                         select r;

            db.ExclusiveWords.DeleteAllOnSubmit(remove);

            // saving each word in the exclusive set lists to the table ExclusiveWord with its respective genre
            foreach (string w in exclusivePop)
            {
                ExclusiveWord insertPair = new ExclusiveWord()
                {
                    word = w, genre = "pop"
                };
                db.ExclusiveWords.InsertOnSubmit(insertPair);
            }

            foreach (string w in exclusiveRock)
            {
                ExclusiveWord insertPair = new ExclusiveWord()
                {
                    word = w, genre = "rock"
                };
                db.ExclusiveWords.InsertOnSubmit(insertPair);
            }
            foreach (string w in exclusiveHipHop)
            {
                ExclusiveWord insertPair = new ExclusiveWord()
                {
                    word = w, genre = "hiphop"
                };
                db.ExclusiveWords.InsertOnSubmit(insertPair);
            }
            foreach (string w in exclusiveCountry)
            {
                ExclusiveWord insertPair = new ExclusiveWord()
                {
                    word = w, genre = "country"
                };
                db.ExclusiveWords.InsertOnSubmit(insertPair);
            }
            db.SubmitChanges();
        }