• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TranslateOption类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.google.cloud.translate.Translate.TranslateOption的典型用法代码示例。如果您正苦于以下问题:Java TranslateOption类的具体用法?Java TranslateOption怎么用?Java TranslateOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TranslateOption类属于com.google.cloud.translate.Translate包,在下文中一共展示了TranslateOption类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: translateText

import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
 * Translate the source text from source to target language.
 *
 * @param sourceText source text to be translated
 * @param sourceLang source language of the text
 * @param targetLang target language of translated text
 * @return source text translated into target language.
 */
public static String translateText(
    String sourceText,
    String sourceLang,
    String targetLang) {
  if (Strings.isNullOrEmpty(sourceLang)
      || Strings.isNullOrEmpty(targetLang)
      || sourceLang.equals(targetLang)) {
    return sourceText;
  }
  com.google.cloud.translate.Translate translate = createTranslateService();
  TranslateOption srcLang = TranslateOption.sourceLanguage(sourceLang);
  TranslateOption tgtLang = TranslateOption.targetLanguage(targetLang);

  Translation translation = translate.translate(sourceText, srcLang, tgtLang);
  return translation.getTranslatedText();
}
 
开发者ID:GoogleCloudPlatform,项目名称:getting-started-java,代码行数:25,代码来源:Translate.java


示例2: main

import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
public static void main(String... args) throws Exception {
  // Instantiates a client
  Translate translate = TranslateOptions.getDefaultInstance().getService();

  // The text to translate
  String text = "Hello, world!";

  // Translates some text into Russian
  Translation translation =
      translate.translate(
          text,
          TranslateOption.sourceLanguage("en"),
          TranslateOption.targetLanguage("ru"));


  System.out.printf("Text: %s%n", text);
  System.out.printf("Translation: %s%n", translation.getTranslatedText());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:19,代码来源:QuickstartSample.java


示例3: translateTextWithOptionsAndModel

import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
 * Translate the source text from source to target language.
 * Make sure that your project is whitelisted.
 *
 * @param sourceText source text to be translated
 * @param sourceLang source language of the text
 * @param targetLang target language of translated text
 * @param out print stream
 */
public static void translateTextWithOptionsAndModel(
    String sourceText,
    String sourceLang,
    String targetLang,
    PrintStream out) {

  Translate translate = createTranslateService();
  TranslateOption srcLang = TranslateOption.sourceLanguage(sourceLang);
  TranslateOption tgtLang = TranslateOption.targetLanguage(targetLang);

  // Use translate `model` parameter with `base` and `nmt` options.
  TranslateOption model = TranslateOption.model("nmt");

  Translation translation = translate.translate(sourceText, srcLang, tgtLang, model);
  out.printf("Source Text:\n\tLang: %s, Text: %s\n", sourceLang, sourceText);
  out.printf("TranslatedText:\n\tLang: %s, Text: %s\n", targetLang,
      translation.getTranslatedText());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:28,代码来源:TranslateText.java


示例4: translateTextWithOptions

import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
 * Translate the source text from source to target language.
 *
 * @param sourceText source text to be translated
 * @param sourceLang source language of the text
 * @param targetLang target language of translated text
 * @param out print stream
 */
public static void translateTextWithOptions(
    String sourceText,
    String sourceLang,
    String targetLang,
    PrintStream out) {

  Translate translate = createTranslateService();
  TranslateOption srcLang = TranslateOption.sourceLanguage(sourceLang);
  TranslateOption tgtLang = TranslateOption.targetLanguage(targetLang);

  Translation translation = translate.translate(sourceText, srcLang, tgtLang);
  out.printf("Source Text:\n\tLang: %s, Text: %s\n", sourceLang, sourceText);
  out.printf("TranslatedText:\n\tLang: %s, Text: %s\n", targetLang,
      translation.getTranslatedText());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:24,代码来源:TranslateText.java


示例5: GoogleTranslateApiPageOutput

import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
public GoogleTranslateApiPageOutput(TaskSource taskSource, Schema inputSchema, Schema outputSchema, PageOutput output) {
    this.task = taskSource.loadTask(PluginTask.class);
    this.outputSchema = outputSchema;
    this.inputColumns = inputSchema.getColumns();
    this.reader = new PageReader(inputSchema);
    this.builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, output);
    this.keyNameColumns = Lists.newArrayList();
    for (String keyName : task.getKeyNames()) {
        this.keyNameColumns.add(outputSchema.lookupColumn(keyName));
    }
    this.translate = createTranslateService();

    this.srcLang = task.getSourceLang().isPresent() ? TranslateOption.sourceLanguage(task.getSourceLang().get()) : null;
    this.model = task.getModel().isPresent() ? TranslateOption.model(task.getModel().get()) : null;
}
 
开发者ID:toyama0919,项目名称:embulk-filter-google_translate_api,代码行数:16,代码来源:GoogleTranslateApiPageOutput.java


示例6: translate

import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
/**
 * @param texts
 * @return
 */
private List<Translation> translate(List<String> texts) {
    TranslateOption[] translateOptions = new TranslateOption[] {};
    if (srcLang != null) {
        translateOptions = ArrayUtils.add(translateOptions, srcLang);
    }
    if (model != null) {
        translateOptions = ArrayUtils.add(translateOptions, model);
    }
    return translate.translate(texts, translateOptions);
}
 
开发者ID:toyama0919,项目名称:embulk-filter-google_translate_api,代码行数:15,代码来源:GoogleTranslateApiPageOutput.java


示例7: translate

import com.google.cloud.translate.Translate.TranslateOption; //导入依赖的package包/类
public String translate(String text, String languageFrom,
		String languageTo) {
	Translation translation = translate.translate(text,
			TranslateOption.sourceLanguage(languageFrom),
			TranslateOption.targetLanguage(languageTo));

	String translatedText = translation.getTranslatedText();
	log.trace("Translating {} [{}] to [{}] ... result={}", text,
			languageFrom, languageTo, translatedText);
	return translatedText;
}
 
开发者ID:bonigarcia,项目名称:dualsub,代码行数:12,代码来源:Translator.java



注:本文中的com.google.cloud.translate.Translate.TranslateOption类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HealthData类代码示例发布时间:2022-05-22
下一篇:
Java ResultProducer类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap