public void getAddressjsonTestAndCompareSDKResponseTest()
        {
            try
            {
                String inputjsonText = "{\"options\": {"
                                       + "\"EntityList\": \"Person\", \"OutputEntityCount\": \"\"},\"Input\": {" + "\"Row\":[{" + "\"PlainText\": \"Michael Phelps was a American swimmer. He was born on 30 June 1985 in Towson, Maryland, USA. Visit www.michaelphelps.com\"" + "}]}}";

                List <Record> rowList = new List <Record>();

                rowList.Add(new Record(null, plaintext: "Michael Phelps was a American swimmer. He was born on 30 June 1985 in Towson, Maryland, USA. Visit www.michaelphelps.com"));

                Options options = new Options();
                input   input   = new input();

                input.RecordList = rowList;
                ExtractEntitiesAPIRequest request = new ExtractEntitiesAPIRequest(input, options);

                ExtractEntitiesAPIResponse response = identifyEntityService.ExtractEntities(request);
                string sdkResponse = Utility.ObjectToJson <ExtractEntitiesAPIResponse>(response);

                String apiResponse = TestUtility.ValidateFromAPI(TEST_URL, "/identifyentity/v1/rest/extractentities/", TEST_TOKEN, inputjsonText, com.pb.identify.utils.Utility.contentType.json);
                apiResponse = apiResponse.Replace("\r\n    ", "");
                apiResponse = apiResponse.Replace("{\r\n", "{");
                apiResponse = apiResponse.Replace("\"", "");
                sdkResponse = sdkResponse.Replace("\"", "");

                apiResponse = string.Join("", apiResponse.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
                sdkResponse = string.Join("", sdkResponse.Split(default(string[]), StringSplitOptions.RemoveEmptyEntries));
                Assert.AreEqual(sdkResponse, apiResponse);
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected Exception: " + e);
            }
        }
示例#2
0
        /// <summary>
        /// Matches the input record request.
        /// Accepts the record request as input and returns matched records
        /// </summary>
        /// <param name="request">Required - ExtractEntitiesAPIRequest request (object filled with input and option) </param>
        /// <returns>ExtractEntitiesAPIResponse</returns>
        public ExtractEntitiesAPIResponse ExtractEntities(ExtractEntitiesAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(IdentifyExtractUrl));
            string        url        = urlBuilder.ToString() + ExtractEntitiesUrl;

            String requestString = Utility.ObjectToJson <ExtractEntitiesAPIRequest>(request);

            return(Utility.processAPIRequest <ExtractEntitiesAPIResponse>(url, requestString));
        }
示例#3
0
        /// <summary>
        /// Matches the input record request in asynchronous mode.
        /// Response can be retrieved by subscribing to event ExtractEntitiesFinishedEvent.
        /// Accepts the record request as input and returns matched records
        /// </summary>
        /// <param name="request">Required - ExtractEntitiesAPIRequest request (object filled with input and option) </param>
        public void ExtractEntitiesAsync(ExtractEntitiesAPIRequest request)
        {
            UrlMaker      urlMaker   = UrlMaker.getInstance();
            StringBuilder urlBuilder = new StringBuilder(urlMaker.getAbsoluteUrl(IdentifyExtractUrl));
            string        url        = urlBuilder.ToString() + ExtractEntitiesUrl;

            String requestString = Utility.ObjectToJson <ExtractEntitiesAPIRequest>(request);
            processAPIRequestDelegate <ExtractEntitiesAPIResponse> delegateApiRequest = new processAPIRequestDelegate <ExtractEntitiesAPIResponse>(Utility.processAPIRequest <ExtractEntitiesAPIResponse>);

            delegateApiRequest.BeginInvoke(url, requestString, new AsyncCallback(WorkflowCompletedCallbackExtractEntities), null);
        }
        public void ExtractEntitiesAsyncTest()
        {
            try
            {
                Boolean failFlag = false;
                this.TriggerTest = new AutoResetEvent(false);
                identifyEntityService.IdentifyEntityRequestFinishedEvent += (object sender, WebResponseEventArgs <ExtractEntitiesAPIResponse> eventArgs) =>
                {
                    try
                    {
                        Assert.IsTrue(eventArgs.ResponseObject != null);
                        this.TriggerTest.Set();
                    }
                    catch (Exception)
                    {
                        failFlag = true;
                        this.TriggerTest.Set();
                    }
                };

                List <Record> rowList = new List <Record>();

                List <user_field> user_fields = new List <user_field>();
                user_field        userfield   = new user_field {
                    name = "name1", value = "value1"
                };
                user_fields.Add(userfield);

                rowList.Add(new Record(user_fields, plaintext: "Michael Phelps was a American swimmer. He was born on 30 June 1985 in Towson, Maryland, USA. Visit www.michaelphelps.com"));

                Options options = new Options();

                input input = new input();

                input.RecordList = rowList;
                ExtractEntitiesAPIRequest request = new ExtractEntitiesAPIRequest(input, options);

                identifyEntityService.ExtractEntitiesAsync(request);

                this.TriggerTest.WaitOne(10000);
                if (failFlag)
                {
                    Assert.Fail("Test Case Failed");
                }
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected Exception");
            }
        }
        public void ExtractEntitiesUnitTest()
        {
            try
            {
                List <Record> rowList = new List <Record>();

                List <user_field> user_fields = new List <user_field>();
                user_field        userfield   = new user_field {
                    name = "name1", value = "value1"
                };
                user_fields.Add(userfield);

                rowList.Add(new Record(user_fields, plaintext: "Michael Phelps was a American swimmer. He was born on 30 June 1985 in Towson, Maryland, USA. Visit www.michaelphelps.com"));

                Options options = new Options();
                options.OutputEntityCount = "true";

                List <String> EntityList = new List <string>();
                EntityList.Add(Entity.Person.ToString());
                EntityList.Add(Entity.Location.ToString());
                options.EntityList = String.Join(",", EntityList.ToArray());

                input input = new input();

                input.RecordList = rowList;
                ExtractEntitiesAPIRequest request = new ExtractEntitiesAPIRequest(input, options);

                ExtractEntitiesAPIResponse response = identifyEntityService.ExtractEntities(request);

                Assert.IsInstanceOfType(response, typeof(ExtractEntitiesAPIResponse));
                string output = Utility.ObjectToJson <ExtractEntitiesAPIResponse>(response);
                Debug.WriteLine(output);
            }
            catch (Exception e)
            {
                Assert.Fail("Unexpected exception");
            }
        }