SPARQL - 如何只获取最新的实体
SPARQL - How to get only newest entities
在我的三重存储中,我有一个 schema:CreativeWork 的集合,其中包含 属性 schema:version 和 schema: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.triplydb.com/s/rLq4V-JgS
注:FILTER( ?identifier = "46d8b7abfec44865a567ea04e385661b" ) .
只是为了方便。
UninformedUser 的查询运行良好:
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
在我的三重存储中,我有一个 schema:CreativeWork 的集合,其中包含 属性 schema:version 和 schema: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.triplydb.com/s/rLq4V-JgS
注:FILTER( ?identifier = "46d8b7abfec44865a567ea04e385661b" ) .
只是为了方便。
UninformedUser 的查询运行良好:
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