我使用定式從Java應用程序內嵌:SPARQL插入與定式不工作
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腳本現在可以工作,它已經根據下面的答案進行了改編。
請問您可以展示客戶端代碼進行操作嗎? – AndyS
這只是一個非常基本的Python腳本(我將它添加到問題中)。我在test_add變量中測試了幾個東西 – Yotm
您可以嘗試在沒有布爾參數的情況下創建服務器嗎?也許它只能通過HTTP進行讀取。 – AKSW