org.apache.tika.language.translate.YandexTranslator类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(2.9k)|赞(0)|评价(0)|浏览(147)

本文整理了Java中org.apache.tika.language.translate.YandexTranslator类的一些代码示例,展示了YandexTranslator类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YandexTranslator类的具体详情如下:
包路径:org.apache.tika.language.translate.YandexTranslator
类名称:YandexTranslator

YandexTranslator介绍

[英]An implementation of a REST client for the YANDEX Translate API. You can sign up for free access online on the API Key form and set your Application's User Key in the translator.yandex.properties file.
[中]YANDEXTranslate API的REST客户端的实现。您可以在API Key form上在线注册免费访问,并在translator.yandex.properties文件中设置应用程序的用户密钥。

代码示例

代码示例来源:origin: apache/tika

@Before
public void setUp() throws Exception {
  this.translator = new YandexTranslator();
}

代码示例来源:origin: apache/tika

@Override
public String translate(String text, String targetLanguage)
    throws TikaException, IOException {
  return this.translate(text, null, targetLanguage);
}

代码示例来源:origin: com.norconex.collectors/norconex-importer

@Override
public Translator createTranslator() {
  YandexTranslator t = new YandexTranslator();
  t.setApiKey(apiKey);
  return t;
}
@Override

代码示例来源:origin: apache/tika

@Override
public String translate(String text, String sourceLanguage,
    String targetLanguage) throws TikaException, IOException {
  if (!this.isAvailable()) {
    return text;

代码示例来源:origin: org.apache.tika/tika-translate

@Override
public String translate(String text, String sourceLanguage,
    String targetLanguage) throws TikaException, IOException {
  if (!this.isAvailable()) {
    return text;

代码示例来源:origin: apache/tika

@Test
public void test2UNDEFINED_DE_ES_Translation() {
  String inputText = "Guten Tag!!!";
  String expectedText = "Buen Día!!!";
  try{
   String transText = translator.translate(inputText, "es");
  assertNotNull("Text not translated", transText);
  assumeTrue(expectedText.equals(transText));
  }
  catch(TikaException e){
  e.printStackTrace();
  fail(e.getMessage());
  }
  catch(IOException e){
    e.printStackTrace();
    fail(e.getMessage());
  }
}

代码示例来源:origin: apache/tika

@Test
public void test1EN_ES_Translation() {
  String inputText = "Hello World!!!";
  String expectedText = "Hola Mundo!!!";
  try{
   String transText = translator.translate(inputText, "en", "es");
    assertNotNull("Text not translated", transText);
    assumeTrue(expectedText.equals(transText));
}
catch(TikaException e){
  e.printStackTrace();
  fail(e.getMessage());
}
catch(IOException e){
    e.printStackTrace();
    fail(e.getMessage());
  }
}

代码示例来源:origin: org.apache.tika/tika-translate

@Override
public String translate(String text, String targetLanguage)
    throws TikaException, IOException {
  return this.translate(text, null, targetLanguage);
}

代码示例来源:origin: apache/tika

@Test
public void test3UNDEFINED_IT_EN_Translation() {
  String inputText = "Buona Sera!!!";
  String expectedText = "Good Evening!!!";
  try{
    String transText = translator.translate(inputText, "en");
    assertNotNull("Text not translated", transText);
    assumeTrue(expectedText.equals(transText));
}
catch(TikaException e){
    e.printStackTrace();
    fail(e.getMessage());
}
  catch(IOException e){
    e.printStackTrace();
    fail(e.getMessage());
  }
}

相关文章