在Amazon Neptune 中使用 SPARQL 1.1 Graph Store HTTP 协议 (GSP) - Amazon Neptune
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

在Amazon Neptune 中使用 SPARQL 1.1 Graph Store HTTP 协议 (GSP)

SPARQL 1.1 Graph Store HTTP 协议建议中,W3C 定义了用于管理 RDF 图表的 HTTP 协议。它定义了删除、创建和替换 RDF 图形内容以及向现有内容添加 RDF 语句的操作。

图形存储协议 (GSP) 提供了一种无需编写复杂的 SPARQL 查询即可操作整个图形的便捷方法。

截至目前发布时间:1.0.5.0 (2021-07-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 建议。但是,该规范未涵盖某些情况。

其中一种情况是,PUTPOST请求在请求正文中指定了一个或多个命名图表,这些图表与请求网址指定的图表不同。只有当请求正文 RDF 格式支持命名图时,才会发生这种情况,例如,使用Content-Type: application/n-quadsContent-Type: application/trig

在这种情况下,Neptune 会添加或更新正文中存在的所有命名图形,以及 URL 中指定的命名图形。

例如,假设您从一个空的数据库开始,发送PUT请求将投票推断为三个图形。其中一个已命名urn:votes,包含所有选举年份的所有选票。另外两个名为urn:votes:2005urn: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 本身中指定了多个图形,使用PUTPOSTGETDELETE。例如:

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 中只能指定一个图形。