Exemplo n.º 1
0
        public string Replace(string songLine, int whichLine)
        {
            SonGeneratorContext _entities = new SonGeneratorContext();
            PartAndClassificate partAndClassificate = new PartAndClassificate();

            var recognizeSpeech = partAndClassificate.PartingSpeechAndSentence(songLine);
            var wordsCounter = 0;
            string generateSongLine = "";
            var words = songLine.Split(new char[] { ' ' });

            foreach (var word in words)
            {
                if (word != "" && word != " ")
                {
                    var conditionalWord = _entities.Words.FirstOrDefault(x => x.WordName == word);
                    if (conditionalWord != null)
                    {
                        var wordToReplace = conditionalWord.WordName;
                        generateSongLine = generateSongLine + wordToReplace + " ";
                    }
                    else
                    {
                        generateSongLine = generateSongLine + " ";
                    }
                }
                wordsCounter++;
            }

            return generateSongLine;
        }
Exemplo n.º 2
0
 private void DeleteAllButton4Click(object sender, EventArgs e)
 {
     using (SonGeneratorContext _entities = new SonGeneratorContext())
     {
         progressBar1.Text = "Generujemy piosenkę";
         progressBar1.Maximum = 10;
         progressBar1.Value = 0;
         progressBar1.Refresh();
         var markovEntity = _entities.Markovs.Where(c => c.ID > 0).ToList();
         progressBar1.Value = 1;
         progressBar1.Refresh();
         var wordEntity = _entities.Words.Where(c => c.ID > 0).ToList();
         progressBar1.Value = 2;
         progressBar1.Refresh();
         var speechEntity = _entities.PartOfSpeeches.Where(c => c.ID > 0).ToList();
         progressBar1.Value = 4;
         progressBar1.Refresh();
         var sentenceEntity = _entities.PartOfSentences.Where(c => c.ID > 0).ToList();
         progressBar1.Value = 6;
         progressBar1.Refresh();
         _entities.Words.RemoveRange(wordEntity);
         progressBar1.Value = 7;
         progressBar1.Refresh();
         _entities.Markovs.RemoveRange(markovEntity);
         progressBar1.Value = 8;
         progressBar1.Refresh();
         _entities.PartOfSpeeches.RemoveRange(speechEntity);
         progressBar1.Value = 9;
         progressBar1.Refresh();
         _entities.PartOfSentences.RemoveRange(sentenceEntity);
         progressBar1.Value = 10;
         progressBar1.Refresh();
         _entities.SaveChanges();
         _entities.Dispose();
     }
 }
Exemplo n.º 3
0
        public void AddWords(string filePath)
        {
            SonGeneratorContext _entities = new SonGeneratorContext();

            PartAndClassificate partAndClassificate = new PartAndClassificate();
            SyllablesCounter sylabizer = new SyllablesCounter();
            LoadText loadText = new LoadText();
            MarkovPreparation markovPreparation = new MarkovPreparation();
            Words tempDbWords = new Words();
            PartOfSpeech tempPartOfSpeech = new PartOfSpeech();
            PartOfSentence tempPartOfSentence = new PartOfSentence();
            List<string> songText = new List<string>();
            SonGeneratorUI progressbar = new SonGeneratorUI();

            progressbar.progressBar1.Maximum = 50;
            progressbar.progressBar1.Value = 0;
            progressbar.Refresh();

            songText = loadText.LoadSentence(filePath).ToList();
            string word, speechTag, sentenceTag;
            int sylablessCounter = 0;

            progressbar.progressBar1.Value = 2;
            progressbar.Refresh();

            foreach (var songLine in songText)
            {
                var wordsCounter = 0;
                var recognizeSpeechAndSentence = partAndClassificate.PartingSpeechAndSentence(songLine);

                foreach (var sentence in recognizeSpeechAndSentence)
                {
                    word = sentence.Name;
                    sentenceTag = sentence.SentenceTag;
                    speechTag = recognizeSpeechAndSentence[wordsCounter].SpeechTag;
                    sylablessCounter = sylabizer.SyllableCount(word);

                    if (_entities.PartOfSentences.FirstOrDefault(x => x.PartOfSentenceField == sentenceTag) == null)
                    {
                        tempPartOfSentence = new PartOfSentence
                        {
                            PartOfSentenceField = sentenceTag
                        };
                    }
                    else
                    {
                        tempPartOfSentence =
                            _entities.PartOfSentences.FirstOrDefault(x => x.PartOfSentenceField == sentenceTag);
                    }

                    if (_entities.PartOfSpeeches.FirstOrDefault(x => x.PartOfSpeechField == speechTag) == null)
                    {
                        tempPartOfSpeech = new PartOfSpeech
                        {
                            PartOfSpeechField = speechTag
                        };
                    }
                    else
                    {
                        tempPartOfSpeech = _entities.PartOfSpeeches.FirstOrDefault(x => x.PartOfSpeechField == speechTag);
                    }

                    if (_entities.Words.FirstOrDefault(
                            x => x.WordName == word && x.NbOfLetter == word.Length) == null)
                    {
                        tempDbWords = new Words
                        {
                            NbOfLetter = word.Length,
                            WordName = word,
                            PartOfSentence = tempPartOfSentence,
                            PartOfSpeech = tempPartOfSpeech,
                            NbOfSylabs = sylablessCounter
                        };
                        _entities.Words.Add(tempDbWords);
                        _entities.SaveChanges();
                    }
                    wordsCounter++;
                }
                progressbar.progressBar1.Value = 30;
                progressbar.Refresh();
                markovPreparation.MarkovProbability(songLine);
                progressbar.progressBar1.Value = 50;
                progressbar.Refresh();
            }
            _entities.Dispose();
        }