IBM Watson + Java

Asked

Viewed 149 times

2

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dino_post_java;


import com.ibm.watson.developer_cloud.natural_language_classifier.v1.NaturalLanguageClassifier;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.Classification;
import com.ibm.watson.developer_cloud.natural_language_classifier.v1.model.ClassifyOptions;

import java.util.ArrayList;
import org.json.JSONObject;

/**
 *
 * @author Matheus Markies
 */
public class Text_Robot extends Thread{

    public static ArrayList<String> KeyWords = new ArrayList<String>();

    public void run(){

    //JSONObject vcap =new JSONObject(System.getenv("VCAP_SERVICES"));

   NaturalLanguageClassifier service = new NaturalLanguageClassifier();
    service.setUsernameAndPassword("<username>", "<password>");

    ClassifyOptions classifyOptions = new ClassifyOptions.Builder()
        .classifierId("<classifierId>")
        .text("Is it sunny?")
        .build();
    Classification classification = service.classify(classifyOptions).execute();

    System.out.println(classification);

    }

}

I’m not getting the Naturallanguageclassifier. When I try to run the program it turns the error below:

inserir a descrição da imagem aqui

I tried to use VCAP_SERVICES.json as shown in this website

But I didn’t get any results.

When I try to access the link using the user and password I put, it says that the user and password are wrong. inserir a descrição da imagem aqui

Can someone help me!

1 answer

0


Step 1:

According to the error message, you are not passing your credentials correctly Exception in thread "Thread-5" ... Access denied due to invalid credentials.

Try to perform the steps according to your own watson documentation:

Step 1: Log in, create the service, and get your credentials

If you already know your credentials for the Natural service instance Language Classifier, ignore this step.

  • Go to Natural Language Classifier and sign up for a free account or log in to the IBM Cloud account.
  • After logging in, on the Natural Language Classifier page, type Classifier-tutorial in the Service name field to identify this instance of the service and click Create.
  • Copy your credentials:
    • to. Click on Service credentials.
    • b. Click View credentials in the "Service credentials section".
    • c. Copy the values username and password.

Step 2:

The error is also indicating that it may be a failure to specify the endpoint. Check if it is correct and according to the API of Watson

Step 3:

It can be of great help to check open-source code of users who have already implemented such cited functions as an example: NaturalLanguageClassifier javaSDK

Step 4:

If it still doesn’t work check the error logs and lines of code where errors are appearing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.