首页 > 解决方案 > SPARQL 语法更正

问题描述

这是我第一次使用 SPARQL。使用 DBpedia,我想列出 1992 年以来所有摇滚乐队的乐队名称

我已经开发的代码运行正确,但结果为 0。我是否错误地过滤了日期?

PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?bandname where {
?band dbo:genre dbp:Rock_music .
?band foaf:name ?bandname .
FILTER (dbo:activeYearsStartYear >= xsd:date("1992-01-01") && dbo:activeYearsStartYear <= xsd:date("1992-12-31"))
}

我只希望列中的乐队名称。

标签: sparqldbpedia

解决方案


PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dbp: <http://dbpedia.org/resource/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT DISTINCT ?bandname ?date where {
?band dbo:genre dbp:Rock_music .
?band foaf:name ?bandname .
?band dbo:activeYearsStartYear ?date .
FILTER (?date >= "1992-01-01"^^xsd:dateTime && ?date <= "1992-12-31"^^xsd:dateTime)
}

这可以解决问题,但请注意 dbo:activeYearsStartYear 仅生成年份,因此 FILTER 不使用日/月。


推荐阅读