/// <summary>
        /// Lists available models for Relations and Entities features, including Watson Knowledge Studio
        /// custom models that you have created and linked to your Natural Language Understanding service.
        /// </summary>
        /// <param name="successCallback">The success callback.</param>
        /// <param name="failCallback">The fail callback.</param>
        /// <param name="customData">Optional custom data.</param>
        /// <returns>True if the call succeeds, false if the call is unsuccessful.</returns>
        public bool GetModels(SuccessCallback <ListModelsResults> successCallback, FailCallback failCallback, Dictionary <string, object> customData = null)
        {
            if (successCallback == null)
            {
                throw new ArgumentNullException("successCallback");
            }
            if (failCallback == null)
            {
                throw new ArgumentNullException("failCallback");
            }

            GetModelsRequest req = new GetModelsRequest();

            req.SuccessCallback       = successCallback;
            req.FailCallback          = failCallback;
            req.CustomData            = customData == null ? new Dictionary <string, object>() : customData;
            req.Parameters["version"] = NaturalLanguageUnderstandingVersion.Version;
            req.OnResponse            = OnGetModelsResponse;

            RESTConnector connector = RESTConnector.GetConnector(Credentials, ModelsEndpoint);

            if (connector == null)
            {
                return(false);
            }

            return(connector.Send(req));
        }
Beispiel #2
0
        /// <summary>
        /// Lists available models for Relations and Entities features, including Watson Knowledge Studio
        /// custom models that you have created and linked to your Natural Language Understanding service.
        /// </summary>
        /// <param name="successCallback">The success callback.</param>
        /// <param name="failCallback">The fail callback.</param>
        /// <param name="customData">Optional custom data.</param>
        /// <returns>True if the call succeeds, false if the call is unsuccessful.</returns>
        public bool GetModels(SuccessCallback <ListModelsResults> successCallback, FailCallback failCallback, Dictionary <string, object> customData = null)
        {
            if (successCallback == null)
            {
                throw new ArgumentNullException("successCallback");
            }
            if (failCallback == null)
            {
                throw new ArgumentNullException("failCallback");
            }

            GetModelsRequest req = new GetModelsRequest();

            req.SuccessCallback = successCallback;
            req.FailCallback    = failCallback;
            req.CustomData      = customData == null ? new Dictionary <string, object>() : customData;
            if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS))
            {
                foreach (KeyValuePair <string, string> kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary <string, string> )
                {
                    req.Headers.Add(kvp.Key, kvp.Value);
                }
            }
            req.Parameters["version"] = NaturalLanguageUnderstandingVersion.Version;
            req.OnResponse            = OnGetModelsResponse;

            RESTConnector connector = RESTConnector.GetConnector(Credentials, ModelsEndpoint);

            if (connector == null)
            {
                return(false);
            }

            return(connector.Send(req));
        }
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonFraudDetectorConfig config = new AmazonFraudDetectorConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonFraudDetectorClient client = new AmazonFraudDetectorClient(creds, config);

            GetModelsResponse resp = new GetModelsResponse();

            do
            {
                GetModelsRequest req = new GetModelsRequest
                {
                    NextToken = resp.NextToken
                    ,
                    MaxResults = maxItems
                };

                resp = client.GetModels(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Models)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Beispiel #4
0
        /// <summary>
        /// This function retrieves all the language models that the user may use by setting the RecognizeModel
        /// public property.
        /// </summary>
        /// <param name="callback">This callback is invoked with an array of all available models. The callback will
        /// be invoked with null on error.</param>
        /// <returns>Returns true if request has been made.</returns>
        public bool GetModels(OnGetModels callback)
        {
            RESTConnector connector = RESTConnector.GetConnector(SERVICE_ID, "/v1/models");

            if (connector == null)
            {
                return(false);
            }

            GetModelsRequest req = new GetModelsRequest();

            req.Callback   = callback;
            req.OnResponse = OnGetModelsResponse;

            return(connector.Send(req));
        }
        /// <summary>
        /// Lists available models for Relations and Entities features, including Watson Knowledge Studio
        /// custom models that you have created and linked to your Natural Language Understanding service.
        /// </summary>
        /// <param name="successCallback">The success callback.</param>
        /// <param name="failCallback">The fail callback.</param>
        /// <param name="customData">Optional custom data.</param>
        /// <returns>True if the call succeeds, false if the call is unsuccessful.</returns>
        public bool GetModels(SuccessCallback <ListModelsResults> successCallback, FailCallback failCallback, Dictionary <string, object> customData = null)
        {
            if (successCallback == null)
            {
                throw new ArgumentNullException("successCallback");
            }
            if (failCallback == null)
            {
                throw new ArgumentNullException("failCallback");
            }

            GetModelsRequest req = new GetModelsRequest();

            req.SuccessCallback        = successCallback;
            req.FailCallback           = failCallback;
            req.HttpMethod             = UnityWebRequest.kHttpVerbGET;
            req.DisableSslVerification = DisableSslVerification;
            req.CustomData             = customData == null ? new Dictionary <string, object>() : customData;
            if (req.CustomData.ContainsKey(Constants.String.CUSTOM_REQUEST_HEADERS))
            {
                foreach (KeyValuePair <string, string> kvp in req.CustomData[Constants.String.CUSTOM_REQUEST_HEADERS] as Dictionary <string, string> )
                {
                    req.Headers.Add(kvp.Key, kvp.Value);
                }
            }
            req.Parameters["version"] = NaturalLanguageUnderstandingVersion.Version;
            req.OnResponse            = OnGetModelsResponse;
            req.Headers["X-IBMCloud-SDK-Analytics"] = "service_name=natural_language_understanding;service_version=v1;operation_id=GetModels";

            RESTConnector connector = RESTConnector.GetConnector(Credentials, ModelsEndpoint);

            if (connector == null)
            {
                return(false);
            }

            return(connector.Send(req));
        }
Beispiel #6
0
        private void OnGetModelsResponse(RESTConnector.Request req, RESTConnector.Response resp)
        {
            GetModelsRequest gmr = req as GetModelsRequest;

            if (gmr == null)
            {
                throw new WatsonException("Unexpected request type.");
            }

            SpeechModel[] models = null;
            if (resp.Success)
            {
                models = ParseGetModelsResponse(resp.Data);
                if (models == null)
                {
                    Log.Error("SpeechToText", "Failed to parse GetModels response.");
                }
            }
            if (gmr.Callback != null)
            {
                gmr.Callback(models);
            }
        }
        /// <summary>
        /// Lists available models for Relations and Entities features, including Watson Knowledge Studio
        /// custom models that you have created and linked to your Natural Language Understanding service.
        /// </summary>
        /// <param name="callback">The OnGetModels callback.</param>
        /// <param name="customData">Optional custom data.</param>
        /// <returns>True if the call succeeds, false if the call is unsuccessful.</returns>
        public bool GetModels(OnGetModels callback, string customData = default(string))
        {
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            GetModelsRequest req = new GetModelsRequest();

            req.Callback = callback;
            req.Data     = customData;
            req.Parameters["version"] = NaturalLanguageUnderstandingVersion.Version;
            req.OnResponse            = OnGetModelsResponse;

            RESTConnector connector = RESTConnector.GetConnector(Credentials, ModelsEndpoint);

            if (connector == null)
            {
                return(false);
            }

            return(connector.Send(req));
        }