Ejemplo n.º 1
0
        public static void AddUserFeedbackScore(UserFeedbackModel model)
        {
            // Creates JSON serializer instance
            ISerializer serializer = new JsonSerializer();

            // Initializes new session with the serializer object and the keys.
            using (Session session = Session.CreateSession(consumerKey, consumerSecret, serializer))
            {
                // Error callback handler. This event will occur in case of server-side error
                session.Error += new Session.ErrorHandler(delegate(object sender, ResponseErrorEventArgs ea)
                {
                    //Console.WriteLine(string.Format("{0}: {1}", (int)ea.Status, ea.Message));
                });

                //Obtaining subscription object to get user limits applicable on server side
                Subscription subscription = session.GetSubscription();
                Dictionary<string, Semantria.Com.TaskStatus> docsTracker = new Dictionary<string, Semantria.Com.TaskStatus>();

                List<Document> outgoingBatch = new List<Document>(subscription.BasicSettings.BatchLimit);

                string docId = Guid.NewGuid().ToString();

                Document doc = new Document()
                {
                    Id = docId,
                    Text = model.Text
                };

                    outgoingBatch.Add(doc);
                    docsTracker.Add(docId, Semantria.Com.TaskStatus.QUEUED);

                if (outgoingBatch.Count > 0)
                {
                    // Queues batch of documents for processing on Semantria service
                    if (session.QueueBatchOfDocuments(outgoingBatch) != -1)
                    {
                        Console.WriteLine(string.Format("{0} documents queued successfully.", outgoingBatch.Count));
                    }
                }

                List<DocAnalyticData> results = new List<DocAnalyticData>();
                while (docsTracker.Any(item => item.Value == Semantria.Com.TaskStatus.QUEUED))
                {
                    System.Threading.Thread.Sleep(500);

                    // Requests processed results from Semantria service
                    Console.WriteLine("Retrieving your processed results...");
                    IList<DocAnalyticData> incomingBatch = session.GetProcessedDocuments();

                    foreach (DocAnalyticData item in incomingBatch)
                    {
                        if (docsTracker.ContainsKey(item.Id))
                        {
                            docsTracker[item.Id] = item.Status;
                            results.Add(item);
                        }
                    }
                }

                foreach (DocAnalyticData data in results)
                {
                     float score = 0;
                    // Printing of document entities
                    if (data.Phrases != null && data.Phrases.Count > 0)
                    {

                        foreach (var entity in data.Phrases)
                        {
                            score += entity.SentimentScore;
                        }
                        score = score / data.Phrases.Count();
                    }

                    model.Score = score;

                }
            }
        }
Ejemplo n.º 2
0
 public void AddFeedback(UserFeedbackModel model)
 {
     RequestService service = new RequestService();
     service.AddUserFeedback(model);
 }
Ejemplo n.º 3
0
        public void AddUserFeedback(UserFeedbackModel model)
        {
            SemantriaHelper.AddUserFeedbackScore(model);

            using (ipl_userprofilerEntities entity = new ipl_userprofilerEntities())
            {
                var homeAwayProperty = entity.HomeAwayProperties.First(res => res.Id == model.PropertyId);

                var request = new HomeAwayFeedback
                {
                    PropertyId = model.PropertyId,
                    UserEmail = model.UserEmail,
                    UserName = model.UserName,
                    Text = model.Text,
                    AddedAt = DateTime.Now

                };

                entity.HomeAwayFeedbacks.Add(request);

                //Map feedbackto to claim property

                var requestId = entity.CliqueClaimRequests.First(res => res.Name == homeAwayProperty.Name && res.Zip == homeAwayProperty.Zip).Id;
                var claimFeedback = new CliqueClaimRequestFeedback
                {
                    RequestId = requestId,
                    UserEmail = model.UserEmail,
                    UserName = model.UserName,
                    Text = model.Text,
                    Score = model.Score,
                    AddedAt = DateTime.Now

                };

                entity.CliqueClaimRequestFeedbacks.Add(claimFeedback);
                entity.SaveChanges();
            }
        }