SPARQL-如何仅获得最新实体

发布于 2025-01-25 06:43:58 字数 922 浏览 1 评论 0原文

在我的三重商店中,我有一个具有属性架构:版本和架构:datecreated的schema:Creativework的集合。 现在,我想获得所有架构:创意工作,但只有最新的架构。 我的示例:

PREFIX schema: <https://schema.org/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT *
WHERE { 
    ?subject rdf:type schema:CreativeWork .     
    ?subject schema:identifier ?identifier .
    ?subject schema:version ?version .
    ?subject schema:dateCreated ?dateCreated .
    OPTIONAL {?subject schema:about/schema:name ?name .}
    FILTER( ?identifier = "46d8b7abfec44865a567ea04e385661b" ) .
} LIMIT 10

如何仅查询最新版本?

可执行示例: https://api.triplipliplipliplipliplipliplydb.com/s/rllq4v-jgs

注意:filter(?didentifier =“ 46D8B7ABFEC44865A567EA04E385661B”)。只是为了使其更容易。

In my triple store i've a collection of schema:CreativeWork which has the property schema:version and schema:dateCreated.
Now i want to get all schema:CreativeWork but only the newest ones.
My sample:

PREFIX schema: <https://schema.org/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT *
WHERE { 
    ?subject rdf:type schema:CreativeWork .     
    ?subject schema:identifier ?identifier .
    ?subject schema:version ?version .
    ?subject schema:dateCreated ?dateCreated .
    OPTIONAL {?subject schema:about/schema:name ?name .}
    FILTER( ?identifier = "46d8b7abfec44865a567ea04e385661b" ) .
} LIMIT 10

How do i manage to query only the latest version?

executable sample: https://api.triplydb.com/s/rLq4V-JgS

Note: FILTER( ?identifier = "46d8b7abfec44865a567ea04e385661b" ) . is just to make it easier.

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

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

发布评论

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

评论(1

巨坚强 2025-02-01 06:43:58

Unformeduser的查询运作良好:

PREFIX schema: <https://schema.org/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT * 
{
  {
    SELECT ?identifier (max(?dateCreated) as ?latestDate) 
    WHERE {     
      ?subject rdf:type schema:CreativeWork .       
      ?subject schema:identifier ?identifier .     
      ?subject schema:dateCreated ?dateCreated . 
    } group by ?identifier
  }     
  ?subject schema:identifier ?identifier .     
  ?subject schema:version ?version .    
  ?subject schema:dateCreated ?latestDate .     
  OPTIONAL {?subject schema:about/schema:name ?name . } 
} LIMIT 100

The query of UninformedUser is working well:

PREFIX schema: <https://schema.org/> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
SELECT DISTINCT * 
{
  {
    SELECT ?identifier (max(?dateCreated) as ?latestDate) 
    WHERE {     
      ?subject rdf:type schema:CreativeWork .       
      ?subject schema:identifier ?identifier .     
      ?subject schema:dateCreated ?dateCreated . 
    } group by ?identifier
  }     
  ?subject schema:identifier ?identifier .     
  ?subject schema:version ?version .    
  ?subject schema:dateCreated ?latestDate .     
  OPTIONAL {?subject schema:about/schema:name ?name . } 
} LIMIT 100
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文