java调用microsoft translate api webservice

想做个东西简体转繁体,找到微软的API可用:
http://msdn.microsoft.com/en-us/library/ff512423.aspx

感觉这个要比GOOGLE的好,因为微软的接口会将一些词汇差异也体现出来,比如"服务器"转换为"伺服器","软件"转换为"软体".


package test;

import javax.xml.namespace.QName;

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

public class Test {
public static void main(String[] args) throws Exception{

//message to be translated
String str = "服务器硬盘软件数据库程序设计";


String method = "Translate";
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL("http://api.microsofttranslator.com/V2/Soap.svc"));
call.setOperationName(new QName("http://api.microsofttranslator.com/V2",method));

call.addParameter(new QName("http://api.microsofttranslator.com/V2","appId"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName("http://api.microsofttranslator.com/V2","text"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName("http://api.microsofttranslator.com/V2","from"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);
call.addParameter(new QName("http://api.microsofttranslator.com/V2","to"), org.apache.axis.encoding.XMLType.XSD_STRING, javax.xml.rpc.ParameterMode.IN);


call.setUseSOAPAction(true);
call.setReturnType(org.apache.axis.encoding.XMLType.SOAP_STRING);
call.setSOAPActionURI("http://api.microsofttranslator.com/V2/LanguageService/Translate");

String result = (String)call.invoke(new Object[]{"YOUR APPID HERE",str,"zh-CHS","zh-CHT"});

//result
System.out.println(result);
}
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值