如何查询美国总统的维基数据,他们在1970年后开始担任总统并且至少有一个女儿?
我知道如何查询美国总统,但我不知道如何过滤我的搜索。
// keep this outside of the event-handler
var lookAtPosition = new THREE.Vector3();
var lookAtTween = new TWEEN.Tween(lookAtPosition);
// as lookAt is not a property we can assign to we need to
// call it every time the tween was updated:
lookAtTween.onUpdate(function() {
camera.lookAt(lookAtPosition);
});
window.onmousedown = function() {
// do your thing to compute pos
// instead of `camera.lookAt(pos)`, do this:
lookAtTween
.stop() // just in case it's still animating
.to(pos, 500) // set destination and duration
.start(); // start the tween
};
答案 0 :(得分:2)
没那么困难:
您已经拥有xsd:date
类型的开始时间。您现在要做的就是提取年份并使用此值进行过滤:
FILTER(year(?start) > 1970)
你的第二个条件“至少有一个女儿”被联合隐含地满足,即如果有这样的数据,总统只会匹配。如果你要求“至少两个女儿”会变得更“有趣”,因为那时你必须由每个总统分组,统计女儿并最终过滤这些群体:
GROUP BY ?p
HAVING (count(?child) > 2)
您的最终查询:
SELECT ?presLabel ?spouseLabel ?picp ?picps ?daughterLabel ?numchild ?start WHERE {
?pres wdt:P31 wd:Q5 .
?pres p:P39 ?position_held_statement .
?position_held_statement ps:P39 wd:Q11696 .
?position_held_statement pq:P580 ?start .
# the spouse
?pres wdt:P26 ?spouse .
# all daughters
?pres wdt:P40 ?daughter.
?daughter wdt:P21 wd:Q6581072.
# number of children
?pres wdt:P1971 ?numchild.
OPTIONAL {
?pres wdt:P18 ?picp
}
OPTIONAL {
?spouse wdt:P18 ?picps
}
# filter by start date here
FILTER(year(?start) > 1970)
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
} ORDER BY ?start
可以在子查询中检索女儿的数量,只需将其放入原始查询中+将变量?numDaughters
添加到所选变量中:
# here we compute the number of daughters
{
select ?pres (count(distinct ?daughter) as ?numDaughters) where {
?pres wdt:P31 wd:Q5 .
?pres p:P39 ?position_held_statement .
?position_held_statement ps:P39 wd:Q11696 .
# all daughters
?pres wdt:P40 ?daughter.
?daughter wdt:P21 wd:Q6581072.
}
group by ?pres
}