我正在尝试为客户分析一些图表。 (我使用带有sparql 1.0规范的ARC2)
他希望确保某些字段由他的数据提供者填充。
要做到这一点,我想计算具有未绑定元素和绑定元素主题的主题:
这是我的问题:
SELECT count(?unbound) as ?unboundCount count(?s) as ?bound
WHERE {
?s <http://purl.org/dc/elements/1.1/source> ?o .
OPTIONAL { ?unbound <http://purl.org/dc/elements/1.1/source> ?y } .
FILTER(!BOUND(?y) )
}
对于?bound和?unboundcount都返回0。我哪里错了?
答案 0 :(得分:0)
尝试以下方法:
SELECT count(?unbound) as ?unboundCount count(?s) as ?bound
WHERE {
# Things with a source
{
?s <http://purl.org/dc/elements/1.1/source> ?o
}
UNION
# Things without a source
{
?unbound a ?type # match everything?
OPTIONAL { ?unbound <http://purl.org/dc/elements/1.1/source> ?y } .
FILTER(!BOUND(?y))
}
}
联盟的第一位显而易见。对于第二位 - 没有来源的东西 - 我们需要找到“一切”(或者至少是感兴趣的东西),然后只保留那些没有来源的主题。 ?s a ?type
是找到所有内容的合理的第一步,但您可能有更好的方法来识别数据集中感兴趣的项目。
答案 1 :(得分:0)
似乎ARC2无法管理此类查询的倍数。
我通过制作两个分隔查询来成功:
# The unbound query
SELECT count(?unbound) as ?unboundCount
WHERE {
?unbound <http://purl.org/dc/elements/1.1/source> ?o .
OPTIONAL { ?unbound <http://purl.org/dc/elements/1.1/source> ?y } .
FILTER(!BOUND(?y) )
}
# The bound query
SELECT count(?s) as ?boundCount
WHERE {
?s <http://purl.org/dc/elements/1.1/source> ?o .
}
我们远非优雅的答案,但似乎这是与ARC2一起使用的唯一途径