2017-02-21 82 views
1

我想人类的父母谁不结婚(父母不在对方的配偶财产),所以我写了下面的查询维基数据查询没有提供预期的效果

SELECT ?human ?father ?mother ?someone ?humanLabel ?fatherLabel ?motherLabel ?someoneLabel WHERE { 
    ?human wdt:P31 wd:Q5. 
    ?human wdt:P22 ?father. 
    ?human wdt:P25 ?mother. 
    ?father wdt:P26 ?someone. 
    FILTER (?mother != ?someone) 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } 
}limit 100 

然后我发现,如果一个人有几个配偶,结果给了我很多垃圾。采取Q15904745作为一个例子,他的父亲(Q198042)具有2个配偶纪录,而他的母亲(Q16603522)是配偶中的一个,但他的信息仍然会回报,我不想包含此。

我想请问我怎样才能改变我的查询来获取我想要什么?这里是Wikidata端点的link

回答

1

如果像this

SELECT distinct ?human ?father ?mother ?someone ?humanLabel ?fatherLabel ?motherLabel 
WHERE { 
    ?human wdt:P31 wd:Q5. 
    ?human wdt:P22 ?father. 
    ?human wdt:P25 ?mother. 
    FILTER (NOT EXISTS {?father wdt:P26 ?mother }) . 
    FILTER (NOT EXISTS {?mother wdt:P26 ?father }) . 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } 
} 
order by ?humanLabel 
limit 100 
+0

嗨,我觉得这个方法返回的父母结婚的人。但我想要父母不结婚的人。 – Charlotte

+0

@Charlotte,更正,请现在检查 – Alexan

+0

嗨,当人类的父亲或母亲拥有一个以上的配偶记录时,这个人也会出现在最终的结果集中(当sparql将他的父母配偶记录与另一个配偶不匹配时父母),我不想包括这一点。 – Charlotte

1

我想这你想要做什么。

SELECT ?human ?father ?mother ?humanLabel ?fatherLabel ?motherLabel WHERE { 
    ?human wdt:P31 wd:Q5. 
    ?human wdt:P22 ?father. 
    ?human wdt:P25 ?mother. 
    MINUS {?mother wdt:P26 ?father.} 

    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } 
}limit 100 

这将排除所有的人,其父母曾经结婚。但是,我不能声称已经彻底测试过它。

+0

嗨,当人类的父亲或母亲有多个配偶记录时,这个人也会出现在最终结果集中(当sparql将他的父母配偶记录与另一个配偶不匹配时父母),我不想包括这一点。 – Charlotte