【问题标题】:SPARQL INSERT not working with PUT method. why?SPARQL INSERT 不适用于 PUT 方法。为什么?
【发布时间】:2016-04-05 10:59:44
【问题描述】:

我正在尝试使用 PUT 方法创建一个新对象,并使用 SPARQL 查询添加一些我自己的前缀。但是,正在创建的对象没有添加前缀。它适用于 POST 和 PATCH。 SPARQL 为什么以及是否有其他方法可以与 PUT 方法一起使用并使用用户定义的前缀添加?

 PREFIX dc: <http://purl.org/dc/elements/1.1/>
 PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
 PREFIX indexing: <http://fedora.info/definitions/v4/indexing#>

 DELETE { }
 INSERT {
   <> indexing:hasIndexingTransformation "default";
      rdf:type indexing:Indexable;
      dc:title "title3";
      dc:identifier "test:10";
 }
 WHERE { }

我的意思是insert 子句中指定的所有上述值根本没有添加。

编辑1:

url = 'http://example.com/rest/object1'
payload = """
PREFIX dc: <http://purl.org/dc/elements/1.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX indexing: <http://fedora.info/definitions/v4/indexing#>
PREFIX custom: <http://customnamespaces/custom#/>
DELETE { }
INSERT {
<> indexing:hasIndexingTransformation "default"; 
rdf:type indexing:Indexable; 
dc:title "title1";
custom:objState "Active";
custom:ownerId "Owner1";
dc:identifier "object1";
}
WHERE { }
""" 
headers = {
    'content-type': "application/sparql-update",
    'cache-control': "no-cache"
    }
response = requests.request("PUT", url, data=payload, headers=headers, auth=('username','password'))

【问题讨论】:

  • 如果没有别的办法,那我需要分两步来做:1.用PUT创建对象2.用PATCH更新对象
  • 您能否更明确地说明您是如何调用POSTPUT 的?
  • 嗨,Scott,我已经在问题中添加了它。
  • 错误输出是什么样的?你也试过用完整的 URL 替换 qnames 吗?
  • 根本没有错误...像往常一样使用此方法创建对象,但它不包含我在查询中提到的属性。什么是 qnames?

标签: sparql put fedora-commons


【解决方案1】:

前缀不是三元组,因此不能使用 SPARQL 查询添加。您始终可以在 SPARQL 查询中指定前缀,它会生成正确的 URI 用于存储在您的三重存储中。

另请注意,您的 custom 命名空间错误地定义为以哈希和斜杠结尾。它应该是PREFIX custom: &lt;http://customnamespaces/custom#&gt;PREFIX custom: &lt;http://customnamespaces/custom/&gt;

即通过您的查询索引:hasIndexingTransformation 将作为&lt;http://fedora.info/definitions/v4/indexing#hasIndexingTransformation&gt; 存储在三重存储中。

没有理由将前缀存储在三重存储中(实际上,前缀是文本序列化的产物,而不是数据本身),因此您可以随后以两种方式之一查询此数据。

1) 使用前缀

PREFIX indexing: <http://fedora.info/definitions/v4/indexing#>
SELECT ?o {
   [] indexing:hasIndexingTransformation ?o .
}

2) 使用完整的 URI:

SELECT ?o {
   [] <http://fedora.info/definitions/v4/indexing#hasIndexingTransformation> ?o .
}

【讨论】:

  • 嗨,苏格兰人,你误解了我的话。我没有正确放置它们。实际上,我正在尝试创建一个新对象并同时添加自定义属性。它适用于 POST,但不适用于 PUT。
猜你喜欢
  • 1970-01-01
  • 2020-09-25
  • 2015-11-24
  • 1970-01-01
  • 1970-01-01
  • 2023-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多