Exemplo n.º 1
0
 public AuthorAlarm(string postQuantity, string quantDays, SentimentType type, TimeMeasure measure) : base()
 {
     PostQuantity = postQuantity;
     Time         = quantDays;
     PostCount    = 0;
     Type         = type;
     TimeMeasure  = measure;
 }
Exemplo n.º 2
0
 public EntityAlarm(string postQuantity, string quantDays, SentimentType type, Entity entity) : base()
 {
     PostQuantity = postQuantity;
     Time         = quantDays;
     PostCount    = 0;
     Type         = type;
     Entity       = entity;
 }
        private void SetSentimentType(SentimentType type)
        {
            if (type == SentimentType.NEUTRAL)
            {
                throw new AlarmException("Sentiment Type can't be neutral.");
            }

            this.type = type;
        }
 public AlarmEntity(string postQuantity, string quantDays, SentimentType type, Entity entity)
 {
     PostQuantity      = postQuantity;
     this.creationDate = DateTime.Now;
     NumberDays        = quantDays;
     PostCount         = 0;
     Type   = type;
     Entity = entity;
 }
Exemplo n.º 5
0
 public EntityAlarm(int id, int postQuantity, int postCount, DateTime creationDate, int numDays, SentimentType type, Entity entity) : base()
 {
     Id           = id;
     PostQuantity = postQuantity.ToString();
     PostCount    = postCount;
     Time         = numDays.ToString();
     Type         = type;
     Entity       = entity;
 }
Exemplo n.º 6
0
 public AuthorAlarm(int id, int postQuantity, int postCount, DateTime creationDate, int numDays, SentimentType type, TimeMeasure measure) : base()
 {
     Id           = id;
     PostQuantity = postQuantity.ToString();
     PostCount    = postCount;
     Time         = numDays.ToString();
     Type         = type;
     TimeMeasure  = measure;
 }
 public AlarmEntity(int id, int postQuantity, int postCount, DateTime creationDate, int numDays, SentimentType type, Entity entity)
 {
     Id                = id;
     PostQuantity      = postQuantity.ToString();
     PostCount         = postCount;
     this.creationDate = creationDate;
     NumberDays        = numDays.ToString();
     Type              = type;
     Entity            = entity;
 }
Exemplo n.º 8
0
        public void Modify(int?id, Sentiment sentiment)
        {
            if (!id.HasValue)
            {
                throw new SentimentException("You must select an Sentiment to modify.");
            }

            PhraseRepository      phraseRepository = new PhraseRepository();
            EntityAlarmRepository alarmRepository  = new EntityAlarmRepository();

            using (SentimentAnalysisContext context = new SentimentAnalysisContext())
            {
                var sentimentFound = context.Sentiments.FirstOrDefault(s => s.Id == id);

                if (id != sentiment.Id || !sentimentFound.Word.Equals(sentiment.Word))
                {
                    Exists(sentiment);
                }

                SentimentType oldType = sentimentFound.Type;

                sentimentFound.Word = sentiment.Word;
                sentimentFound.Type = sentiment.Type;

                context.Sentiments.AddOrUpdate(sentimentFound);
                context.SaveChanges();

                foreach (var phrase in Helper.Instance.GetPhrases(context.Phrases).Where(p => p.Type == null || p.Type == oldType))
                {
                    phrase.Type   = null;
                    phrase.Entity = null;

                    try
                    {
                        phrase.AnalyzePhrase(Helper.Instance.GetEntities(context.Entities), Helper.Instance.GetSentiments(context.Sentiments));
                        phraseRepository.Modify(phrase.Id, phrase);
                    }
                    catch (AnalysisException)
                    {
                        phraseRepository.Modify(phrase.Id, phrase);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }

                foreach (var alarm in Helper.Instance.GetEntityAlarms(context.EntityAlarms))
                {
                    alarm.ReAnalyePhrases(Helper.Instance.GetPhrases(context.Phrases));
                    alarmRepository.Modify(alarm.Id, alarm);
                }
            }
        }
        public override bool Equals(object obj)
        {
            Sentiment sentiment = obj as Sentiment;

            if (sentiment == null || Convert.IsDBNull(sentiment))
            {
                return(false);
            }
            return(string.Equals(Utilities.DeleteSpaces(SentimientText.Trim()),
                                 Utilities.DeleteSpaces(sentiment.SentimientText.Trim()),
                                 StringComparison.OrdinalIgnoreCase) && SentimentType.Equals(sentiment.SentimentType));
        }
        public void ModifySentimentType()
        {
            string        newWord = "Me disgusta";
            SentimentType newType = SentimentType.NEGATIVE;

            SentimentRepository repository = new SentimentRepository();

            repository.Add(SENTIMENT);

            SENTIMENT.Word = newWord;
            SENTIMENT.Type = newType;

            REPOSITORY.Modify(SENTIMENT.Id, SENTIMENT);

            Assert.AreEqual(repository.Get(SENTIMENT.Id).Type, (SentimentType)newType);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Update coordinates of face rectangle and predominant sentiment passsed as parameter
        /// </summary>
        /// <param name="coordinates"></param>
        public void Update(IReadOnlyList <float> coordinates, SentimentType sentiment)
        {
            if (coordinates == null)
            {
                return;
            }
            if (coordinates.Count != 4)
            {
                throw new Exception("you can only pass a set of 4 float coordinates (left, top, right, bottom) to this method");
            }
            m_rectangle.Width  = (coordinates[2] - coordinates[0]) * m_canvas.Width;
            m_rectangle.Height = (coordinates[3] - coordinates[1]) * m_canvas.Height;
            Canvas.SetLeft(m_rectangle, coordinates[0] * m_canvas.Width);
            Canvas.SetTop(m_rectangle, coordinates[1] * m_canvas.Height);

            m_sentimentControl.Text = $"{m_emojis[sentiment]}";
        }
        public void CurrentDayEngulfsPreviousDayBullish(SentimentType type, bool latestOccurenceHasValue)
        {
            var quotes = new List<Quote>
                {
                    Quote.Create("TST.L", monday.AddDays(0), 10, 12, 15, 9, 0),
                    Quote.Create("TST.L", monday.AddDays(1), 11, 13, 15, 9, 0),
                    Quote.Create("TST.L", monday.AddDays(2), 13, 14, 60, 1, 0),
                    Quote.Create("TST.L", monday.AddDays(3), 14, 15, 60, 1, 0),
                    Quote.Create("TST.L", monday.AddDays(4), 16, 15, 60, 1, 0),
                    Quote.Create("TST.L", monday.AddDays(5), 11, 17, 60, 1, 0),
                };

            var latestOccurencesExpected = new DateTime[] {};
            if (latestOccurenceHasValue) latestOccurencesExpected = new[] {monday.AddDays(5)};

            this.Test(quotes, type, latestOccurencesExpected);
        }
Exemplo n.º 13
0
        /// <summary>
        /// returns true if success and false if failed. For every sentimentType = neutral, the output score is zero
        /// </summary>
        public bool GetSentiment(string sentence, out SentimentType sentimentType, out double score, bool isTransformNeutralScore = true)
        {
            sentimentType = SentimentType.Neutral;
            score         = 0;
            if (string.IsNullOrWhiteSpace(sentence))
            {
                return(false);
            }

            sentence = sentence.Trim();

            IList <Sentiment> sentiments = _engine.Analyze(sentence);

            if (sentiments.Count == 0)
            {
                return(false);
            }
            var sentiment = sentiments.First();

            score = sentiment.Score;
            switch (sentiment.Polarity)
            {
            case Polarity.Negative:
                sentimentType = SentimentType.Negative;
                break;

            case Polarity.Positive:
                sentimentType = SentimentType.Positive;
                break;

            case Polarity.Neutral:
                if (isTransformNeutralScore)
                {
                    score = 0;
                }
                sentimentType = SentimentType.Neutral;
                break;

            default:
                throw new ArgumentException();
            }
            return(true);
        }
Exemplo n.º 14
0
 public IList <Sentiment> GetBySentimentType(SentimentType type)
 {
     try
     {
         return(GetAll().Where(s => s.Type == type).ToList());
     }
     catch (SqlException)
     {
         throw new DatabaseException();
     }
     catch (DbException)
     {
         throw new DatabaseException();
     }
     catch (EntityException)
     {
         throw new DatabaseException();
     }
     catch (InvalidOperationException)
     {
         throw new DatabaseException();
     }
 }
 public KickerPatternRecogniser(IEnumerable<DataPoints> datapoints, SentimentType sentimentType)
 {
     this.datapoints = datapoints;
     this.sentimentType = sentimentType;
 }
 public Sentiment(SentimentType sentiment, string word)
 {
     Type = sentiment;
     Word = word;
 }
 public Sentiment(int id, SentimentType sentiment, string word) : this(sentiment, word)
 {
     Id = id;
 }
 private void Test(IEnumerable<Quote> quotes, SentimentType type, IEnumerable<DateTime> expectedOccurences)
 {
     var patternRecogniser = new EngulfingPatterRecogniser(quotes.Select(DataPoints.CreateFromQuote), type);
     var latestOccurences = patternRecogniser.FindOccurences();
     Assert.AreEqual(expectedOccurences, latestOccurences);
 }
 public EngulfingPatterRecogniser(IEnumerable<DataPoints> quotes, SentimentType engulfingType)
 {
     this.quotes = quotes;
     this.engulfingType = engulfingType;
     patternType = engulfingType == SentimentType.Bullish ? 1 : 2;
 }
Exemplo n.º 20
0
 private void ExistsAlarm(Entity entity, string numbDays, string postQuantity, SentimentType type)
 {
     using (SentimentAnalysisContext context = new SentimentAnalysisContext())
         if (helper.GetEntityAlarms(context.EntityAlarms).Any(a => a.Entity.Id == entity.Id && a.NumberDays.Equals(numbDays) && a.PostQuantity.Equals(postQuantity) && a.Type == type))
         {
             throw new AlarmException($"Already exist an Alarm for {entity.Name}, with {numbDays} days and Sentiment {type}");
         }
 }