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

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

在 Amazon Neptune 中使用 SPARQL 1.1 图形存储 HTTP 协议 (GSP)

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

图形存储协议 (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 建议。但是,此规范没有涵盖某些情况。

其中一种情况是,PUTPOST 请求在请求正文中指定了一个或多个命名图形,这些图形与由请求 URL 指定的图形不同。只有当请求正文 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>

另一种模棱两可的情况是,使用 PUTPOSTGETDELETE 中的任何一个操作在请求 URL 本身中指定多个图形。例如:

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