IBM Watson Natural Language了解Java空指针异常

时间:2018-11-24 22:23:20

标签: nlp ibm-watson

我正在使用IBM Watson自然语言理解来分析给定的字符串。目前,我正在按照给出的here示例进行操作。我正在使用Maven构建工具来添加依赖项。我收到一个空值异常。
我删除了这篇文章的api密钥。

 public static void main(String[] args) {
        try {
            IamOptions options = new IamOptions.Builder()
                    .apiKey("{APK}")
                    .build();

            NaturalLanguageUnderstanding service = new NaturalLanguageUnderstanding("2018-03-16", options);
            service.setEndPoint("{https://gateway.watsonplatform.net/natural-language-understanding/api}");


            String text = "Differences in how writing systems represent language raise important questions about the extent to which the\n" +
"role of linguistic skills such as phonological awareness (PA) and morphological awareness (MA) in reading\n" +
"is universal. In this meta-analysis, the authors examined the relationship between PA, MA, and reading\n" +
"(accuracy, fluency, and comprehension) in 2 languages (English and Chinese) representing different writing\n" +
"systems (alphabetic and logographic). A random-effects model analysis of data from 64 studies with native\n" +
"speakers of each language revealed significant correlations between PA, MA, and all reading outcomes in both\n" +
"languages. The correlations remained significant even after controlling for each other’s effect on reading.\n" +
"However, PA was a stronger correlate of reading in English than in Chinese. MA was as good a correlate of\n" +
"reading in English as in";

            CategoriesOptions categories = new CategoriesOptions();

            Features features = new Features.Builder()
                    .categories(categories)
                    .build();

            AnalyzeOptions parameters = new AnalyzeOptions.Builder()
                    .text(text)
                    .features(features)
                    .build();

            AnalysisResults response = service
                    .analyze(parameters)
                    .execute();
            System.out.println(response);

        } catch (Exception e) {
            System.out.println(e.getMessage());
        }

    }

1 个答案:

答案 0 :(得分:2)

您需要从"{https://gateway.watsonplatform.net/natural-language-understanding/api}"-"https://gateway.watsonplatform.net/natural-language-understanding/api"中删除大括号。

(该库正在尝试打开对“ {https:...”的请求,并引发空指针异常,但它应该更正常地失败。)