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

Java GoogleAPI类代码示例

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

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



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

示例1: translate

import com.google.api.GoogleAPI; //导入依赖的package包/类
static String translate(String sourceLanguageCode, String targetLanguageCode, String sourceText) {
    Log.d(TAG, sourceLanguageCode + " -> " + targetLanguageCode);

    // Truncate excessively long strings. Limit for Google Translate is 5000 characters
    if (sourceText.length() > 4500) {
        sourceText = sourceText.substring(0, 4500);
    }

    GoogleAPI.setKey(API_KEY);
    GoogleAPI.setHttpReferrer("https://github.com/rmtheis/android-ocr");
    try {
        return Translate.DEFAULT.execute(sourceText, Language.fromString(sourceLanguageCode),
                Language.fromString(targetLanguageCode));
    } catch (Exception e) {
        Log.e(TAG, "Caught exeption in translation request.");
        return Translator.BAD_TRANSLATION_MSG;
    }
}
 
开发者ID:hujiaweibujidao,项目名称:android-ocr-demo,代码行数:19,代码来源:TranslatorGoogle.java


示例2: googleValidator

import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
 * 访问goolge api以验证 Key是否可用。 ;
 */
private void googleValidator() {
	final String googleKey = googleKeyText.getText();
	BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

		public void run() {
			// TODO Auto-generated method stub
			if (googleKey != null && !googleKey.trim().equals("")) {
				GoogleAPI.setHttpReferrer("http://www.heartsome.net");
				GoogleAPI.setKey(googleKey);
				try {
					String result = Translate.DEFAULT.execute("test", GoogleTransUtils.processLanguage("en-US"),
							GoogleTransUtils.processLanguage("zh-CN"));
					if (result.equals("测试")) {
						googleState = true;
					}
				} catch (GoogleAPIException e) {
					googleState = false;
				}
			} else {
				googleState = false;
			}
		}
	});
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:28,代码来源:MachineTranslationPreferencePage.java


示例3: validator

import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
 * 访问api以验证 Key是否可用。 ;
 */
private void validator() {
	final String googleKey = googleKeyText.getText();
	BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

		public void run() {
			// TODO Auto-generated method stub
			if (googleKey != null && !googleKey.trim().equals("")) {
				GoogleAPI.setHttpReferrer("http://www.heartsome.net");
				GoogleAPI.setKey(googleKey);
				try {
					String result = Translate.DEFAULT.execute("test", GoogleTransUtils.processLanguage("en-US"),
							GoogleTransUtils.processLanguage("zh-CN"));
					if (result.equals("测试")) {
						state = true;
					}
				} catch (GoogleAPIException e) {
					state = false;
				}
			} else {
				state = false;
			}
		}
	});
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:28,代码来源:GooglePreferencePage.java


示例4: translateString

import com.google.api.GoogleAPI; //导入依赖的package包/类
public String translateString( String source ) {
    String translatedText = "";
    GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
    //Translate.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
    try {
        translatedText = Translate.execute(source, Language.ENGLISH, Language.FRENCH);
    } catch (Exception e) {
        System.err.println( "Exception " + e.getMessage() );
    }
    return removeSpaces ( translatedText );
}
 
开发者ID:dozed,项目名称:align-api-project,代码行数:12,代码来源:RenameThings.java


示例5: googleTranslate

import com.google.api.GoogleAPI; //导入依赖的package包/类
public void googleTranslate() {
    String clientId = googleTranslatePropertyResolver.getProperty("clientId");
    String clientSecret = googleTranslatePropertyResolver.getProperty("clientSecret");

    log.info("googleTranslate.init: {} {}", clientId, clientSecret);

    GoogleAPI.setHttpReferrer(clientId);

    // Set the Google Translate API key
    // See: http://code.google.com/apis/language/translate/v2/getting_started.html
    GoogleAPI.setKey(clientSecret);
}
 
开发者ID:esutoniagodesu,项目名称:egd-web,代码行数:13,代码来源:IntegrationServerConfiguration.java


示例6: translate

import com.google.api.GoogleAPI; //导入依赖的package包/类
public static String translate(String text, Language sourceLang, Language targetLang, boolean markTranslation) {
    String translatedText = null;
    if(text != null && sourceLang != null && targetLang != null) {
        try {
            System.out.println("Google Translating '"+text+"' from '"+sourceLang+"' to '"+targetLang+"'");
            GoogleAPI.setHttpReferrer("http://wandora.org");
            if(apikey == null || apikey.length() == 0) {
                apikey = WandoraOptionPane.showInputDialog(Wandora.getWandora(), "Give your Google Translate API key?", "", "Give your Google Translate API key?");
                if(apikey != null) apikey = apikey.trim();
            }
            if(apikey != null) {
                GoogleAPI.setKey(apikey);
                translatedText = Translate.DEFAULT.execute(text, sourceLang, targetLang);
                if(translatedText != null && translatedText.length() == 0) {
                    translatedText = null;
                }
                if(translatedText != null && markTranslation) {
                    translatedText += " [GOOGLE TRANSLATION]";
                }
            }
        }
        catch(Exception e) {
            Wandora.getWandora().handleError(e);
            //e.printStackTrace();
        }
    }
    return translatedText;
}
 
开发者ID:wandora-team,项目名称:wandora,代码行数:29,代码来源:GoogleTranslateBox.java


示例7: getGoogleTranslation

import com.google.api.GoogleAPI; //导入依赖的package包/类
private String getGoogleTranslation(String text, String originLangStr, String targetLangStr) throws GoogleAPIException {
	
	if (text.equals("") || text.equals(" ")) //avoid empty text
		return "";
	
	//String translatedText;
	String translatedText=text;// + "_" + num_tranlated_characters;
	
	//Check if text is in local dictionary
	if (isInLocalDictionary(text))
		return getLocalTranslation(text);
	
	else if(Parameters.call_online_translator){		
		// Set Google key here
		//GoogleAPI.setHttpReferrer("http://code.google.com/p/google-api-translate-java/");
		//GoogleAPI.setKey("AIzaSyALd_XsjljQ0U0n8SB_3q6Iocc8kPeLsCo"); //api yuan gong
		GoogleAPI.setHttpReferrer("https://code.google.com/p/logmap-matcher/");
		//GoogleAPI.setKey("AIzaSyCXIH0M0Ya4WpnbHYIqNrRC4wXOqtszQuU"); //university of oxford api, max 100,000. Old key
		GoogleAPI.setKey("AIzaSyCOXm6fqYcqJtpFSrlMsgAy1VPkgNcrD2k"); //New key
		
		
		Language originLang = LanguageMap.get(originLangStr);
		Language targetLang = LanguageMap.get(targetLangStr);
		
		num_tranlated_characters+=text.length();
		num_calls++;
		
		LogOutput.printAlways("Translating: '" + text + "' from " + originLangStr + " to " + targetLangStr + " using Google API. Num chars translated so far: " + num_tranlated_characters);
		
		//Google call
		if (!Parameters.is_test_mode_multilingual){
			try{
				translatedText = Translate.DEFAULT.execute(text, originLang, targetLang);
			}
			catch (Exception e){
				LogOutput.printError("Error Translating: '" + text + "' from " + originLangStr + " to " + targetLangStr + " using Google API. " + e.getMessage());
				e.printStackTrace();
				return "";
			}
			//System.out.println(translatedText.length());
		}
		else{ //This is for test only!
			translatedText=text + "_" + num_tranlated_characters + "_g";
		}
		
		
	    //System.out.println(translatedText);
		
		//Store in on-the-fly dictionary
		addTranslation2Map(text, translatedText);		
	}
	
    return translatedText;

}
 
开发者ID:ernestojimenezruiz,项目名称:logmap-matcher,代码行数:56,代码来源:GoogleBasedTranslator.java


示例8: SimpleMatcherGoogleImpl

import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
 * 
 */
public SimpleMatcherGoogleImpl() {
	String googleKey = this.parameters.getGoolgeKey();
	GoogleAPI.setHttpReferrer("http://www.heartsome.net");
	GoogleAPI.setKey(googleKey);
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:9,代码来源:SimpleMatcherGoogleImpl.java


示例9: SimpleMatcherGoogleImpl

import com.google.api.GoogleAPI; //导入依赖的package包/类
/**
 * 
 */
public SimpleMatcherGoogleImpl() {
	String googleKey = this.parameters.getKey();
	GoogleAPI.setHttpReferrer("http://www.heartsome.net");
	GoogleAPI.setKey(googleKey);
}
 
开发者ID:heartsome,项目名称:translationstudio8,代码行数:9,代码来源:SimpleMatcherGoogleImpl.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java StrategyConfig类代码示例发布时间:2022-05-22
下一篇:
Java ScriptAttribute类代码示例发布时间: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