src/Classificationbox.Net/ServiceWrapper.cs
/// <summary>
/// Creates a model with the given name and classification classes.
/// </summary>
/// <param name="modelName">name of the model to create</param>
/// <param name="classes">list of classification classes</param>
/// <returns></returns>
Creates a model with the given name and classification classes.
Creates a model with the given name and classification classes .
public CreateModelResponse CreateModel(string modelName, IEnumerable<string> classes)
        {
            HttpClient client = new HttpClient();
            var classesString = "\"" + string.Join(",", classes).Replace(",", "\",\"") + "\"";
            var payload = string.Format("{{ \"name\": \"{0}\", \"classes\": [ {1} ] }}", modelName, classesString);
            HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json");
            var request = new HttpRequestMessage
            {
                Method = HttpMethod.Post,
                RequestUri = new Uri(_baseUrl + "/classificationbox/models"),
                Headers = {
                    { HttpRequestHeader.Accept.ToString(), "application/json; charset=utf-8" }
                },
                Content = content
            };
            HttpResponseMessage rsp;
            try
            {
                rsp = client.SendAsync(request).GetAwaiter().GetResult();
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString());
                return new CreateModelResponse() { error = ex.Message };
            }
            var s = rsp.Content.ReadAsStringAsync().Result;
            var ret = JsonConvert.DeserializeObject<CreateModelResponse>(s);
            if (!ret.success)
                Debug.WriteLine($"Error creating model '{modelName}': {ret.error}");
            return ret;
        }
public CreateModelResponse CreateModel ( string modelName , IEnumerable < string > classes ) { HttpClient client = new HttpClient ( ) ; var classesString = " \" " + string . Join ( " " , classes ) . Replace ( " " , " \" \" " ) + " \" " ; var payload = string . Format ( " \" \" \" \" \" \" " , modelName , classesString ) ; HttpContent content = new StringContent ( payload , Encoding . UTF8 , " " ) ; var request = new HttpRequestMessage { Method = HttpMethod . Post , RequestUri = new Uri ( _baseUrl + " " ) , Headers = { { HttpRequestHeader . Accept . ToString ( ) , " " } } , Content = content } ; HttpResponseMessage rsp ; try { rsp = client . SendAsync ( request ) . GetAwaiter ( ) . GetResult ( ) ; } catch ( Exception ex ) { Debug . WriteLine ( ex . ToString ( ) ) ; return new CreateModelResponse ( ) { error = ex . Message } ; } var s = rsp . Content . ReadAsStringAsync ( ) . Result ; var ret = JsonConvert . DeserializeObject < CreateModelResponse > ( s ) ; if ( ! ret . success ) Debug . WriteLine ( $" Error creating model ' { modelName } ':  { ret . error } " ) ; return ret ; }
Creates a model with the given name and classification classes.
Creates a model with the given name and classification classes .
// id: 60ad2c0247c41223
None
modelName
string
name of the model to create
name of the model to create
classes
IEnumerable<string>
list of classification classes
list of classification classes