public void ClassifyCollection_Success() { IClient client = Substitute.For <IClient>(); IRequest request = Substitute.For <IRequest>(); client.PostAsync(Arg.Any <string>()) .Returns(request); NaturalLanguageClassifierService service = new NaturalLanguageClassifierService(client); var classifierId = "classifierId"; var collection = new List <ClassifyInput>(); var result = service.ClassifyCollection(classifierId: classifierId, collection: collection); JObject bodyObject = new JObject(); if (collection != null && collection.Count > 0) { bodyObject["collection"] = JToken.FromObject(collection); } var json = JsonConvert.SerializeObject(bodyObject); request.Received().WithBodyContent(Arg.Is <StringContent>(x => x.ReadAsStringAsync().Result.Equals(json))); client.Received().PostAsync($"{service.ServiceUrl}/v1/classifiers/{classifierId}/classify_collection"); }
public void ClassifyCollection() { TokenOptions tokenOptions = new TokenOptions() { IamApiKey = apikey, ServiceUrl = url }; NaturalLanguageClassifierService service = new NaturalLanguageClassifierService(tokenOptions); var collection = new List <ClassifyInput>() { new ClassifyInput() { Text = "Will it be hot today?" }, new ClassifyInput() { Text = "Is it raining?" } }; var result = service.ClassifyCollection( classifierId: classifierId, collection: collection ); Console.WriteLine(result.Response); }
public void ClassifyCollection() { IamConfig config = new IamConfig( apikey: apikey ); NaturalLanguageClassifierService service = new NaturalLanguageClassifierService(config); service.SetEndpoint(url); var collection = new List <ClassifyInput>() { new ClassifyInput() { Text = "Will it be hot today?" }, new ClassifyInput() { Text = "Is it raining?" } }; var result = service.ClassifyCollection( classifierId: classifierId, collection: collection ); Console.WriteLine(result.Response); }
public void ClassifyCollection() { IamAuthenticator authenticator = new IamAuthenticator( apikey: "{apikey}"); NaturalLanguageClassifierService service = new NaturalLanguageClassifierService(authenticator); service.SetServiceUrl("{serviceUrl}"); var collection = new List <ClassifyInput>() { new ClassifyInput() { Text = "How hot will it be today?" }, new ClassifyInput() { Text = "Is it hot outside?" } }; var result = service.ClassifyCollection( classifierId: "10D41B-nlc-1", collection: collection ); Console.WriteLine(result.Response); }
private ClassificationCollection ClassifyCollection(string classifierId, ClassifyCollectionInput body, Dictionary <string, object> customData = null) { Console.WriteLine("\nAttempting to ClassifyCollection()"); var result = _service.ClassifyCollection(classifierId: classifierId, body: body, customData: customData); if (result != null) { Console.WriteLine("ClassifyCollection() succeeded:\n{0}", JsonConvert.SerializeObject(result, Formatting.Indented)); } else { Console.WriteLine("Failed to ClassifyCollection()"); } return(result); }
public IEnumerator TestClassifyCollection() { Log.Debug("NaturalLanguageClassifierServiceV1IntegrationTests", "Attempting to ClassifyCollection..."); ClassificationCollection classifyCollectionResponse = null; List <ClassifyInput> collection = new List <ClassifyInput>() { new ClassifyInput() { Text = textToClassify0 }, new ClassifyInput() { Text = textToClassify1 } }; service.ClassifyCollection( callback: (DetailedResponse <ClassificationCollection> response, IBMError error) => { Log.Debug("NaturalLanguageClassifierServiceV1IntegrationTests", "ClassifyCollection result: {0}", response.Response); classifyCollectionResponse = response.Result; Assert.IsNotNull(classifyCollectionResponse); Assert.IsNotNull(classifyCollectionResponse.Collection); Assert.IsTrue(classifyCollectionResponse.Collection.Count > 0); Assert.IsTrue(classifyCollectionResponse.ClassifierId == classifierId); Assert.IsNull(error); }, classifierId: classifierId, collection: collection ); while (classifyCollectionResponse == null) { yield return(null); } }
public void TestClassifiers_Success() { service.WithHeader("X-Watson-Test", "1"); var listClassifiersResult = service.ListClassifiers(); string classifierId = null; if (listClassifiersResult.Result.Classifiers.Count > 0) { classifierId = listClassifiersResult.Result.Classifiers[0].ClassifierId; } DetailedResponse <Classification> classifyResult = null; if (!string.IsNullOrEmpty(classifierId)) { service.WithHeader("X-Watson-Test", "1"); classifyResult = service.Classify( classifierId: classifierId, text: textToClassify1 ); } DetailedResponse <ClassificationCollection> classifyCollectionResult = null; if (!string.IsNullOrEmpty(classifierId)) { var collection = new List <ClassifyInput>() { new ClassifyInput() { Text = textToClassify0 }, new ClassifyInput() { Text = textToClassify1 } }; service.WithHeader("X-Watson-Test", "1"); classifyCollectionResult = service.ClassifyCollection( classifierId: classifierId, collection: collection ); } DetailedResponse <Classifier> createClassifierResult = null; using (FileStream trainingDataFile = File.OpenRead(classifierDataFilePath), metadataFile = File.OpenRead(metadataDataFilePath)) { using (MemoryStream trainingData = new MemoryStream(), metadata = new MemoryStream()) { trainingDataFile.CopyTo(trainingData); metadataFile.CopyTo(metadata); service.WithHeader("X-Watson-Test", "1"); createClassifierResult = service.CreateClassifier( trainingMetadata: metadata, trainingData: trainingData ); } } var createdClassifierId = createClassifierResult.Result.ClassifierId; service.WithHeader("X-Watson-Test", "1"); var getClassifierResult = service.GetClassifier( classifierId: createdClassifierId ); if (!string.IsNullOrEmpty(classifierId) && !string.IsNullOrEmpty(createdClassifierId)) { service.WithHeader("X-Watson-Test", "1"); service.DeleteClassifier( classifierId: createdClassifierId ); } if (!string.IsNullOrEmpty(classifierId)) { Assert.IsNotNull(classifyResult); Assert.IsNotNull(classifyCollectionResult); } Assert.IsNotNull(getClassifierResult); Assert.IsTrue(createdClassifierId == getClassifierResult.Result.ClassifierId); Assert.IsNotNull(createClassifierResult); Assert.IsNotNull(listClassifiersResult); }