按日期对 SPARQL 结果排序
有没有办法按创建日期对结果进行排序?
必须排序的示例查询:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
既然您说过您实际上并未将创建日期存储在 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.
您可以像在 SQL 中一样使用 order by 子句。 请注意,根据 SPARQL 规范,
ORDER BY
仅适用于SELECT
查询。 您需要为要用于排序的属性创建绑定。更新:如果您尚未存储创建日期,则需要自行存储元数据。 至于如何做到这一点,您有几个选择:
在默认图表中存储一个三元组,其中包含每个主题的创建日期。 如果您要存储多个图表,这很快就会变得很麻烦,而且可能不是您想要的。
将每个图作为命名图存储在 RDF 三元组存储中。 然后,您可以将有关每个图的元数据存储在默认图或创建时间的一个“共享”命名图中。
将您的数据存储在命名图表中,并使用命名图表来存储创建时间元数据。
选项 #2 的 SPARQL 查询的示例如下:
You can use an order by clause just like you can in SQL. Note that per the SPARQL specification, the
ORDER BY
only applies toSELECT
queries. You will need to create a binding for the property you want to use for ordering.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:
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.
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.
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: