There's more…

The translate method is overloaded, providing various translation options to be applied using the TranslateOption class. These methods are listed here:

  • sourceLanguage: Takes a language code that specifies the language being translated.
  • targetLanguage: Takes a language code that specifies the language being translated to.
  • model: Specifies the model to use. The model used can be specified using the model method, as shown next (Translate.TranslateOption.model("nmt")). The nmt and base strings are used for the NMT and PBMT models, respectively.

Add the following code to the main method. The code demonstrates the use of these methods. The first sequence specifies a target language of German using the NMT model. The second sequence ...

Get Natural Language Processing with Java Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.