コード例 #1
0
        public void SetUp()
        {
            CleanRepositories();

            AUTHOR = new Author("sada", "sadasd", "sdaasd", new DateTime(1995, 2, 3));

            Entity google    = new Entity("Google");
            Entity starbucks = new Entity("Starbucks");

            ENTITITES = new List <Entity>();
            ENTITITES.Add(google);
            ENTITITES.Add(starbucks);

            Sentiment positive = new Sentiment(SentimentType.POSITIVE, "i like");
            Sentiment negative = new Sentiment(SentimentType.NEGATIVE, "i dont like");

            SENTIMENTS = new List <Sentiment>();
            SENTIMENTS.Add(positive);
            SENTIMENTS.Add(negative);

            PHRASE = new Phrase("I like Google", DateTime.Now, AUTHOR);

            ALARM  = new EntityAlarm("1", "1", SentimentType.POSITIVE, google);
            ALARMS = new List <EntityAlarm>();
            ALARMS.Add(ALARM);

            REPOSITORY = new PhraseRepository();
        }
        public void ModifySentimentNotUpdatePhraseWithoutType()
        {
            PhraseRepository phraseRepository = new PhraseRepository();
            AuthorRepository authorRepository = new AuthorRepository();

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i love");

            authorRepository.Add(AUTHOR);

            try
            {
                REPOSITORY.Add(sentiment);
            }
            catch (AnalysisException) { }

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            SENTIMENT.Word = "i dont like";
            SENTIMENT.Type = SentimentType.NEGATIVE;

            REPOSITORY.Modify(sentiment.Id, SENTIMENT);

            Assert.IsNull(phraseRepository.Get(phrase.Id).Type);
        }
        public void ModifyUpdatePhrasesWithEntityNull()
        {
            Entity entity = new Entity("Microsoft");

            REPOSITORY.Add(entity);

            SentimentRepository sentimentRepository = new SentimentRepository();
            PhraseRepository    phraseRepository    = new PhraseRepository();
            AuthorRepository    authorRepository    = new AuthorRepository();

            authorRepository.Add(AUTHOR);

            try
            {
                sentimentRepository.Add(new Sentiment(SentimentType.POSITIVE, "i like"));
            }
            catch (AnalysisException) { }

            Phrase phrase = new Phrase("I like Uber", DateTime.Now, AUTHOR);

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            entity.Name = "Uber";

            REPOSITORY.Modify(entity.Id, entity);

            Assert.AreEqual(phraseRepository.Get(phrase.Id).Entity, entity);
        }
コード例 #4
0
        private void LoadGrid()
        {
            IRepository <Phrase> phraseRepository = new PhraseRepository();

            var reports = phraseRepository.GetAll().ToList();

            List <Analysis> reportPhrases = new List <Analysis>();

            reports.ForEach(r =>
                            reportPhrases.Add(new Analysis()
            {
                Author        = r.Author.ToString(),
                Word          = r.Word,
                SentimentType = r.Type != null
                    ? r.Type.ToString()
                    : string.Empty,
                PostedDate = r.PostedDate.ToString("dd/MM/yyyy HH:mm"),
                Entity     = r.Entity != null
                    ? r.Entity.ToString()
                    : string.Empty,
                Grade = r.Type == SentimentType.NEUTRAL
                    ? string.Empty
                    : r.Grade.ToString()
            })
                            );;

            dgvPhrases.DataSource = reportPhrases.ToList();
        }
コード例 #5
0
        public JsonResult AddPhrase(Phrase phrase)
        {
            PhraseRepository phraseRepository = new PhraseRepository();
            int id = phraseRepository.Insert(phrase);

            return(Json(new { id = id }, JsonRequestBehavior.AllowGet));
        }
        public void AddSentimentUpdatesPhrases()
        {
            PhraseRepository phraseRepository = new PhraseRepository();

            phraseRepository.Clear();

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Clear();

            authorRepository.Add(AUTHOR);

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            try
            {
                REPOSITORY.Add(sentiment);
            }
            catch (AnalysisException) { }

            Assert.AreEqual(sentiment.Type, phraseRepository.Get(phrase.Id).Type);
        }
コード例 #7
0
        private void LoadGrid()
        {
            IRepository <EntityAlarm> entityAlarmRepository = new EntityAlarmRepository();
            IRepository <AuthorAlarm> authorAlarmRepository = new AuthorAlarmRepository();
            IRepository <Phrase>      phrasesRepository     = new PhraseRepository();

            List <Alert> alerts = new List <Alert>();

            #region Entity Alarms

            var activeEntityAlarms = entityAlarmRepository.GetAll().Where(a => a.IsEnabled()).ToList();

            activeEntityAlarms.ForEach(a =>
                                       alerts.Add(new Alert()
            {
                NumberDays    = a.Time.ToString(),
                CantPost      = a.PostQuantity.ToString(),
                Entity        = a.Entity.Name.ToString(),
                InitDate      = a.CreationDate.ToString("dd/MM/yyyy HH:mm"),
                SentimentType = a.Type.ToString(),
                Authors       = string.Empty
            })
                                       );

            #endregion

            #region Author Alarms

            var activeAuthorAlarms = authorAlarmRepository.GetAll().Where(a => a.IsEnabled()).ToList();

            var phrases = phrasesRepository.GetAll().ToList();


            foreach (AuthorAlarm alarm in activeAuthorAlarms)
            {
                var phrasesInRange = phrases
                                     .Where(p => p.Type == alarm.Type && alarm.InRangeOfTime(p.PostedDate))
                                     .GroupBy(p => p.Author.Username);

                string authorsName = "";

                phrasesInRange.Select(p => p.Key).ToList().ForEach(a => authorsName += a + ",");

                alerts.Add(new Alert()
                {
                    NumberDays    = alarm.Time.ToString(),
                    CantPost      = alarm.PostQuantity.ToString(),
                    Entity        = string.Empty,
                    InitDate      = alarm.CreationDate.ToString("dd/MM/yyyy HH:mm"),
                    SentimentType = alarm.Type.ToString(),
                    Authors       = authorsName.Substring(0, authorsName.Length - 1)
                });
            }
            #endregion

            dgvAlerts.DataSource = alerts.ToList();
        }
        public void ModifySentimentNoUpdateDifferentSentimentTypeAlarm()
        {
            PhraseRepository      phraseRepository = new PhraseRepository();
            EntityRepository      entityRepository = new EntityRepository();
            AuthorRepository      authorRepository = new AuthorRepository();
            EntityAlarmRepository alarmRepository  = new EntityAlarmRepository();

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Entity    google    = new Entity("google");
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

            authorRepository.Add(AUTHOR);

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            try
            {
                entityRepository.Add(google);
            }
            catch (AnalysisException) { }

            try
            {
                phrase.AnalyzePhrase(new List <Entity> {
                    google
                }, new List <Sentiment> {
                    sentiment
                });
            }
            catch (AnalysisException) { }

            try
            {
                REPOSITORY.Add(sentiment);
            }
            catch (AnalysisException) { }

            SENTIMENT.Word = "i dont like";
            SENTIMENT.Type = SentimentType.NEGATIVE;

            REPOSITORY.Modify(sentiment.Id, SENTIMENT);

            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.NEGATIVE, google);

            alarmRepository.Add(alarm);

            SENTIMENT.Word = "i really like";

            REPOSITORY.Modify(sentiment.Id, SENTIMENT);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 0);
        }
コード例 #9
0
        public bool MovePhrase(int groupID, int phraseID)
        {
            PhraseRepository phraseRepository = new PhraseRepository();
            Phrase           phrase           = phraseRepository.Get(phraseID);

            phrase.GroupID = groupID;
            phraseRepository.Update(phrase);

            return(true);
        }
コード例 #10
0
 private async void InitializeAsync()
 {
     if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
     {
         IsLoading = true;
         List <Phrase> loadedPhrases = (await PhraseRepository.GetAllPhrasesFromLevelAsync(6)).ToList();
         SearcheablePhrases = new SearcheableObservableCollection <Phrase>(loadedPhrases);
         IsLoading          = false;
     }
 }
コード例 #11
0
        private async void LoadAsync()
        {
            IEnumerable <Phrase> loadedPhrases = await PhraseRepository.GetAllPhrasesAsync();

            IEnumerable <SelectableItem <Phrase> > phrases = loadedPhrases.Select(loadedPhrase => new SelectableItem <Phrase>(loadedPhrase));

            SearcheablePhrases = new SearcheableObservableCollection <SelectableItem <Phrase> >(phrases);

            IEnumerable <MeasureWord> loadedMeasureWords = await MeasureWordRepository.GetAllMeasureWordsAsync();

            IEnumerable <SelectableItem <MeasureWord> > measureWords = loadedMeasureWords.Select(loadedMeasureWord => new SelectableItem <MeasureWord>(loadedMeasureWord));

            SearcheableMeasureWords = new SearcheableObservableCollection <SelectableItem <MeasureWord> >(measureWords);
        }
コード例 #12
0
        private void CleanRepositories()
        {
            AuthorAlarmRepository authorAlarmRepository = new AuthorAlarmRepository();
            PhraseRepository      phraseRepository      = new PhraseRepository();
            EntityRepository      entityRepository      = new EntityRepository();
            SentimentRepository   sentimentRepository   = new SentimentRepository();
            AuthorRepository      authorRepository      = new AuthorRepository();
            AlarmRepository       alarmRepository       = new AlarmRepository();

            authorAlarmRepository.Clear();
            phraseRepository.Clear();
            entityRepository.Clear();
            sentimentRepository.Clear();
            authorRepository.Clear();
            alarmRepository.Clear();
        }
コード例 #13
0
        public bool MoveToGroup(int groupID, int newPhraseID)
        {
            NewPhraseRepository newPhraseRepository = new NewPhraseRepository();
            NewPhrase           newPhrase           = newPhraseRepository.Get(newPhraseID);

            PhraseRepository phraseRepository = new PhraseRepository();
            Phrase           phrase           = new Phrase();

            phrase.GroupID   = groupID;
            phrase.Name      = newPhrase.Name;
            phrase.Frequency = newPhrase.Frequency;

            phraseRepository.Insert(phrase);
            newPhraseRepository.Delete(newPhrase.ID);

            return(true);
        }
        public void AddSentimentUpdateAlarm()
        {
            EntityAlarmRepository alarmRepository = new EntityAlarmRepository();

            alarmRepository.Clear();

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Clear();

            PhraseRepository phraseRepository = new PhraseRepository();

            phraseRepository.Clear();

            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Clear();

            authorRepository.Add(AUTHOR);

            Phrase    phrase    = new Phrase("i like google", DateTime.Now, AUTHOR);
            Entity    google    = new Entity("google");
            Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like");

            try
            {
                entityRepository.Add(google);
            }
            catch (AnalysisException) { }

            try
            {
                phraseRepository.Add(phrase);
            }
            catch (AnalysisException) { }

            EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.POSITIVE, google);

            alarmRepository.Add(alarm);

            REPOSITORY.Add(sentiment);

            Assert.AreEqual(alarmRepository.Get(alarm.Id).PostCount, 1);
        }
コード例 #15
0
        public void AddNewEntity()
        {
            PhraseRepository phraseRepository = new PhraseRepository();
            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Add(AUTHOR);

            Phrase phrase = new Phrase("I like Google", DateTime.Now, AUTHOR);

            try
            {
                phraseRepository.Add(phrase);
            }
            catch { }

            REPOSITORY.Add(ENTITY);

            Assert.AreEqual(ENTITY.Id, phraseRepository.Get(phrase.Id).Entity.Id);
        }
        public void UpdateAlarmWithOldPhrases()
        {
            EntityRepository entityRepository = new EntityRepository();

            entityRepository.Add(ALARM.Entity);

            SentimentRepository sentimentRepository = new SentimentRepository();

            sentimentRepository.Add(new Sentiment(SentimentType.POSITIVE, "i like"));

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Add(AUTHOR);

            PhraseRepository phraseRepository = new PhraseRepository();

            phraseRepository.Add(new Phrase($"i like {ALARM.Entity.Name}", DateTime.Now.AddDays(-1), AUTHOR));

            REPOSITORY.Add(ALARM);

            Assert.AreEqual(REPOSITORY.Get(ALARM.Id).PostCount, 1);
        }
コード例 #17
0
        private async void TryGenerateNextPhrase()
        {
            if (IsCheckEnglishOption)
            {
                if (EnglishAnswerValidator())
                {
                    CurrentPhrase = await PhraseRepository.GetRandomHskPhraseByLevel(1);

                    points.AnsweredCorrect();
                    SendPointsUpdate();
                }
                else
                {
                    points.AnseredIncorrect();
                    SendPointsUpdate();
                }
            }
            else
            {
                CurrentPhrase = await PhraseRepository.GetRandomHskPhraseByLevel(1);
            }
        }
コード例 #18
0
        public void UpdateAlarmWithOldPhrases()
        {
            SentimentRepository sentimentRepository = new SentimentRepository();

            sentimentRepository.Add(new Sentiment(SentimentType.POSITIVE, "i like"));

            AuthorRepository authorRepository = new AuthorRepository();

            authorRepository.Add(AUTHOR);

            PhraseRepository phraseRepository = new PhraseRepository();

            REPOSITORY.Add(ALARM);

            Phrase phraseTest = new Phrase($"i like Google", DateTime.Now, AUTHOR);

            try
            {
                phraseRepository.Add(phraseTest);
            }
            catch (AnalysisException) { }

            Assert.AreEqual(REPOSITORY.Get(ALARM.Id).PostCount, 1);
        }