搭建Jena Fuseki並執行SPARQL查詢

1. 下載Jena Fuseki:http://jena.apache.org/download/index.cgi

2. 運行服務

windows解壓後雙擊fuseki-server.bat
linux解壓後運行命令java

java -jar fuseki-server.jar --update --loc /data/apache-jena-fuseki-3.5.0/run/databases/DB /ds

「–update」表示容許修改;「–loc」後面的參數,表示存放Fuseki數據的文件夾路徑; 「/ds」表示Fuseki服務的名字
程序啓動後默認在3030端口運行,http://localhost:3030linux

3. 導入rdf文件

新建test.rdf,複製如下內容sql

<?xml version="1.0"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#">
  <rdf:Description rdf:about="http://somewhere/MattJones/">
    <vCard:FN>Matt Jones</vCard:FN>
      <vCard:N rdf:parseType="Resource">
        <vCard:Family>Jones</vCard:Family>
        <vCard:Given>Matthew</vCard:Given>
      </vCard:N>
  </rdf:Description>
  <rdf:Description rdf:about="http://somewhere/RebeccaSmith/">
    <vCard:FN>Becky Smith</vCard:FN>
    <vCard:N rdf:parseType="Resource">
      <vCard:Family>Smith</vCard:Family>
      <vCard:Given>Rebecca</vCard:Given>
    </vCard:N>
  </rdf:Description>
  <rdf:Description rdf:about="http://somewhere/JohnSmith/">
    <vCard:FN>John Smith</vCard:FN>
    <vCard:N rdf:parseType="Resource">
      <vCard:Family>Smith</vCard:Family>
      <vCard:Given>Jones</vCard:Given>
    </vCard:N>
  </rdf:Description>
  <rdf:Description rdf:about="http://somewhere/SarahJones/">
    <vCard:FN>Sarah Jones</vCard:FN>
    <vCard:N rdf:parseType="Resource">
      <vCard:Family>Jones</vCard:Family>
      <vCard:Given>Sarah</vCard:Given>
    </vCard:N>
  </rdf:Description>
</rdf:RDF>

在fuseki界面新建database,並導入以上xml,
shell

3. 執行SPARQL查詢

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT ?x

WHERE { ?x  <http://www.w3.org/2001/vcard-rdf/3.0#FN>  "John Smith" }

參考:https://blog.csdn.net/svenhuayuncheng/article/details/78829035apache

相關文章
相關標籤/搜索