簡體   English   中英

具有Fuseki的SPARQL插入不起作用

[英]SPARQL insert with Fuseki not working

我正在使用從Java應用程序嵌入的fuseki:

Dataset ds = DatasetFactory.createTxnMem() ;

FusekiEmbeddedServer server = FusekiEmbeddedServer.create()
        .setPort(3333)
        .add("/ds", ds, true)
        .build() ;
server.start() ;

查詢端點工作正常,我可以執行SELECT請求。 但是,當我要插入值時,它確實返回204 HTTP代碼,但沒有數據添加到圖形中。 這是我所做的:

PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}

<Response [204]>

然后我選擇所有內容以查看是否有效:

SELECT DISTINCT * WHERE {?s ?q ?o}

我得到

<?xml version="1.0"?>
<sparql xmlns="http://www.w3.org/2005/sparql-results#">
  <head>
    <variable name="s"/>
    <variable name="q"/>
    <variable name="o"/>
  </head>
  <results>
  </results>
</sparql>

在客戶端,我有一個基本的python腳本:

port = 3333
test_add = 'PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}'
try :
    print requests.post("http://localhost:"+str(port)+"/ds", data={'update': test_add})
    print urllib2.urlopen("http://localhost:"+str(port)+"/ds?query=SELECT%20DISTINCT%20*%20WHERE%20{?s%20?q%20?o}").read()

except Exception as e :
    print e

這個python腳本現在可以工作了,它已經從下面的答案中改編了。

這可能不是一個很好的答案,而只是告訴您它對我有用。

耶拿·富塞基2.6.0

啟動嵌入式服務器

public class FusekiTestServer {
    public static void main(String[] args) {
        Dataset ds = DatasetFactory.createTxnMem() ;

        FusekiEmbeddedServer server = FusekiEmbeddedServer.create()
                .setPort(3333)
                .add("/ds", ds, true)
                .build() ;
        server.start() ;
    }
}

插入資料

請求

curl --request POST http://localhost:3333/ds --data-urlencode 'update=PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}'

產量

<html>
<head>
</head>
<body>
<h1>Success</h1>
<p>
Update succeeded
</p>
</body>
</html>

查詢數據

請求

curl --request GET http://localhost:3333/ds --data-urlencode 'query=SELECT DISTINCT * WHERE {?s ?q ?o}'

產量

<http://example/book3>
        <http://purl.org/dc/elements/1.1/title>
                "A new book" .

診斷

我不是Python專家,但是由於它是POST請求,因此不應該將查詢字符串放入數據數組中嗎? 就像是

requests.post("http://localhost:"+str(port)+"/ds, data={'update': 'PREFIX dc: <http://purl.org/dc/elements/1.1/>INSERT DATA{ <http://example/book3> dc:title "A new book"}'})

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM