com.hn.translation.impl.OmiTranslator Maven / Gradle / Ivy
package com.hn.translation.impl;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.hn.translation.AbstractOnlineTranslator;
import com.hn.translation.LANG;
import com.hn.translation.annotation.TranslatorComponent;
import java.util.HashMap;
import java.util.Map;
@TranslatorComponent(id="omi")
public final class OmiTranslator
extends AbstractOnlineTranslator
{
public OmiTranslator()
{
this.langMap.put(LANG.EN, "e");
this.langMap.put(LANG.ZH, "c");
}
public String getResponse(LANG from, LANG targ, String query)
throws Exception
{
Map params = new HashMap();
params.put("languageType",this.langMap.get(from) + "2" + this.langMap.get(targ));
params.put("userDbName", "");
params.put("sentsToTrans", query);
return HttpUtil.get("http://www.alifanyi1688.com/transSents.do",params);
}
protected String parseString(String jsonString)
{
JSONObject jsonObject = JSONUtil.parseObj(jsonString);
JSONArray segments = jsonObject.getJSONArray("sentsResults").getJSONArray(1);
StringBuilder result = new StringBuilder();
for (int i = 0; i < segments.size(); i++) {
result.append(segments.getStr(i));
}
return result.toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy