2017-02-21 81 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