是否可以将这 2 个 SPARQL 更新查询合并为一个?

发布于 2024-12-18 17:39:24 字数 737 浏览 2 评论 0原文

我想要执行更新以删除 RDF 存储中两个节点之间的链接(谓词)。该链接是双向的(skos:narrower 和 skos:broader)。我想进行一个唯一的查询,以确保在唯一的操作中删除两个链接。

目前,我正在使用这两个查询( ?term 和 ?parentTerm 都将在执行时与特定的 URI 绑定):

  PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
  PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
  DELETE
  WHERE{ 
    GRAPH ?graph {
      ?term skos:broader ?parentTerm
    }
  }

  PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
  PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
  DELETE
  WHERE{ 
    GRAPH ?graph {
      ?parentTerm skos:narrower ?term
    }
  }

有没有办法进行唯一的查询,而不改变其他链接(又名:谓词)谓词之间存在吗?

我厌倦了使用 ;分离查询,并将其作为单个命令发送到芝麻存储(就像您有时在 SQL 中所做的那样),但它不起作用。

I want to perform an update to remove the link (predicate) between two nodes in my RDF Store. The link is bidirectional (skos:narrower, and skos:broader). I would like to make a unique query, to insure both links are removed in a unique operation.

Currently, I'm using those 2 queries (both ?term and ?parentTerm will be bound with specific URIs at time of execution):

  PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
  PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
  DELETE
  WHERE{ 
    GRAPH ?graph {
      ?term skos:broader ?parentTerm
    }
  }

  PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
  PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
  DELETE
  WHERE{ 
    GRAPH ?graph {
      ?parentTerm skos:narrower ?term
    }
  }

Is there a way to make a unique query, and not alter other links (aka: predicates) that could exist between the predicates?

I tired using a ; to separate the queries, and sent it as a single command to the sesame store (as you sometimes do in SQL), but it did not work.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我恋#小黄人 2024-12-25 17:39:24

遗憾的是,无法将其写为对上一个答案的评论...

您可以写

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
DELETE {
  GRAPH ?graph {
    ?term skos:broader ?parentTerm .
    ?parentTerm skos:narrower ?term .
  }
}    
WHERE { 
  GRAPH ?graph {
    OPTIONAL { ?term skos:broader ?parentTerm }
    OPTIONAL { ?parentTerm skos:narrower ?term }
  }
}

它更加冗长,因为您不能将 OPTIONAL 与 DELETE WHERE 一起使用,但它不应该显着降低效率。

请注意,您还可以使用 ; 分隔 SPARQL 更新操作。并在单个请求中发送它们,这应该会让您得到相同的行为。

Couldn't write this as a comment to the previous answer sadly...

You can write

PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
DELETE {
  GRAPH ?graph {
    ?term skos:broader ?parentTerm .
    ?parentTerm skos:narrower ?term .
  }
}    
WHERE { 
  GRAPH ?graph {
    OPTIONAL { ?term skos:broader ?parentTerm }
    OPTIONAL { ?parentTerm skos:narrower ?term }
  }
}

It's a lot more verbose as you can't use OPTIONAL with DELETE WHERE, but it shouldn't be significantly less efficient.

Note, you can also separate SPARQL Update operations with a ; and send them in a single request, which should get you the same behaviour.

汹涌人海 2024-12-25 17:39:24

您可以将这两个三重模式合并到一个查询中:

PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
DELETE
WHERE{ 
  GRAPH ?graph {
    ?term skos:broader ?parentTerm .
    ?parentTerm skos:narrower ?term .
  }
}

请注意,这只会删除两者都存在的情况,但听起来您的数据就是这种情况。

You can combine both triple patterns into a single query:

PREFIX skos:<http://www.w3.org/2004/02/skos/core#>
PREFIX rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>      
DELETE
WHERE{ 
  GRAPH ?graph {
    ?term skos:broader ?parentTerm .
    ?parentTerm skos:narrower ?term .
  }
}

Note that this will only delete these where both exist, but it sounds like that's the case in your data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文