【问题标题】:Change PREFIX in SPARQL在 SPARQL 中更改前缀
【发布时间】:2017-12-21 06:27:59
【问题描述】:

我创建了一个具有不同前缀(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 1.1 更新查询不起作用?用新的 URI 替换旧的 URI,或者问题到底出在哪里?
  • 本体编辑器/三元存储中已经存在本体。我只想更改现有节点的前缀@AKSW
  • 我知道你想做什么。但我没有看到你到目前为止尝试了什么......但知道没关系,请参阅下面@StanislavKralin 的完美答案(并接受它)
  • 您创建了实例数据,而不是本体。本体是类和属性的结构,用于描述实体。您的数据描述了实体。

标签: sparql rdf owl allegrograph topbraid-composer


【解决方案1】:

依次替换主语、谓语和宾语中的前缀。

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 中测试,可能存在 Allegrograph 特定的解决方案。

更新

我仍然需要所有的关系,带有前缀“汽车”的对象不需要 必须更换……

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

...用 new PREFIX 并将旧对象保留在数据库中。

“独立”URI 不存储在三重存储中。

【讨论】:

    猜你喜欢
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-13
    • 2020-11-28
    • 1970-01-01
    • 1970-01-01
    • 2018-08-21
    相关资源
    最近更新 更多