本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
在 Amazon Neptune 中使用 SPARQL 1.1 圖形存放區 HTTP 通訊協定 (GSP)
在 SPARQL 1.1 圖形存放區 HTTP 通訊協定
圖形存放區通訊協定 (GSP) 提供了一種便利的方式來操作您的整個圖形,而不必撰寫複雜的 SPARQL 查詢。
從 版本:1.0.5.0 (2021 年 7 月 27 日) 開始,Neptune 完全支援此通訊協定。
圖形存放區通訊協定 (GSP) 的端點為:
https://
your-neptune-cluster
:port
/sparql/gsp/
若要使用 GSP 存取預設圖形,請使用:
https://
your-neptune-cluster
:port
/sparql/gsp/?default
若要使用 GSP 存取具名圖形,請使用:
https://
your-neptune-cluster
:port
/sparql/gsp/?graph=named-graph-URI
Neptune GSP 實作的特殊詳細資訊
Neptune 完全實作了定義 GSP 的 W3C 建議
其中一種情況是,PUT
或 POST
請求在請求內文中指定一個或多個具名圖形,這些圖形與請求 URL 指定的圖形不同。僅在請求內文 RDF 格式支援具名圖形時,才可能發生這種情況,例如,使用 Content-Type: application/n-quads
或 Content-Type:
application/trig
。
在此情況下,Neptune 會新增或更新內文中存在的所有具名圖形,以及在 URL 中指定的具名圖形。
例如,假設從空白資料庫開始,您會傳送 PUT
請求,以將選票 upsert 至三個圖形。其中一個名為 urn:votes
,包含來自所有選舉年的所有選票。另外兩個名為 urn:votes:2005
和 urn:votes:2019
,包含來自特定選舉年的選票. 請求及其承載看起來像這樣:
PUT "http://
your-Neptune-cluster
:port
/sparql/gsp/?graph=urn:votes" Host: example.com Content-Type: application/n-quads PAYLOAD: <urn:JohnDoe> <urn:votedFor> <urn:Labour> <urn:votes:2005> <urn:JohnDoe> <urn:votedFor> <urn:Conservative> <urn:votes:2019> <urn:JaneSmith> <urn:votedFor> <urn:LiberalDemocrats> <urn:votes:2005> <urn:JaneSmith> <urn:votedFor> <urn:Conservative> <urn:votes:2019>
在執行請求之後,資料庫中的資料看起來像這樣:
<urn:JohnDoe> <urn:votedFor> <urn:Labour> <urn:votes:2005> <urn:JohnDoe> <urn:votedFor> <urn:Conservative> <urn:votes:2019> <urn:JaneSmith> <urn:votedFor> <urn:LiberalDemocrats> <urn:votes:2005> <urn:JaneSmith> <urn:votedFor> <urn:Conservative> <urn:votes:2019> <urn:JohnDoe> <urn:votedFor> <urn:Labour> <urn:votes> <urn:JohnDoe> <urn:votedFor> <urn:Conservative> <urn:votes> <urn:JaneSmith> <urn:votedFor> <urn:LiberalDemocrats> <urn:votes> <urn:JaneSmith> <urn:votedFor> <urn:Conservative> <urn:votes>
另一個不明確的情況是,在請求 URL 本身中使用任一 PUT
、POST
、GET
或 DELETE
指定多個圖形 例如:
POST "http://
your-Neptune-cluster
:port
/sparql/gsp/?graph=urn:votes:2005&graph=urn:votes:2019"
或者:
GET "http://
your-Neptune-cluster
:port
/sparql/gsp/?default&graph=urn:votes:2019"
在此情況下,Neptune 會傳回 HTTP 400,其中訊息指出只能在請求 URL 中指定一個圖形。