116 lines
4.9 KiB
HTML
116 lines
4.9 KiB
HTML
<!DOCTYPE html>
|
||
<html lang="zh-cn">
|
||
<head>
|
||
<meta charset="UTF-8"/>
|
||
<title>API</title>
|
||
</head>
|
||
<!--<body style="font-family: 'Arial','Microsoft YaHei','黑体','宋体',sansserif;">-->
|
||
<body style="font-family: Helvetica, 'Hiragino Sans GB', 'Microsoft Yahei', '微软雅黑', Arial, sans-serif;">
|
||
<div style="align:center:">
|
||
<img src="logo.png" height="60px" />
|
||
</div>
|
||
<!--
|
||
<h1 style="color: rgb(0, 0, 153);">API</h1>
|
||
-->
|
||
<a href="https://github.com/Caesar11/gStore/blob/master/docs/API.md">了解更多关于API的用法</a>
|
||
<h2>REST API示例</h2>
|
||
<p>
|
||
<b>// 初始化IP地址和端口</b><br>
|
||
<b>// NOTICE: IP地址和端口由用户自定义,其中IP地址也可用对应的域名形式</b><br>
|
||
<b>// 如:String url = "http://" + "tourist.gstore-pku.com" + ":" + "80";</b><br>
|
||
String url = "http://" + "127.0.0.1" + ":" + "9000";<br>
|
||
StringBuffer result = new StringBuffer();<br>
|
||
BufferedReader in = null;<br>
|
||
String param = "?operation=load&db_name=lubm";<br>
|
||
String urlNameString = url + "/" + URLEncoder.encode(param, "UTF-8");<br>
|
||
URL realUrl = new URL(urlNameString);<br>
|
||
<b>// 打开和URL之间的连接</b><br>
|
||
URLConnection connection = realUrl.openConnection();<br>
|
||
<b>// 设置通用的请求属性</b><br>
|
||
connection.setRequestProperty("accept", "*/*");<br>
|
||
connection.setRequestProperty("connection", "Keep-Alive");<br>
|
||
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");<br>
|
||
<b>// 建立实际的连接</b><br>
|
||
connection.connect();<br>
|
||
<b>// 获取所有响应头字段</b><br>
|
||
Map<String, List<String>> map = connection.getHeaderFields();<br>
|
||
<b>// 定义 BufferedReader输入流来读取URL的响应</b><br>
|
||
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));<br>
|
||
String line;<br>
|
||
while ((line = in.readLine()) != null) {<br>
|
||
result.append(line);<br>
|
||
}<br>
|
||
}<br>
|
||
<h2>Java API示例</h2>
|
||
<p>
|
||
import jgsc.GstoreConnector;<br>
|
||
public class JavaAPIExample<br>
|
||
{<br>
|
||
public static void main(String[] args)<br>
|
||
{<br>
|
||
<b>// 初始化ip地址和端口</b><br>
|
||
<b>// NOTICE: IP地址和端口由用户自定义,其中IP地址也可用对应的域名形式</b><br>
|
||
<b>// 如:GstoreConnector gc = new GstoreConnector("tourist.gstore-pku.com", 80);</b><br>
|
||
GstoreConnector gc = new GstoreConnector("127.0.0.1",80);<br>
|
||
<b>// 查询语句</b><br>
|
||
String sparql = "select ?x where "<br>
|
||
+ "{" <br>
|
||
+ "?x <rdf:type > < ub:UndergraduateStudent >. "<br>
|
||
+ "?y < ub:name > < Course1 >." <br>
|
||
+ "?x < ub:takesCourse > ?y." <br>
|
||
+ "?z < ub:teacherOf > ?y." <br>
|
||
+ "?z < ub:name > < FullProfessor1 >." <br>
|
||
+ "?z < ub:worksFor > ?w." <br>
|
||
+ "?w < ub:name > < Department0 >." <br>
|
||
+ "}";<br>
|
||
<b>//执行查询</b><br>
|
||
String answer = gc.query(sparql);<br>
|
||
System.out.println(answer);<br>
|
||
}<br>
|
||
}<br>
|
||
<h2>URL规范</h2>
|
||
<p>
|
||
URL rules: operation, db_name, ds_path, format, sparql<br>
|
||
<br>
|
||
<b>NOTICE:</b> do URL encoding before sending it to database server<br>
|
||
<ul>
|
||
<li><b>operation:</b> build, load, unload, query, monitor, show, checkpoint</li>
|
||
<li><b>db_name:</b> the name of database, for example: lubm</li>
|
||
<li><b>ds_path:</b> dataset path in the server, for example: /home/data/test.n3</li>
|
||
<li><b>format:</b> html, json, txt, csv</li>
|
||
<li><b>sparql:</b> select ?s where { ?s ?p ?o.}</li>
|
||
</ul>
|
||
</ul>
|
||
<ul>
|
||
<li><b>to build a database from a dataset:</b> http://localhost:9000/?operation=build&db_name=[db_name]&ds_path=[ds_path]</li>
|
||
<li><b>to load a database:</b> http://localhost:9000/?operation=load&db_name=[db_name]</li>
|
||
<li><b>to unload a database:</b> http://localhost:9000/?operation=unload&db_name=[db_name]</li>
|
||
<li><b>to query a database:</b> http://localhost:9000/?operation=query&format=[format]&sparql=[sparql]</li>
|
||
<li><b>to monitor the server:</b> http://localhost:9000/?operation=monitor</li>
|
||
<li><b>to show the database used:</b> http://dlocalhost:9000/?operation=show</li>
|
||
<li><b>to save the database currently:</b> http://localhost:9000/?operation=checkpoint</li>
|
||
</ul>
|
||
<br>
|
||
<div id="footer" style="color:#080808; font-size:small; text-align:center;">
|
||
<div id="support">Supported by <a href="http://www.gstore-pku.com" style="color:#1435E9">gStore</a></div>
|
||
<div id="copyright">Copyright © 2017 <a href="http://www.icst.pku.edu.cn/db/zh/index.php/%E9%A6%96%E9%A1%B5" style="color:#1435E9">Data Management Lab, Institute of Computer Science & Technology of Peking University</a></div>
|
||
</div>
|
||
</body>
|
||
</html>
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|