本文整理汇总了Java中com.memetix.mst.language.Language类的典型用法代码示例。如果您正苦于以下问题:Java Language类的具体用法?Java Language怎么用?Java Language使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Language类属于com.memetix.mst.language包,在下文中一共展示了Language类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toLanguage
import com.memetix.mst.language.Language; //导入依赖的package包/类
/**
* Convert the given name of a natural language into a Language from the enum of Languages
* supported by this translation service.
*
* @param languageName The name of the language, for example, "English"
* @return code representing this language, for example, "en", for this translation API
* @throws IllegalArgumentException
*/
public static String toLanguage(String languageName) throws IllegalArgumentException {
// Convert string to all caps
String standardizedName = languageName.toUpperCase();
// Replace spaces with underscores
standardizedName = standardizedName.replace(' ', '_');
// Remove parentheses
standardizedName = standardizedName.replace("(", "");
standardizedName = standardizedName.replace(")", "");
// Map Norwegian-Bokmal to Norwegian
if (standardizedName.equals("NORWEGIAN_BOKMAL")) {
standardizedName = "NORWEGIAN";
}
try {
return Language.valueOf(standardizedName).toString();
} catch (IllegalArgumentException e) {
Log.e(TAG, "Not found--returning default language code");
return CaptureActivity.DEFAULT_TARGET_LANGUAGE_CODE;
}
}
示例2: main
import com.memetix.mst.language.Language; //导入依赖的package包/类
/**
* @param args the command line arguments
* 1st parameter is name of the file(path inclusive) to be translated
* 2nd parameter is the language the file should be translated into
*/
public static void main(String[] args) {
try {
Language languageToBeTranslatedInto = Language.ENGLISH;
if(args[1].toLowerCase().contains("fr")){
languageToBeTranslatedInto = Language.FRENCH;
}else if(args[1].toLowerCase().contains("es")){
languageToBeTranslatedInto = Language.SPANISH;
}else if(args[1].toLowerCase().contains("de")){
languageToBeTranslatedInto = Language.GERMAN;
}else if(args[1].toLowerCase().contains("pt")){
languageToBeTranslatedInto = Language.PORTUGUESE;
}
new FileManager().translateFile(args[0],languageToBeTranslatedInto);
} catch (IOException ex) {
Logger.getLogger(Translator.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例3: processLanguage
import com.memetix.mst.language.Language; //导入依赖的package包/类
/** 处理语言 */
public static Language processLanguage(String hsLanguageCode) {
// 由于中文前缀一样,需针对中文特殊处理。
if (hsLanguageCode.equalsIgnoreCase("zh-CN")) {
return Language.CHINESE_SIMPLIFIED;
}
if (hsLanguageCode.equalsIgnoreCase("zh-TW") || hsLanguageCode.equalsIgnoreCase("zh-HK")) {
return Language.CHINESE_TRADITIONAL;
}
Language[] supportedLangs = Language.values();
for (Language lang : supportedLangs) {
String code = lang.toString();
if (code.equals("")) {
continue;
}
if (hsLanguageCode.startsWith(code) || code.startsWith(hsLanguageCode)) {
return lang;
}
}
return null;
}
示例4: getTargetLanguages
import com.memetix.mst.language.Language; //导入依赖的package包/类
public Collection<Language> getTargetLanguages() {
int[] iis = targetList.getSelectedIndices();
Collection<Language> languages = new ArrayList<Language>();
if(allLanguagesCheckBox.isSelected()) {
for(int i=0; i<iis.length; i++) {
languages.add(langs[iis[i]]);
}
}
else {
for(int i=0; i<iis.length; i++) {
languages.add(someLangs[iis[i]]);
}
}
targets = languages.toArray( new Language[] {} );
return languages;
}
示例5: translate
import com.memetix.mst.language.Language; //导入依赖的package包/类
public static String translate(String text, Topic sourceLangTopic, Topic targetLangTopic, boolean markTranslation) {
try {
String sourceLangStr = LanguageBox.getCodeForLangTopic(sourceLangTopic);
String targetLangStr = LanguageBox.getCodeForLangTopic(targetLangTopic);
if(sourceLangStr != null && targetLangStr != null) {
Language sourceLang = Language.fromString(sourceLangStr);
Language targetLang = Language.fromString(targetLangStr);
if(sourceLang != null && targetLang != null) {
return translate(text, sourceLang, targetLang, markTranslation);
}
}
}
catch(Exception e) {
e.printStackTrace();
}
return null;
}
示例6: translateTextArrays
import com.memetix.mst.language.Language; //导入依赖的package包/类
public String[] translateTextArrays(String[] sourceTexts, Language from, Language to) {
// Set your Windows Azure Marketplace client info - See http://msdn.microsoft.com/en-us/library/hh454950.aspx
//Translate.setClientId("thisisinsaneineedtogeneratemyownclientid");
//Translate.setClientSecret("81+DZxvj/VGO4gPlfYpKSrbBHLdyB4F7BXGq++ttI9I=");
Translate.setClientId(azureClientID);
Translate.setClientSecret(azureClientSecret);
// Call the translate.execute method, passing an array of source texts
String[] translatedTexts;
try {
translatedTexts = Translate.execute(sourceTexts, from, to);
// System.out.println("Translation Successful");
} catch (Exception e) {
translatedTexts = null;
System.out.println(e.getMessage());
}
return translatedTexts;
}
示例7: index
import com.memetix.mst.language.Language; //导入依赖的package包/类
/**
* Indexes the CLEF2011 collection.
*/
public void index() {
// measuring index time
Date start = new Date();
// create indexers
CLEF2011WikiDocIndexer clef2011WikiDocIndexer = new CLEF2011WikiDocIndexer(configManager);
CLEF2011WikiMetaIndexer clef2011WikiMetaIndexer = new CLEF2011WikiMetaIndexer(configManager);
// Creates or updated Wikipedia Document Index
System.out.println("1) Building/Updating Wiki document index");
clef2011WikiDocIndexer.index(System.getProperty(ConfigConstants.WIKI_DOC_DIR), System.getProperty(ConfigConstants.WIKI_DOC_INDEXDIR));
// Creates or updates Wikipedia Meta Information Index
System.out.println("2) Building/Updating Wiki meta index");
clef2011WikiMetaIndexer.index(System.getProperty(ConfigConstants.WIKI_META_DIR), Language.ENGLISH);
// time stamping
Date end = new Date();
System.out.println("CLEF2011Manager: Total index time: " + (end.getTime() - start.getTime()) + " ms");
}
示例8: translateString
import com.memetix.mst.language.Language; //导入依赖的package包/类
/**
* Translates text conditionally.
*
* @param destinationLanguage The language to which should be translated (e.g. Language.ENGLISH).
* @param toText Text to which should be translated. This might be empty but also may contain for text
* already, in which case no translation will be performed and the text will be returned directly.
* @param fromTexts An array of Strings with source texts. The array is prioritized in order of
* translation quality. This means that the first item in the String array is the most fit text
* for the translation. Only and only if this text is an empty string, the method tries to
* translate the second entry of the array. If this one is also empty, it continues with the third
* entry, and so on until the end of the array is reached or a translation has been successful
* before. If all texts were empty Strings, no translation is performed and the method returns
* and empty String.
* @return the translated String or an empty String if no translation was possible
*/
public String translateString(Language destinationLanguage, String toText, String[] fromTexts) {
// check if translation already exists
if (toText.length() > 0) {
return toText;
}
for (String fromText : fromTexts) {
if (fromText.length() > 0) {
countTranslate++;
return BingLanguageTranslator.translate(fromText, null, destinationLanguage);
}
}
// no result is an empty String
return "";
}
示例9: translate
import com.memetix.mst.language.Language; //导入依赖的package包/类
/**
* Translates text conditionally.
*
* @param texts An array of Strings with source texts. The array is prioritized in order of translation quality. This means that the
* first item in the String array is the most fit text for the translation. Only and only if this text is an empty string,
* the method tries to translate the second entry of the array. If this one is also empty, it continues with the third entry,
* and so on until the end of the array is reached or a translation has been successful before. If all texts were empty
* Strings, no translation is performed and the method returns and empty String.
* @param to The language to which should be translated (e.g. Language.ENGLISH).
* @param resultText Result of the translation. The translation will only be performed if the result text is empty. If the result text
* is already available, no translation will be performed and the result text will be returned directly.
* @return the translated String or an empty String if no translation was possible
*/
public String translate(String[] texts, Language from, Language to, String resultText) {
// check if translation already exists.
if (resultText.length() > 0) {
return resultText;
}
// translate the first text you find in the array
for (String fromText : texts) {
if (fromText.length() > 0) {
return BingLanguageTranslator.translate(fromText, null, to);
}
}
// no result is an empty String
return "";
}
示例10: doInBackground
import com.memetix.mst.language.Language; //导入依赖的package包/类
@Override
protected Object doInBackground(Object... words) {
String word = (String) words[0];
try {
System.out.println("WORDTASK: .................................................."+word);
String translatedText = Translate.execute(word, Language.ENGLISH, Language.FINNISH);
System.out.println(translatedText);
return translatedText;
} catch (Exception e) {
//e.printStackTrace();
System.out.println(e.getCause());
return null;
}
}
示例11: BingTranslate
import com.memetix.mst.language.Language; //导入依赖的package包/类
public BingTranslate(Language from, Language to) {
// 获取源语言
SRCLANGUAGE = from;
// 获取目标语言
TARGETLANGUAGE = to;
// 设置翻译api的用户id
Translate.setClientId("20000227");
// 设置翻译api的用户密钥
Translate.setClientSecret("bvgP0SOFq1up2Elv2I8QI1Yuhdb0GZlQ82mS0cDohgM=");
Translate.setHttpReferrer("https://datamarket.azure.com/developer/applications");
}
示例12: translate
import com.memetix.mst.language.Language; //导入依赖的package包/类
/**
* Translate using Microsoft Translate API
*
* @param sourceLanguageCode Source language code, for example, "en"
* @param targetLanguageCode Target language code, for example, "es"
* @param sourceText Text to send for translation
* @return Translated text
*/
static String translate(String sourceLanguageCode, String targetLanguageCode, String sourceText) {
Translate.setClientId(CLIENT_ID);
Translate.setClientSecret(CLIENT_SECRET);
try {
Log.d(TAG, sourceLanguageCode + " -> " + targetLanguageCode);
return Translate.execute(sourceText, Language.fromString(sourceLanguageCode),
Language.fromString(targetLanguageCode));
} catch (Exception e) {
Log.e(TAG, "Caught exeption in translation request.");
e.printStackTrace();
return Translator.BAD_TRANSLATION_MSG;
}
}
示例13: doTranslation
import com.memetix.mst.language.Language; //导入依赖的package包/类
/**
*
*/
public String doTranslation(String text,String fromLang,String toLang) {
String response = text;
try {
response = new String(Translate.execute(text,Language.fromString(fromLang), Language.fromString(toLang)).getBytes("UTF-8"),
java.nio.charset.Charset.forName("UTF-8"));
} catch(Exception ex) {
HelperFunctions.writeInformationIntoFile("Translation exception . Reason :" + ex.getMessage() + " " );
HelperFunctions.writeInformationIntoFile("Original string returned as translationn !! ");
}
return response;
}
示例14: t
import com.memetix.mst.language.Language; //导入依赖的package包/类
public static String t(String args) throws Exception {
// Set your Windows Azure Marketplace client info - See http://msdn.microsoft.com/en-us/library/hh454950.aspx
Translate.setClientId("9cf63463-28b0-49d9-9649-a71bd3a983c3");
Translate.setClientSecret("sZE0BqM84VSU4QLpmGSTuEe2RMw4Sr9n1rnOwojEcJo");
String translatedText = Translate.execute(args, Language.ENGLISH, Language.CHINESE_SIMPLIFIED);
return translatedText;
}
示例15: translate
import com.memetix.mst.language.Language; //导入依赖的package包/类
public static String translate(String from, String to, String string) {
try {
Language lfrom = Language.fromString(from);
Language lto = Language.fromString(to);
log.debug("translate: {}, {}, {}", string, lfrom, lto);
return Translate.execute(string, lfrom, lto);
} catch (Exception e) {
log.error("translate: ", e.getMessage(), e);
return null;
}
}