Not able to find out the IBM NLU latest syntax for Python

271 Views Asked by At

I am trying to connect IBM Watson NLU using python but below code is outdated because today I have created the new resource group for the IBM NLU then I tried to find out the credentials but I didn't get the username and password.

There are new things. Please check the below image.

enter image description here

    natural_language_understanding = NaturalLanguageUnderstandingV1(
        url=<URL>,
        version='2018-03-16',
        username=<UserName>,
        password=<Password>)

    natural_language_understanding.disable_SSL_verification()
    try:
        response = natural_language_understanding.analyze(
            text=str(user_answer_sent),
            features=Features(
                semantic_roles=SemanticRolesOptions(),
                sentiment=SentimentOptions()
            ), language='en'
        ).get_result()

I am not able to find out the latest syntax for IBM Watson NLU. Please let me know if you have then I will try it.

2

There are 2 best solutions below

0
Allen Dean On BEST ANSWER

There are additional examples and more information in the API reference.

3
data_henrik On

Please check out the Python SDK for the IBM Watson services. It includes sample code for IBM Watson NLU which shows how the new Authenticator model is used. It is something like:

import json
from ibm_watson import NaturalLanguageUnderstandingV1
from ibm_watson.natural_language_understanding_v1 import Features, EntitiesOptions, KeywordsOptions
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator

# Authentication via IAM
authenticator = IAMAuthenticator('your_api_key')
 service = NaturalLanguageUnderstandingV1(
     version='2018-03-16',
     authenticator=authenticator)
 service.set_service_url('https://gateway.watsonplatform.net/natural-language-understanding/api')