0

Recently, I tried to work with IBM's Watson text assistant. I chose to program it with Java and everything worked alright until I tried to use German phrases, which use umlauts [ä, ö, ü].

The skill language is also German.

When receiving a response from the API, all umlauts where replaced by �.

Here's the code:

public String inquiry(String anfrage){
    MessageInput input = new MessageInput();
    input.setText(anfrage);

    MessageOptions options = new MessageOptions.Builder(WORKSPACEID)
            .input(input)
            .build();

    MessageResponse response = assistant.message(options)
            .execute()
            .getResult();

    return response.getOutput().getGeneric().get(0).text();
}

Do you know a way to properly get umlauts from the IBM API?

Lucadmin
  • 157
  • 1
  • 12
  • Which operating system and how / where do you print the output? This looks like an encoding issue on your side. Do you handle Unicode strings? Are you using the Java SDK or the REST API directly? https://github.com/watson-developer-cloud/java-sdk/tree/master/assistant – data_henrik Jun 17 '20 at 11:41
  • I'm using Windows 10 with IntelliJ Ultimate version and system.out.println the response – Lucadmin Jun 17 '20 at 11:44
  • https://stackoverflow.com/questions/28567208/how-can-i-change-the-standard-out-to-utf-8-in-java/42957623 could you try this? – data_henrik Jun 17 '20 at 11:49
  • It works now. Thank you really much – Lucadmin Jun 17 '20 at 13:43

1 Answers1

1

This line did it in my case. (Thanks to @data_henrik)

System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out), true, "UTF-8"));
Lucadmin
  • 157
  • 1
  • 12