public void AnalyzeUpdateCountDuplicateAuthors() { AuthorAlarm alarm = new AuthorAlarm("2", "2", SentimentType.POSITIVE, TimeMeasure.HOURS); Phrase firstPhrase = new Phrase("I like google", DateTime.Now.AddHours(-1), AUTHOR); Phrase secondPhrase = new Phrase("I like starbucks", DateTime.Now.AddHours(-1), AUTHOR); try { firstPhrase.AnalyzePhrase(new List <Entity>(), new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); } catch (AnalysisException) { } try { secondPhrase.AnalyzePhrase(new List <Entity>(), new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); } catch (AnalysisException) { } alarm.AnalyzePhrases(new List <Phrase> { firstPhrase, secondPhrase }); Assert.AreEqual(alarm.PostCount, 2); }
public void ReAnalyze() { EntityAlarm alarm = new EntityAlarm("2", "2", SentimentType.POSITIVE, ENTITY); Phrase phrase = new Phrase("I like google", YESTERDAY, AUTHOR); try { phrase.AnalyzePhrase(new List <Entity> { ENTITY }, new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); } catch (AnalysisException) { } alarm.AnalyzePhrases(new List <Phrase> { phrase }); alarm.ReAnalyePhrases(new List <Phrase> { phrase }); Assert.AreEqual(alarm.PostCount, 1); }
public void GetHighGrade() { Entity entity = new Entity("Starbucks"); Sentiment iLike = new Sentiment(SentimentType.POSITIVE, "I like"); Sentiment iLove = new Sentiment(SentimentType.POSITIVE, "I love"); Sentiment fascinatesMe = new Sentiment(SentimentType.POSITIVE, "Fascinates me"); List <Sentiment> sentiments = new List <Sentiment>(); sentiments.Add(iLike); sentiments.Add(iLove); sentiments.Add(fascinatesMe); string word = "I love and fascinates me Starbucks, i like it to much"; Phrase phrase = new Phrase(word, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(new List <Entity>() { entity }, sentiments); Assert.AreEqual(phrase.Grade, SentimentGrade.HIGH); }
public void DeleteSentimentUpdateAlarm() { Phrase phrase = new Phrase("i like google", DateTime.Now, AUTHOR); Entity google = new Entity("google"); Sentiment sentiment = new Sentiment(SentimentType.POSITIVE, "i like"); try { phrase.AnalyzePhrase(new List <Entity> { google }, new List <Sentiment> { sentiment }); } catch (AnalysisException) { } EntityAlarm alarm = new EntityAlarm("1", "1", SentimentType.POSITIVE, google); REPOSITORY.Add(sentiment); REPOSITORY.Delete(sentiment.Id); Assert.AreEqual(alarm.PostCount, 0); }
public void AnalyzePhraseMultipleSentimentsType() { string newWord = string.Concat(WORD, ", but i dont like Microsoft"); Phrase phrase = new Phrase(newWord, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(entities, sentiments); }
public void AnalyzePhraseMultipleEntities() { string newWord = string.Concat(WORD, " and Google"); Phrase phrase = new Phrase(newWord, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(entities, sentiments); }
public void AnalyzePhraseSetSentimentType() { Phrase phrase = new Phrase(WORD, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(entities, sentiments); Assert.AreEqual(phrase.Type, SentimentType.POSITIVE); }
public void AnalyzePhraseSetEntity() { Phrase phrase = new Phrase(WORD, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(entities, sentiments); Assert.AreEqual(phrase.Entity, entities.First(e => e.Name.Equals("Starbucks"))); }
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); }
public void ToStringTest() { Phrase phrase = new Phrase(WORD, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(entities, sentiments); string str = $"{WORD} [Type: {SentimentType.POSITIVE}] [Entity: Starbucks] [Author: {AUTHOR.Username}]"; Assert.AreEqual(phrase.ToString(), str); }
public void AnalyzeSentimentGradeEmptyList() { Entity entity = new Entity("Starbucks"); List <Sentiment> sentiments = new List <Sentiment>(); string word = "I love and fascinates me Starbucks, i like it to much"; Phrase phrase = new Phrase(word, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(new List <Entity>() { entity }, sentiments); }
public void AnalyzeNoUpdatePostCount() { AlarmEntity alarm = new AlarmEntity("2", "1", SentimentType.NEGATIVE, ENTITY); Phrase phrase = new Phrase("I like google", YESTERDAY.AddDays(-25), AUTHOR); phrase.AnalyzePhrase(new List <Entity> { ENTITY }, new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); alarm.AnalyzePhrases(new List <Phrase> { phrase }); Assert.AreEqual(alarm.PostCount, 0); }
public void AnalyzeUpdatePostCount() { EntityAlarm alarm = new EntityAlarm("2", "2", SentimentType.POSITIVE, ENTITY); Phrase phrase = new Phrase("I like google", YESTERDAY, AUTHOR); phrase.AnalyzePhrase(new List <Entity> { ENTITY }, new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); alarm.AnalyzePhrases(new List <Phrase> { phrase }); Assert.AreEqual(alarm.PostCount, 1); }
public void IsNotEnabled() { AlarmEntity alarm = new AlarmEntity("2", "1", SentimentType.POSITIVE, ENTITY); Phrase phrase = new Phrase("I like google", YESTERDAY, AUTHOR); phrase.AnalyzePhrase(new List <Entity> { ENTITY }, new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); alarm.AnalyzePhrases(new List <Phrase> { phrase }); Assert.IsFalse(alarm.IsEnabled()); }
public void Modify(int?id, Entity entity) { if (!id.HasValue) { throw new EntityException("You must select an Entity to modify."); } PhraseRepository phraseRepository = new PhraseRepository(); EntityAlarmRepository alarmRepository = new EntityAlarmRepository(); using (SentimentAnalysisContext context = new SentimentAnalysisContext()) { var entityFound = context.Entities.FirstOrDefault(e => e.Id == id); if (id != entity.Id || !entityFound.Name.Equals(entity.Name)) { Exists(entity); } entityFound.Name = entity.Name; context.SaveChanges(); foreach (var phrase in context.Phrases.Where(p => p.Entity == null || p.Entity.Id == entityFound.Id)) { phrase.Entity = null; try { Phrase toModify = Helper.Instance.ToPhraseBL(phrase); toModify.AnalyzePhrase(Helper.Instance.GetEntities(context.Entities), Helper.Instance.GetSentiments(context.Sentiments)); phraseRepository.Modify(phrase.Id, toModify); } catch (AnalysisException) { } } foreach (var alarm in context.EntityAlarms.ToList()) { EntityAlarm toModify = Helper.Instance.ToEntityAlarmBL(alarm); toModify.ReAnalyePhrases(Helper.Instance.GetPhrases(context.Phrases)); alarmRepository.Modify(alarm.Alarm.Id, toModify); } } }
public void AnalyzePhraseWithoutEntity() { Entity entity = new Entity("Starbucks"); AlarmEntity alarm = new AlarmEntity("1", "2", SentimentType.POSITIVE, entity); Phrase phrase = new Phrase("I like google", YESTERDAY, AUTHOR); phrase.AnalyzePhrase(new List <Entity> { ENTITY }, new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); alarm.AnalyzePhrases(new List <Phrase> { phrase }); Assert.AreEqual(alarm.PostCount, 0); }
public void IsNotEnabled() { AuthorAlarm alarm = new AuthorAlarm("2", "1", SentimentType.POSITIVE, TimeMeasure.HOURS); Phrase phrase = new Phrase("I like google", YESTERDAY, AUTHOR); try { phrase.AnalyzePhrase(new List <Entity>(), new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); } catch (AnalysisException) { } alarm.AnalyzePhrases(new List <Phrase> { phrase }); Assert.IsFalse(alarm.IsEnabled()); }
public void AnalyzeNoUpdatePostCount() { AuthorAlarm alarm = new AuthorAlarm("2", "1", SentimentType.NEGATIVE, TimeMeasure.DAYS); Phrase phrase = new Phrase("I like google", YESTERDAY.AddDays(-25), AUTHOR); try { phrase.AnalyzePhrase(new List <Entity>(), new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); } catch (AnalysisException) { } alarm.AnalyzePhrases(new List <Phrase> { phrase }); Assert.AreEqual(alarm.PostCount, 0); }
public void GetLowGrade() { Entity entity = new Entity("Starbucks"); Sentiment iLike = new Sentiment(SentimentType.NEGATIVE, "I dislike"); List <Sentiment> sentiments = new List <Sentiment>(); sentiments.Add(iLike); string word = "I love and fascinates me Starbucks, i dislike it to much"; Phrase phrase = new Phrase(word, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(new List <Entity>() { entity }, sentiments); Assert.AreEqual(phrase.Grade, SentimentGrade.LOW); }
public void GetSentimentList() { Entity entity = new Entity("Starbucks"); Sentiment iLike = new Sentiment(SentimentType.POSITIVE, "I like"); List <Sentiment> sentiments = new List <Sentiment>(); sentiments.Add(iLike); string word = "I love and fascinates me Starbucks, i like it to much"; Phrase phrase = new Phrase(word, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(new List <Entity>() { entity }, sentiments); Assert.IsTrue(phrase.SentimentList.SequenceEqual(sentiments)); }
public void AnalyzePhraseWithoutEntity() { EntityAlarm alarm = new EntityAlarm("2", "2", SentimentType.NEGATIVE, ENTITY); Phrase phrase = new Phrase("I like UberEats", YESTERDAY.AddDays(-1), AUTHOR); try { phrase.AnalyzePhrase(new List <Entity> { ENTITY }, new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }); } catch (AnalysisException) { } alarm.AnalyzePhrases(new List <Phrase> { phrase }); Assert.AreEqual(alarm.PostCount, 0); }
public void SetUp() { AUTHOR = new Author("sada", "sadasd", "sdaasd", new DateTime(1995, 2, 3)); ENTITY = new Entity("Google"); ALARM = new EntityAlarm("1", "1", SentimentType.POSITIVE, ENTITY); REPOSITORY = new EntityAlarmRepository(); ENTITIES = new List <Entity> { ENTITY }; SENTIMENTS = new List <Sentiment> { new Sentiment(SentimentType.POSITIVE, "I like") }; PHRASES = new List <Phrase>(); Phrase phrase = new Phrase("I like Google", DateTime.Now, AUTHOR); phrase.AnalyzePhrase(ENTITIES, SENTIMENTS); PHRASES.Add(phrase); CleanRepositories(); }
public void AnalyzePhraseNotFoundSentimentType() { Phrase phrase = new Phrase(WORD, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(entities, new List <Sentiment>()); }
public void AnalyzePhraseNotFoundEntity() { Phrase phrase = new Phrase(WORD, DateTime.Now, AUTHOR); phrase.AnalyzePhrase(new List <Entity>(), sentiments); }