/// <summary>
        /// Add feedback.
        ///
        /// Adds feedback in the form of _labels_ from a subject-matter expert (SME) to a governing document.
        /// **Important:** Feedback is not immediately incorporated into the training model, nor is it guaranteed to be
        /// incorporated at a later date. Instead, submitted feedback is used to suggest future updates to the training
        /// model.
        /// </summary>
        /// <param name="feedbackData">An object that defines the feedback to be submitted.</param>
        /// <returns><see cref="FeedbackReturn" />FeedbackReturn</returns>
        public DetailedResponse <FeedbackReturn> AddFeedback(FeedbackDataInput feedbackData, string userId = null, string comment = null)
        {
            if (feedbackData == null)
            {
                throw new ArgumentNullException("`feedbackData` is required for `AddFeedback`");
            }

            if (string.IsNullOrEmpty(VersionDate))
            {
                throw new ArgumentNullException("versionDate cannot be null.");
            }

            DetailedResponse <FeedbackReturn> result = null;

            try
            {
                IClient client = this.Client;
                SetAuthentication();

                var restRequest = client.PostAsync($"{this.Endpoint}/v1/feedback");

                restRequest.WithArgument("version", VersionDate);
                restRequest.WithHeader("Accept", "application/json");
                restRequest.WithHeader("Content-Type", "application/json");

                JObject bodyObject = new JObject();
                if (feedbackData != null)
                {
                    bodyObject["feedback_data"] = JToken.FromObject(feedbackData);
                }
                if (!string.IsNullOrEmpty(userId))
                {
                    bodyObject["user_id"] = userId;
                }
                if (!string.IsNullOrEmpty(comment))
                {
                    bodyObject["comment"] = comment;
                }
                var httpContent = new StringContent(JsonConvert.SerializeObject(bodyObject), Encoding.UTF8, HttpMediaType.APPLICATION_JSON);
                restRequest.WithBodyContent(httpContent);

                restRequest.WithHeaders(Common.GetSdkHeaders("compare-comply", "v1", "AddFeedback"));
                restRequest.WithHeaders(customRequestHeaders);
                ClearCustomRequestHeaders();

                result = restRequest.As <FeedbackReturn>().Result;
                if (result == null)
                {
                    result = new DetailedResponse <FeedbackReturn>();
                }
            }
            catch (AggregateException ae)
            {
                throw ae.Flatten();
            }

            return(result);
        }
        public void AddFeedback_Success()
        {
            IClient  client  = Substitute.For <IClient>();
            IRequest request = Substitute.For <IRequest>();

            client.PostAsync(Arg.Any <string>())
            .Returns(request);

            CompareComplyService service = new CompareComplyService(client);
            var versionDate = "versionDate";

            service.VersionDate = versionDate;

            var feedbackData = new FeedbackDataInput();
            var userId       = "userId";
            var comment      = "comment";

            var result = service.AddFeedback(feedbackData: feedbackData, userId: userId, comment: comment);

            JObject bodyObject = new JObject();

            if (feedbackData != null)
            {
                bodyObject["feedback_data"] = JToken.FromObject(feedbackData);
            }
            if (!string.IsNullOrEmpty(userId))
            {
                bodyObject["user_id"] = JToken.FromObject(userId);
            }
            if (!string.IsNullOrEmpty(comment))
            {
                bodyObject["comment"] = JToken.FromObject(comment);
            }
            var json = JsonConvert.SerializeObject(bodyObject);

            request.Received().WithArgument("version", versionDate);
            request.Received().WithBodyContent(Arg.Is <StringContent>(x => x.ReadAsStringAsync().Result.Equals(json)));
        }
示例#3
0
        public void AddFeedback()
        {
            IamConfig config = new IamConfig(
                apikey: apikey
                );

            CompareComplyService service = new CompareComplyService(versionDate, config);

            service.SetEndpoint(url);

            #region feedbackData
            FeedbackDataInput feedbackData = new FeedbackDataInput()
            {
                FeedbackType = "element_classification",
                Document     = new ShortDoc()
                {
                    Hash  = "",
                    Title = "doc title"
                },
                ModelId      = "contracts",
                ModelVersion = "11.00",
                Location     = new Location()
                {
                    Begin = 241,
                    End   = 237
                },
                Text           = "1. IBM will provide a Senior Managing Consultant / expert resource, for up to 80 hours, to assist Florida Power & Light (FPL) with the creation of an IT infrastructure unit cost model for existing infrastructure.",
                OriginalLabels = new OriginalLabelsIn()
                {
                    Types = new List <TypeLabel>()
                    {
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Obligation",
                                Party  = "IBM"
                            },
                            ProvenanceIds = new List <string>()
                            {
                                "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                            }
                        },
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "End User",
                                Party  = "Exclusion"
                            },
                            ProvenanceIds = new List <string>()
                            {
                                "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                            }
                        }
                    },
                    Categories = new List <Category>()
                    {
                        new Category()
                        {
                            Label         = Category.LabelEnumValue.RESPONSIBILITIES,
                            ProvenanceIds = new List <string>()
                            {
                            }
                        },
                        new Category()
                        {
                            Label         = Category.LabelEnumValue.AMENDMENTS,
                            ProvenanceIds = new List <string>()
                            {
                            }
                        }
                    }
                },
                UpdatedLabels = new UpdatedLabelsIn()
                {
                    Types = new List <TypeLabel>()
                    {
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Obligation",
                                Party  = "IBM"
                            }
                        },
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Disclaimer",
                                Party  = "buyer"
                            }
                        }
                    },
                    Categories = new List <Category>()
                    {
                        new Category()
                        {
                            Label = Category.LabelEnumValue.RESPONSIBILITIES,
                        },
                        new Category()
                        {
                            Label = Category.LabelEnumValue.AUDITS
                        }
                    }
                }
            };
            #endregion

            var result = service.AddFeedback(
                feedbackData: feedbackData,
                userId: "user_id_123x",
                comment: "Test feedback comment"
                );

            feedbackId = result.Result.FeedbackId;

            Console.WriteLine(result.Response);
        }
示例#4
0
        public void Feedback_Success()
        {
            DateTime before = DateTime.Now;
            DateTime after  = new DateTime(2018, 11, 13);

            service.WithHeader("X-Watson-Test", "1");
            var ListFeedbackResult = service.ListFeedback(
                feedbackType: "element_classification",
                before: before,
                after: after,
                documentTitle: "doc title",
                modelId: "contracts",
                modelVersion: "11.00",
                categoryRemoved: "categoryRemoved",
                categoryAdded: "categoryAdded",
                categoryNotChanged: "categoryUnchanged",
                typeRemoved: "nature:party",
                typeAdded: "nature:party",
                typeNotChanged: "nature:party",
                pageLimit: 3,
                sort: "created"
                );

            string userId  = "user_id_123x";
            string comment = "Test feedback comment";

            #region feedbackData
            FeedbackDataInput feedbackData = new FeedbackDataInput()
            {
                FeedbackType = "element_classification",
                Document     = new ShortDoc()
                {
                    Hash  = "",
                    Title = "doc title"
                },
                ModelId      = "contracts",
                ModelVersion = "11.00",
                Location     = new Location()
                {
                    Begin = 241,
                    End   = 237
                },
                Text           = "1. IBM will provide a Senior Managing Consultant / expert resource, for up to 80 hours, to assist Florida Power & Light (FPL) with the creation of an IT infrastructure unit cost model for existing infrastructure.",
                OriginalLabels = new OriginalLabelsIn()
                {
                    Types = new List <TypeLabel>()
                    {
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Obligation",
                                Party  = "IBM"
                            },
                            ProvenanceIds = new List <string>()
                            {
                                "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                            }
                        },
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "End User",
                                Party  = "Exclusion"
                            },
                            ProvenanceIds = new List <string>()
                            {
                                "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                            }
                        }
                    },
                    Categories = new List <Category>()
                    {
                        new Category()
                        {
                            Label         = Category.LabelEnumValue.RESPONSIBILITIES,
                            ProvenanceIds = new List <string>()
                            {
                            }
                        },
                        new Category()
                        {
                            Label         = Category.LabelEnumValue.AMENDMENTS,
                            ProvenanceIds = new List <string>()
                            {
                            }
                        }
                    }
                },
                UpdatedLabels = new UpdatedLabelsIn()
                {
                    Types = new List <TypeLabel>()
                    {
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Obligation",
                                Party  = "IBM"
                            }
                        },
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Disclaimer",
                                Party  = "buyer"
                            }
                        }
                    },
                    Categories = new List <Category>()
                    {
                        new Category()
                        {
                            Label = Category.LabelEnumValue.RESPONSIBILITIES,
                        },
                        new Category()
                        {
                            Label = Category.LabelEnumValue.AUDITS
                        }
                    }
                }
            };
            #endregion

            service.WithHeader("X-Watson-Test", "1");
            var addFeedbackResult = service.AddFeedback(
                feedbackData: feedbackData,
                userId: userId,
                comment: comment
                );

            string feedbackId = addFeedbackResult.Result.FeedbackId;

            service.WithHeader("X-Watson-Test", "1");
            var getFeedbackResult = service.GetFeedback(
                feedbackId: feedbackId,
                model: compareComplyModel
                );

            service.WithHeader("X-Watson-Test", "1");
            var deleteFeedbackResult = service.DeleteFeedback(
                feedbackId: feedbackId
                );

            Assert.IsNotNull(deleteFeedbackResult.Result.Status);
            Assert.IsNotNull(getFeedbackResult.Result.FeedbackId);
            Assert.IsNotNull(addFeedbackResult.Result.FeedbackId);
            Assert.IsNotNull(ListFeedbackResult.Result.Feedback);
        }
示例#5
0
        public IEnumerator TestAddFeedback()
        {
            Log.Debug("CompareComplyServiceV1IntegrationTests", "Attempting to AddFeedback...");
            FeedbackReturn addFeedbackResponse = null;

            #region feedbackData
            var feedbackData = new FeedbackDataInput()
            {
                FeedbackType = "element_classification",
                Document     = new ShortDoc()
                {
                    Hash  = "",
                    Title = "doc title"
                },
                ModelId      = "contracts",
                ModelVersion = "11.00",
                Location     = new Location()
                {
                    Begin = 241,
                    End   = 237
                },
                Text           = "1. IBM will provide a Senior Managing Consultant / expert resource, for up to 80 hours, to assist Florida Power & Light (FPL) with the creation of an IT infrastructure unit cost model for existing infrastructure.",
                OriginalLabels = new OriginalLabelsIn()
                {
                    Types = new List <TypeLabel>()
                    {
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Obligation",
                                Party  = "IBM"
                            },
                            ProvenanceIds = new List <string>()
                            {
                                "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                            }
                        },
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "End User",
                                Party  = "Exclusion"
                            },
                            ProvenanceIds = new List <string>()
                            {
                                "85f5981a-ba91-44f5-9efa-0bd22e64b7bc",
                                "ce0480a1-5ef1-4c3e-9861-3743b5610795"
                            }
                        }
                    },
                    Categories = new List <Category>()
                    {
                        new Category()
                        {
                            Label         = Category.LabelValue.RESPONSIBILITIES,
                            ProvenanceIds = new List <string>()
                            {
                            }
                        },
                        new Category()
                        {
                            Label         = Category.LabelValue.AMENDMENTS,
                            ProvenanceIds = new List <string>()
                            {
                            }
                        }
                    }
                },
                UpdatedLabels = new UpdatedLabelsIn()
                {
                    Types = new List <TypeLabel>()
                    {
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Obligation",
                                Party  = "IBM"
                            }
                        },
                        new TypeLabel()
                        {
                            Label = new Label()
                            {
                                Nature = "Disclaimer",
                                Party  = "buyer"
                            }
                        }
                    },
                    Categories = new List <Category>()
                    {
                        new Category()
                        {
                            Label = Category.LabelValue.RESPONSIBILITIES,
                        },
                        new Category()
                        {
                            Label = Category.LabelValue.AUDITS
                        }
                    }
                }
            };
            #endregion

            service.AddFeedback(
                callback: (DetailedResponse <FeedbackReturn> response, IBMError error) =>
            {
                Log.Debug("CompareComplyServiceV1IntegrationTests", "AddFeedback result: {0}", response.Response);
                addFeedbackResponse = response.Result;
                createdFeedbackId   = addFeedbackResponse.FeedbackId;
                Assert.IsNotNull(addFeedbackResponse);
                Assert.IsNotNull(createdFeedbackId);
                Assert.IsNull(error);
            },
                feedbackData: feedbackData,
                userId: "user_id_123x",
                comment: "Test feedback comment"
                );

            while (addFeedbackResponse == null)
            {
                yield return(null);
            }
        }