代码之家  ›  专栏  ›  技术社区  ›  Grapheneer

更改SPARQL中的前缀

  •  1
  • Grapheneer  · 技术社区  · 7 年前

    我创建了一个带有不同前缀的本体( 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.
    

    有没有办法改变 PREFIX " 汽车: “至,例如” plane: “,并保持以下关系:

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

    我仍然需要所有的关系。具有的对象 前缀 " 汽车: “不必更换;用新的 前缀 并将旧对象保留在数据库中。。

    谢谢你的建议!

    1 回复  |  直到 7 年前
        1
  •  4
  •   Stanislav Kralin kenwenzel    7 年前

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

    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)
    } ;
    

    未在Allegrgraph中测试,可能存在Allegrgraph特定的解决方案。

    使现代化

    我仍然需要所有关系,前缀为“car”的对象不需要 必须更换

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

    这就足够用 新建前缀并在数据库中保留旧对象。

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

    推荐文章