IRI 在发布到 Neptune 服务器上的 SparQL 客户端时包含未编码的 space 错误

IRI included an unencoded space Error when posted to SparQL Client on Neptune Server

我在向我的 SPARQL 客户端端点发出 POST 请求时收到以下错误:

Malformed query: org.openrdf.rio.RDFParseException: IRI included an unencoded space: '32' [line 1]

我正在使用 Postman 发出请求并设置了一个 header,即 Content-Type 并且值为 sparql-update.

我在 body 中传递的数据是这样的:

insert data { <rdf:RDF xmlns:html="http://www.w3.org/1999/xhtml"
         xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
         xmlns:country="http://example.xyz.ds/country/"
         xmlns:currency="http://example.xyz.ds/currency/"
         xmlns:area="http://example.xyz.ds/area/"
         xmlns:city="http://example.xyz.ds/city/"
         xmlns:root="http://example.xyz.ds/terms#"
         xmlns:specialIdenifier="http://example.xyz.ds/specialIdenifier/"
         xmlns:product="http://example.xyz.ds/product/"
         xmlns:company="http://example.xyz.ds/company/"
         xmlns:office="http://example.xyz.ds/office/"
         xmlns:schema="http://schema.org/"
         xmlns:uuid="java:java.util.UUID"
         xmlns:acmUtil="http://example.xyz.ds/util-functions">
    <rdf:Description rdf:about="http://example.xyz.ds/company/123456789>
        <rdf:type rdf:resource="http://example.xyz.ds/terms#company"/>
        <rdfs:label/>
        <root:fid xmlns:urn="urn:"
                  xmlns:func="http://example.xyz.ds/func"
                  rdf:datatype="http://www.w3.org/2001/XMLSchema#string">4049</root:fid>
        <root:deleted xmlns:urn="urn:"
                      xmlns:func="http://example.xyz.ds/func"
                      rdf:datatype="http://www.w3.org/2001/XMLSchema#boolean">false</root:deleted>
    </rdf:Description>
</rdf:RDF> }

我希望我可以 POST body 中的整个 RDF XML 文档和 SPARQL client/Neptune 数据库将只理解其中的三元组。

我在网上看到很多关于此错误的信息,但找不到与直接 POSTing 数据相关的解决方案。知道如何解决这个问题吗?

如评论中所述,您的 SPARQL 命令在语法上无效:您不能只将 RDF/XML 文档粘贴到 SPARQL INSERT DATA 命令中(请参阅 SPARQL Update specification有关正确语法的详细信息)。

I am hoping that I can just POST this entire RDF XML document in the body and the SPARQL client/Neptune database will just understand the triples within it.

不幸的是,Neptune 对此没有选择(至少,据我从 Neptune 文档中可以看出)。

您可以使用 UPDATE LOAD 命令将 RDF/XML 文档上传到 Neptune,如 Neptune documentation 所示。如果这不适合您,您将需要转换文档中的数据以某种方式更正 SPARQL 语法。

有几种方法可以做到这一点,但如果您在 Java 中工作,一种可能的选择是使用 rdf4j 存储库 API。您可以使用 SPARQLRepository class 连接到 Neptune 实例的 SPARQL 端点,如下所示:

Repository rep = new SPARQLRepository("https://your-neptune-endpoint:port/sparql");
rep.init();

然后您可以打开一个连接并以这种方式加载您的文件:

try(RepositoryConnection conn = rep.getConnection()) {
      File file = new File("/my/local/rdf-xml-file.rdf");
      conn.add(file, "", RDFFormat.RDFXML);
}

Rdf4j 会负责将您的命令转换为 Neptune 服务器可以理解的 SPARQL 更新请求(小警告:我自己还没有用 Neptune 对此进行测试,但如果它符合 SPARQL W3C 建议,这应该工作)。