我正在从imdb的数据集中使用sparql开展有关查询的学校工作。我不得不做一些询问,我对这个有审美问题:
SELECT ?1d ?2d WHERE {
{
SELECT ?d (COUNT(?d) AS ?count)
WHERE {
?x projeto:actsIn ?m .
?x foaf-modified:firstName ?1x .
?x foaf-modified:familyName ?2x .
FILTER REGEX(?1x, "^Frances?") .
FILTER REGEX(?2x, "^Mcdormand?") .
?d projeto:directs ?m .
} GROUP BY ?d
}
{
SELECT (MAX(?count) AS ?max)
WHERE {
{
SELECT ?d (COUNT(?d) AS ?count)
WHERE {
?x projeto:actsIn ?m .
?x foaf-modified:firstName ?1x .
?x foaf-modified:familyName ?2x .
FILTER REGEX(?1x, "^Frances?") .
FILTER REGEX(?2x, "^Mcdormand?") .
?d projeto:directs ?m .
} GROUP BY ?d
}
}
}
FILTER (?count = ?max) .
?d foaf-modified:firstName ?1d .
?d foaf-modified:familyName ?2d .
}
我需要得到哪位导演最能导演演员X的电影(在这个例子中是Frances Mcdormand)。我找到的解决方案使用相同的选择块和计数两次。如果不使用同一个块两次,还有其他方法可以执行此查询吗?