gStore/Server/web/api.html

116 lines
4.9 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!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>
&nbsp;&nbsp; public static void main(String[] args)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp; <b>// 初始化ip地址和端口</b><br>
&nbsp;&nbsp; <b>// NOTICE: IP地址和端口由用户自定义其中IP地址也可用对应的域名形式</b><br>
&nbsp;&nbsp; <b>// 如GstoreConnector gc = new GstoreConnector("tourist.gstore-pku.com", 80);</b><br>
&nbsp;&nbsp; GstoreConnector gc = new GstoreConnector("127.0.0.1",80);<br>
&nbsp;&nbsp; <b>// 查询语句</b><br>
&nbsp;&nbsp; String sparql = "select ?x where "<br>
&nbsp;&nbsp; + "{" <br>
&nbsp;&nbsp; + "?x &lt;rdf:type &gt; &lt; ub:UndergraduateStudent &gt;. "<br>
&nbsp;&nbsp; + "?y &lt; ub:name &gt; &lt; Course1 &gt;." <br>
&nbsp;&nbsp; + "?x &lt; ub:takesCourse &gt; ?y." <br>
&nbsp;&nbsp; + "?z &lt; ub:teacherOf &gt; ?y." <br>
&nbsp;&nbsp; + "?z &lt; ub:name &gt; &lt; FullProfessor1 &gt;." <br>
&nbsp;&nbsp; + "?z &lt; ub:worksFor &gt; ?w." <br>
&nbsp;&nbsp; + "?w &lt; ub:name &gt; &lt; Department0 &gt;." <br>
&nbsp;&nbsp; + "}";<br>
&nbsp;&nbsp; <b>//执行查询</b><br>
&nbsp;&nbsp; String answer = gc.query(sparql);<br>
&nbsp;&nbsp; System.out.println(answer);<br>
&nbsp;&nbsp; }<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>&nbsp;&nbsp;&nbsp;build, load, unload, query, monitor, show, checkpoint</li>
<li><b>db_name:</b>&nbsp;&nbsp;&nbsp;the name of database, for example: lubm</li>
<li><b>ds_path:</b>&nbsp;&nbsp;&nbsp;dataset path in the server, for example: /home/data/test.n3</li>
<li><b>format:</b>&nbsp;&nbsp;&nbsp;html, json, txt, csv</li>
<li><b>sparql:</b>&nbsp;&nbsp;&nbsp;select ?s where { ?s ?p ?o.}</li>
</ul>
</ul>
<ul>
<li><b>to build a database from a dataset:</b>&nbsp;&nbsp;&nbsp; http://localhost:9000/?operation=build&db_name=[db_name]&ds_path=[ds_path]</li>
<li><b>to load a database:</b>&nbsp;&nbsp;&nbsp; http://localhost:9000/?operation=load&db_name=[db_name]</li>
<li><b>to unload a database:</b>&nbsp;&nbsp;&nbsp; http://localhost:9000/?operation=unload&db_name=[db_name]</li>
<li><b>to query a database:</b>&nbsp;&nbsp;&nbsp; http://localhost:9000/?operation=query&format=[format]&sparql=[sparql]</li>
<li><b>to monitor the server:</b>&nbsp;&nbsp;&nbsp; http://localhost:9000/?operation=monitor</li>
<li><b>to show the database used:</b>&nbsp;&nbsp;&nbsp; http://dlocalhost:9000/?operation=show</li>
<li><b>to save the database currently:</b>&nbsp;&nbsp;&nbsp; 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 &copy; 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>