在SPARQL中更改PREFIX

问题描述 投票:0回答:1

我创建了一个具有不同前缀的本体(rdf:rdfs:owl:example:car:bike:,......)。我用它们来划分不同的域和例子。

小提取物:

car:Software rdf:type demo:CyberObject.
car:Hardware rdf:type spdm:PhysicalObject.
car:Software car:hasMaturity "ten".
car:Hardware demo:isProducedIn loc:NorthPole.

有没有办法将PREFIXcar:”改为例如“plane:”,并保持关系:

plane:Software rdf:type demo:CyberObject.
plane:Hardware rdf:type spdm:PhysicalObject.
plane:Software plane:hasMaturity "ten".
plane:Hardware demo:isProducedIn loc:NorthPole.

我仍然需要所有的关系。 PREFIXcar:”的物品不必更换;使用新的PREFIX创建新的并将旧对象保存在数据库中就足够了。

谢谢你的建议!

sparql rdf owl allegrograph topbraid-composer
1个回答
2
投票

连续替换主题,谓词和对象中的前缀。

prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
prefix car: <http://example.com/car/>
prefix demo: <http://example.com/demo/>
prefix spdm: <http://example.com/spdm/>
prefix loc: <http://example.com/loc/>
prefix plane: <http://example.com/plane/>

DELETE {?s ?p1 ?o} INSERT {?s ?p2 ?o} WHERE
{
?s ?p1 ?o .
FILTER (strstarts(str(?p1), str(car:)))
BIND (IRI(replace(str(?p1), str(car:), str(plane:)))  AS ?p2)
} ;

DELETE {?s1 ?p ?o} INSERT {?s2 ?p ?o} WHERE
{
?s1 ?p ?o .
FILTER (strstarts(str(?s1), str(car:)))
BIND (IRI(replace(str(?s1), str(car:), str(plane:)))  AS ?s2)
} ; 

DELETE {?s ?p ?o1} INSERT {?s ?p ?o2} WHERE
{
?s ?p ?o1 .
FILTER (strstarts(str(?o1), str(car:)) && isIRI(?o1))
BIND (IRI(replace(str(?o1), str(car:), str(plane:)))  AS ?o2)
} ;

没有在Allegrograph中测试,可能存在Allegr®graph特定的解决方案。

更新

我仍然需要所有关系,PREFIX“car”的对象不必更换......

然后不要替换对象中的前缀。但是,请记住,一个三元组中的对象可以是另一个三元组中的主题。

...使用新的PREFIX创建新的并将旧对象保留在数据库中就足够了。

“独立”URI不存储在triplestore中。

© www.soinside.com 2019 - 2024. All rights reserved.