【问题标题】:IBM Watson Natural Language Understanding Java null pointer exceptionIBM Watson 自然语言理解 Java 空指针异常
【发布时间】:2018-11-27 03:03:35
【问题描述】:

我正在使用 IBM Watson Natural Language Understanding 来分析给定的字符串。目前我正在按照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());
        }

    }

【问题讨论】:

    标签: nlp ibm-watson


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-11
      • 1970-01-01
      • 2017-12-23
      • 2017-09-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多