示例#1
0
        public async Task <IHttpActionResult> OpinionOnProduct([FromUri] int ProductId)
        {
            var ProductPosts = PostAuxiliar.PostsByProduct(ProductId);
            var Product      = SQLContext.Products.Find(ProductId);

            double Opinion = 0;

            foreach (var Post in ProductPosts)
            {
                var Response = await MakeRequest(Post.Text.Replace("$", "")).ConfigureAwait(false);

                var Analysis = (Response as JArray).ToObject <List <SentimentalAnalysis> >();

                Opinion += CalculateMeanScore(new List <string>()
                {
                    Product.Name,
                    Product.Description,
                    Product.Pro.Firstname,
                    Product.Pro.Lastname,
                    Product.Pro.Nickname
                }, Analysis);
            }

            return(Ok(new { Product = Product.Name, Score = Opinion, Opinion = ScoreTranslator(Opinion) }));
        }
示例#2
0
        public IHttpActionResult PostsByProduct([FromUri] int ProductId)
        {
            var Posts = PostAuxiliar.PostsByProduct(ProductId);

            Posts = PostAuxiliar.UpdateOwner(Posts, SQLContext);

            return(Ok(Posts));
        }