按日期对 SPARQL 结果排序

发布于 2024-07-27 22:20:59 字数 108 浏览 4 评论 0原文

有没有办法按创建日期对结果进行排序?

必须排序的示例查询:

SELECT * WHERE {?s ?p ?o} limit 200

Is there a way to sort the results by creation date?

Example query which must be sortet:

SELECT * WHERE {?s ?p ?o} limit 200

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

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

发布评论

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

评论(2

亚希 2024-08-03 22:21:00

既然您说过您实际上并未将创建日期存储在 RDF 中,那么执行此操作的任何可能机制都将特定于您正在使用的 SPARQL 实现以及支持 RDF 存储或其他内容。 这很可能是不可能的。

Since you've said you don't actually store the creation date in your RDF then any possible mechanism for doing this would be specific to the SPARQL implementation you were using and the backing RDF store or whatever. It's quite likely that it's just not possible.

土豪我们做朋友吧 2024-08-03 22:20:59

您可以像在 SQL 中一样使用 order by 子句。 请注意,根据 SPARQL 规范,ORDER BY 仅适用于 SELECT 查询。 您需要为要用于排序的属性创建绑定。

SELECT ?s ?p ?o
WHERE {?s ?p ?o .
       ?s <creationDatePredicate> ?date . }
ORDER BY DESC(?date)
LIMIT 200

更新:如果您尚未存储创建日期,则需要自行存储元数据。 至于如何做到这一点,您有几个选择:

  1. 在默认图表中存储一个三元组,其中包含每个主题的创建日期。 如果您要存储多个图表,这很快就会变得很麻烦,而且可能不是您想要的。

  2. 将每个图作为命名图存储在 RDF 三元组存储中。 然后,您可以将有关每个图的元数据存储在默认图或创建时间的一个“共享”命名图中。

  3. 将您的数据存储在命名图表中,并使用命名图表来存储创建时间元数据。

选项 #2 的 SPARQL 查询的示例如下:

SELECT ?s ?p ?o
WHERE {
        GRAPH ?g { ?s ?p ?o . }
        ?g <creationDatePredicate> ?date . }
ORDER BY DESC(?date)
LIMIT 200

You can use an order by clause just like you can in SQL. Note that per the SPARQL specification, the ORDER BY only applies to SELECT queries. You will need to create a binding for the property you want to use for ordering.

SELECT ?s ?p ?o
WHERE {?s ?p ?o .
       ?s <creationDatePredicate> ?date . }
ORDER BY DESC(?date)
LIMIT 200

Update: If you're not already storing the creation date, you will need to store the metadata yourself. As to how do to do that, you have a few options:

  1. Store a triple in your default graph which has the creation date for each subject. If you're storing more than one graph, this will become unwieldy very quickly and probably is not what you want.

  2. Store each graph as a named graph in your RDF triple store. You can then store metadata about each graph in the default graph or in one "shared" named graph for creation times.

  3. Store your data in the named graph and use a named graph to store the creation time metadata.

An example of option #2's SPARQL query would be:

SELECT ?s ?p ?o
WHERE {
        GRAPH ?g { ?s ?p ?o . }
        ?g <creationDatePredicate> ?date . }
ORDER BY DESC(?date)
LIMIT 200
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文