示例#1
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int id)
        {
            Artist.ArtistID = id;

            if (!ModelState.IsValid)
            {
                error = string.Join(" | ", ModelState.Values
                                    .SelectMany(v => v.Errors)
                                    .Select(e => e.ErrorMessage));

                error += id.ToString();

                return(Page());
            }

            Artist.Listens = 0;

            Artist.Rating = 1;

            Artist.WordVec = Vspace.ConvertToString(Vspace.Add(_textprocessor.PredictText(Artist.Name), _textprocessor.PredictText(Artist.Description)));

            await _access.Create(id, Artist);

            return(RedirectToPage("./Index"));
        }
        public async Task OnGetAsync()
        {
            if (SearchString.Length > 0)
            {
                List <Song> songs = _context.Song.ToList();

                var word_vector = _textprocessor.PredictText(SearchString);
                lv = NaturalLanguage.vector.VectorSpace.ToString(word_vector);

                if (!string.IsNullOrEmpty(SearchString))
                {
                    foreach (var song in songs)
                    {
                        msg += song.Name + ": " + NaturalLanguage.vector.VectorSpace.Loss(word_vector, NaturalLanguage.vector.VectorSpace.ToArray(song.WordVec)) + ", ";
                    }

                    songs.Sort((a, b) => NaturalLanguage.vector.VectorSpace.Loss(word_vector,
                                                                                 NaturalLanguage.vector.VectorSpace.ToArray(a.WordVec)).CompareTo(NaturalLanguage.vector.VectorSpace.Loss(word_vector, NaturalLanguage.vector.VectorSpace.ToArray(b.WordVec))));
                }
                Song = songs;
            }
            else
            {
                Song = await _context.Song.ToListAsync();
            }
        }
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                error = string.Join(" | ", ModelState.Values
                                    .SelectMany(v => v.Errors)
                                    .Select(e => e.ErrorMessage));
                return(Page());
            }

            Song.WordVec = NaturalLanguage.vector.VectorSpace.ToString(_textprocessor.PredictText(Song.Lyrics));

            _context.Song.Add(Song);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#4
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            file = Path.Combine(_environment.ContentRootPath, "wwwroot", "music", UploadedFile.FileName);
            using (var fileStream = new FileStream(file, FileMode.Create))
            {
                await UploadedFile.CopyToAsync(fileStream);
            }

            string filename = UploadedFile.FileName;

            filename.Replace(" ", string.Empty);
            Song.Filepath = "/music/" + filename;

            User user = _context.User.FirstOrDefault(u => u.Username == User.Identity.Name);

            Artist artist = _context.Artist.FirstOrDefault(a => a.ArtistID == id);

            Genre genre = _context.Genre.FirstOrDefault(g => g.Name == Song.Genre.Name);

            if (genre == null)
            {
                genre = new Genre
                {
                    Name    = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Song.Genre.Name.ToLower()),
                    WordVec = VSpace.ConvertToString(_textprocessor.PredictText(Song.Genre.Name))
                };
                _context.Genre.Add(genre);
            }

            Song.Genre = genre;

            var album = _context.Album.FirstOrDefault(a => a.Name == Song.Album.Name && a.Artist.ArtistID == id);

            if (album == null)
            {
                Album Album = new Album
                {
                    Name   = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Song.Album.Name),
                    Artist = artist
                };
                Song.Album = Album;
                _context.Album.Add(Album);
            }
            else
            {
                Song.Album = album;
            }

            _textprocessor.PredictText(Song.Lyrics);

            Song.Listens = 1;

            NaturalLanguage.vector.VectorSpace.ToArray(artist.WordVec);

            NaturalLanguage.vector.VectorSpace.ToArray(genre.WordVec);

            NaturalLanguage.vector.VectorSpace.Scale(genre_contrib, NaturalLanguage.vector.VectorSpace.ToArray(genre.WordVec));

            Song.WordVec = VSpace.ConvertToString(
                VSpace.Normalize(VSpace.Add(_textprocessor.PredictText(Song.Lyrics), _textprocessor.PredictText(Song.Name))));

            _reader.Read(Path.Combine(Environment.CurrentDirectory, "wwwroot/music",
                                      filename));

            double[][] res = AudioAnalysis.Fourier.FFT(_reader.GetStream(), 200, _reader.GetSampleRate());
            int[]      f   = AudioAnalysis.Compare.ToIntArray(res[1]);

            Song.FreqVec = AudioAnalysis.Compare.ToString(f);

            _context.Song.Add(Song);
            await _context.SaveChangesAsync();

            return(RedirectToPage("./Index"));
        }
示例#5
0
        public async Task OnGetAsync(int?id)
        {
            preference_vector = Vspace.Ones(10);

            if (HttpContext.User.Identity.IsAuthenticated)
            {
                int _id = Int32.Parse(HttpContext.User.Claims.Where(c => c.Type == "UserID").Select(c => c.Value).SingleOrDefault());
                Playlists         = _context.Playlist.Where(p => p.User.UserID == _id).ToList();
                _User             = _context.User.Find(_id);
                preference_vector = Vspace.ToArray(_User.PreferenceVector);
            }

            if (id != null)
            {
                Song = await _context.Song.Where(s => s.Album.Artist.ArtistID == id).Include(x => x.Genre).Include(x => x.Album).ThenInclude(x => x.Artist).ToListAsync();
            }
            else
            {
                List <Song> songs = _context.Song.Include(x => x.Genre).Include(x => x.Album).ThenInclude(x => x.Artist).ToList();

                if (SearchString.Length > 0)
                {
                    SearchString = SearchString.ToLower();

                    if (!string.IsNullOrEmpty(SearchString))
                    {
                        Song s = _context.Song.Where(x => x.Name.ToLower() == SearchString).FirstOrDefault();

                        if (s != null)
                        {
                            int[] f = AudioAnalysis.Compare.ToArray(s.FreqVec);
                            songs = songs.OrderByDescending(x => AudioAnalysis.Compare.Similarity(f, AudioAnalysis.Compare.ToArray(x.FreqVec)) + .01 * x.Rating / (double)x.Listens).ToList();
                            foreach (var song in songs)
                            {
                                msg += song.Name + ":" + AudioAnalysis.Compare.Similarity(f, AudioAnalysis.Compare.ToArray(song.FreqVec)) + "; ";
                            }
                        }
                        else
                        {
                            Artist a = _context.Artist.Where(x => x.Name.ToLower() == SearchString).FirstOrDefault();

                            if (a != null)
                            {
                                songs = _context.Song.Where(s => s.Album.Artist.ArtistID == a.ArtistID).ToList();
                                songs = songs.OrderByDescending(x => .01 * x.Rating / (double)x.Listens).ToList();
                            }
                            else
                            {
                                Genre g = _context.Genre.Where(x => x.Name.ToLower() == SearchString).FirstOrDefault();

                                if (g != null)
                                {
                                    songs = _context.Song.Where(s => s.Genre.GenreID == g.GenreID).ToList();
                                    songs = songs.OrderByDescending(x => .01 * x.Rating / (double)x.Listens).ToList();
                                }
                                else
                                {
                                    var word_vector = _textprocessor.PredictText(SearchString);


                                    songs.Sort((a, b) =>
                                               (Vspace.Loss(word_vector, Vspace.ToArray(a.WordVec)).CompareTo(Vspace.Loss(word_vector, Vspace.ToArray(b.WordVec)))));
                                }
                            }
                        }
                    }
                }
                Song = songs;
            }
        }
示例#6
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            Song s = _context.Song.Where(x => x.SongID == Song.SongID).FirstOrDefault();



            User user = _context.User.FirstOrDefault(u => u.Username == User.Identity.Name);

            Artist artist = _context.Artist.FirstOrDefault(a => a.ArtistID == user.UserID);

            Album a = _context.Album.Where(x => x.Name == Song.Album.Name && x.Artist.ArtistID == user.UserID).FirstOrDefault();
            Genre g = _context.Genre.Where(x => x.Name == Song.Genre.Name).FirstOrDefault();

            //if (a == null)
            //{
            //    Album Album = new Album
            //    {
            //        Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Song.Album.Name),
            //        Artist = artist
            //    };
            //    Song.Album = Album;
            //    _context.Album.Add(Album);
            //}
            //else
            //{
            //    Song.Album = a;
            //}


            //if (g == null)
            //{
            //    g = new Genre
            //    {
            //        Name = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Song.Genre.Name.ToLower()),
            //        WordVec = Vspace.ConvertToString(_textprocessor.PredictText(Song.Genre.Name))
            //    };
            //    _context.Genre.Add(g);
            //}

            //Song.Genre = g;

            //Song.Filepath = ;

            Song.WordVec = VSpace.ConvertToString(
                VSpace.Normalize(VSpace.Add(_textprocessor.PredictText(Song.Lyrics), _textprocessor.PredictText(Song.Name))));


            _context.Song.Update(s);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SongExists(Song.SongID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(RedirectToPage("./Index"));
        }