SPARQL INSERT 不适用于 PUT 方法.为什么? [英] SPARQL INSERT not working with PUT method. why?

查看:63
本文介绍了SPARQL INSERT 不适用于 PUT 方法.为什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to create a new object with PUT method and to add some of my own prefixes with SPARQL query. But, the object is being created without the added prefixes. It works with POST and PATCH though. Why and is there alternative way for SPARQL to use with PUT method and add using user-defined prefixes?

 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 子句中指定的所有上述值都没有添加.

What I am saying was all the above values specified in the insert clause are not added at all.

编辑 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'))

推荐答案

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

Prefixes are not triples and therefore cannot be added using a SPARQL query. You can always specify prefixes in the SPARQL query and it will generate the correct URI for storage in your triple store.

另请注意,您的 custom 命名空间被错误地定义为以散列和斜杠结尾.它应该是 PREFIX custom: PREFIX custom: .

Also note that your custom namespace is errantly defined by ending with both a hash and a slash. It should be either PREFIX custom: <http://customnamespaces/custom#> or PREFIX custom: <http://customnamespaces/custom/>.

即根据您的查询索引:hasIndexingTransformation 将作为 存储在三元组中.

I.e. by your query indexing:hasIndexingTransformation will be stored in the triple store as <http://fedora.info/definitions/v4/indexing#hasIndexingTransformation>.

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

There is no reason to store the prefix in the triple store (actually, prefixes are an artifact of the text serialization, not the data itself), so you can subsequently query this data in one of two ways.

1) 使用前缀

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

2) 使用完整的 URI:

2) Using the full URI:

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

这篇关于SPARQL INSERT 不适用于 PUT 方法.为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆