Анализатор тона IBM Watson

Попытка работать с образцом кода для работы. Я использую Java 7.

Я получаю ошибку в этой строке

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

Уведомление просит меня выполнить поиск репо для «сервиса». Этого не должно быть, поскольку служба определена в строке выше. Кто-нибудь знает, что здесь может быть не так?

import com.ibm.watson.developer_cloud.tone_analyzer.v3.*;
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis;
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneOptions;

public class test {

    ToneAnalyzer service = new ToneAnalyzer("2017-09-21");
service.setUsernameAndPassword("<username>", "<password>");

String text =
  "I know the times are difficult! Our sales have been "
      + "disappointing for the past three quarters for our data analytics "
      + "product suite. We have a competitive data analytics product "
      + "suite in the industry. But we need to do our job selling it! "
      + "We need to acknowledge and fix our sales challenges. "
      + "We can’t blame the economy for our lack of execution! "
      + "We are missing critical sales opportunities. "
      + "Our product is in no way inferior to the competitor products. "
      + "Our clients are hungry for analytical tools to improve their "
      + "business outcomes. Economy has nothing to do with it.";

// Call the service and get the tone
ToneOptions toneOptions = new ToneOptions.Builder()
  .html(text)
  .build();

ToneAnalysis tone = service.tone(toneOptions).execute();
System.out.println(tone);

}

Я также получаю сообщение об ошибке для System.out.println, в котором говорится, что он не может найти символ «тон».

пом-файл:

    <dependency>
        <groupId>com.ibm.watson.developer_cloud</groupId>
        <artifactId>java-sdk</artifactId>
        <version>6.1.0</version>
    </dependency>  

person fints1col    schedule 21.06.2018    source источник
comment
Не могли бы вы также вставить точную ошибку.   -  person Aman Chhabra    schedule 21.06.2018


Ответы (1)


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

Это оператор вызова, и он должен находиться внутри метода.

Может быть, вы хотите переписать свой класс следующим образом:

import com.ibm.watson.developer_cloud.tone_analyzer.v3.*;
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneAnalysis;
import com.ibm.watson.developer_cloud.tone_analyzer.v3.model.ToneOptions;

public class Test {

public static void main(String...s) {
    ToneAnalyzer service = new ToneAnalyzer("2017-09-21");
service.setUsernameAndPassword("<username>", "<password>");

String text =
  "I know the times are difficult! Our sales have been "
      + "disappointing for the past three quarters for our data analytics "
      + "product suite. We have a competitive data analytics product "
      + "suite in the industry. But we need to do our job selling it! "
      + "We need to acknowledge and fix our sales challenges. "
      + "We can’t blame the economy for our lack of execution! "
      + "We are missing critical sales opportunities. "
      + "Our product is in no way inferior to the competitor products. "
      + "Our clients are hungry for analytical tools to improve their "
      + "business outcomes. Economy has nothing to do with it.";

// Call the service and get the tone
ToneOptions toneOptions = new ToneOptions.Builder()
  .html(text)
  .build();

ToneAnalysis tone = service.tone(toneOptions).execute();
System.out.println(tone);

}

}

PS: Хороший стандарт кодирования — начинать имя класса с заглавной буквы.

person Aman Chhabra    schedule 21.06.2018
comment
Спасибо. Но как мне найти документ IBM watson java? Например, я хочу анализировать длинные абзацы, не прерывая запросы на точки. - person fints1col; 28.06.2018