/*
* This example shows how to use Java to build http connection and request
* the ltp-cloud service for perform full-stack Chinese language analysis
* and get results in specified formats
*/
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class SimpleAPI{
public static void main(String[] args) throws IOException {
/*if (args.length < 1 || !(args[0].equals("xml")
|| args[0].equals("json")
|| args[0].equals("conll"))) {
System.out.println("Usage: java SimpleAPI [xml/json/conll]");
return;
}*/
String api_key = "your apikey";
String pattern = "ws";
String format = "plain";
String text = "分词做了两个月,LTP终于搞定了。我真的很高兴,来不及等待就在测试LTP的稳定性。看来他会吧不同的句子分成不同的段落。也许句子的长短对LTP的分析并没有太大的影响。网络的速度也许会影响LTP分词的使用。但是,在分词的具体实施中,我应该不能直接将一个长长的文章读入网络,实践时再说咯。";
text = URLEncoder.encode(text, "utf-8");
//
URL url = new URL("http://api.ltp-cloud.com/analysis/?"
+ "api_key=" + api_key + "&"
+ "text=" + text + "&"
+ "format=" + format + "&"
+ "pattern=" + pattern);
URLConnection conn = url.openConnection();
conn.connect();
BufferedReader innet = new BufferedReader(new InputStreamReader(
conn.getInputStream(),
"utf-8"));
String line;
while ((line = innet.readLine())!= null) {
System.out.println(line);
}
innet.close();
}
}