1
votes

I am using IBM Watson Natural Language Understanding for analyze a given string. Currently I am following the example given here. I am using maven build tool to add the dependencies. I am getting a null point exception.
I removed the api key for this post.

 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

1 Answers

2
votes

You need to remove the curly brackets from "{https://gateway.watsonplatform.net/natural-language-understanding/api}" -- "https://gateway.watsonplatform.net/natural-language-understanding/api".

(The library is trying to open a request to "{https:..." and throwing a null pointer exception, but it should fail more gracefully.)