Reputation: 113
I want to get humans whose parents who are not married (the parents are not in each others spouse property), so I write the following query
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
Then I discover if one person has several spouses, then the results give me lots of garbage. take Q15904745 as an example, his father(Q198042) has 2 spouse records, and his mother(Q16603522) is one of the spouse, but his info still will returns and i do not want to include this.
I would like to ask how can I change my query to get what I want? Here is the link to Wikidata endpoint.
Upvotes: 1
Views: 175
Reputation: 8625
If something like 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
Upvotes: 1
Reputation: 1993
I think this does what you want.
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
It will exclude all people whose parents have ever married. However, I can't claim to have tested it thoroughly.
Upvotes: 1