test(nlc): Update natural language cllassifier examples
-from __future__ import print_function
import json
import os
-# from os.path import join, dirname
from ibm_watson import NaturalLanguageClassifierV1
+from ibm_cloud_sdk_core.authenticators import IAMAuthenticator
-# If service instance provides API key authentication
+authenticator = IAMAuthenticator('your_api_key')
service = NaturalLanguageClassifierV1(
## url is optional, and defaults to the URL below. Use the correct URL for your region.
url='https://gateway.watsonplatform.net/natural-language-classifier/api',
- iam_apikey='YOUR APIKEY')
-
-# service = NaturalLanguageClassifierV1(
-# ## url is optional, and defaults to the URL below. Use the correct URL for your region.
-# # url='https://gateway.watsonplatform.net/natural-language-classifier/api',
-# username='YOUR SERVICE USERNAME',
-# password='YOUR SERVICE PASSWORD')
+ authenticator=authenticator)
classifiers = service.list_classifiers().get_result()
print(json.dumps(classifiers, indent=2))
@@ -27,7 +20,7 @@ with open(
'rb') as training_data:
metadata = json.dumps({'name': 'my-classifier', 'language': 'en'})
classifier = service.create_classifier(
- metadata=metadata, training_data=training_data).get_result()
+ training_metadata=metadata, training_data=training_data).get_result()
classifier_id = classifier['classifier_id']
print(json.dumps(classifier, indent=2))
@@ -52,5 +45,5 @@ print(json.dumps(delete, indent=2))
# example of raising a ValueError
# print(json.dumps(
-# service.create_classifier(training_data='', name='weather3', metadata='metadata'),
+# service.create_classifier(training_data='', training_metadata='metadata'),
# indent=2))
