了解更多关于API的用法

REST API示例

// 初始化IP地址和端口
// NOTICE: IP地址和端口由用户自定义,其中IP地址也可用对应的域名形式
// 如:String url = "http://" + "tourist.gstore-pku.com" + ":" + "80";
String url = "http://" + "127.0.0.1" + ":" + "9000";
StringBuffer result = new StringBuffer();
BufferedReader in = null;
String param = "?operation=load&db_name=lubm";
String urlNameString = url + "/" + URLEncoder.encode(param, "UTF-8");
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map> map = connection.getHeaderFields();
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result.append(line);
}
}

Java API示例

import jgsc.GstoreConnector;
public class JavaAPIExample
{
   public static void main(String[] args)
   {
   // 初始化ip地址和端口
   // NOTICE: IP地址和端口由用户自定义,其中IP地址也可用对应的域名形式
   // 如:GstoreConnector gc = new GstoreConnector("tourist.gstore-pku.com", 80);
   GstoreConnector gc = new GstoreConnector("127.0.0.1",80);
   // 查询语句
   String sparql = "select ?x where "
   + "{"
   + "?x <rdf:type > < ub:UndergraduateStudent >. "
   + "?y < ub:name > < Course1 >."
   + "?x < ub:takesCourse > ?y."
   + "?z < ub:teacherOf > ?y."
   + "?z < ub:name > < FullProfessor1 >."
   + "?z < ub:worksFor > ?w."
   + "?w < ub:name > < Department0 >."
   + "}";
   //执行查询
   String answer = gc.query(sparql);
   System.out.println(answer);
   }
}

URL规范

URL rules: operation, db_name, ds_path, format, sparql

NOTICE: do URL encoding before sending it to database server