如何用SPARQL查询带时间约束的人类相关Wikidata属性?
Hey there, I see you're trying to pull Wikidata properties that apply to humans and require both a start time and end time—great use case! The issue with your initial query is likely that it wasn't tightly enough scoped to properties specifically meant for human entities, or didn't properly check that both time constraints are required for the property.
Let's fix that with a precise SPARQL query that eliminates false positives:
SELECT ?property ?propertyLabel WHERE { # Ensure we're only dealing with Wikidata properties ?property wdt:P31 wd:Q18616576 ; # Mark that the property has a "value required" constraint wdt:P2302 wd:Q21503250 ; # Specify the property applies exclusively to human entities (Q5) wdt:P2306 wd:Q5 . # Require that the property's constraints include BOTH start time (P580) and end time (P582) ?property p:P2302 [ ps:P2302 wd:Q21503250 ; pq:P580 [] ; # Exists a start time constraint pq:P582 [] # Exists an end time constraint ] . # Fetch human-readable labels (swap "en" for "zh" for Chinese labels) SERVICE wikibase:label { bd:serviceParam wikibase:language "en" } } ORDER BY ?propertyLabel
Key Improvements in This Query:
- Scoped to human-only properties: The
wdt:P2306 wd:Q5clause ensures we only pull properties that are meant to be used with human entities (Q5 is Wikidata's item for "human"). - Explicit dual time constraints: The nested
p:P2302block checks that the property's required constraints include both start and end time, not just one or the other. - Property validation:
wdt:P31 wd:Q18616576confirms we're only working with actual Wikidata properties, not other entity types.
Expected Accurate Results:
When you run this query, you'll get properties like:
- P26: Spouse
- P39: Position held
- P451: Partner
- P108: Employer (for roles with start/end dates)
- P1412: Language known (if proficiency has a start/end period)
If you want to adjust the language of the labels, just change the "en" in the SERVICE clause to your preferred language code (e.g., "zh" for Chinese).
内容的提问来源于stack exchange,提问作者Omri Myers
相关产品推荐
相关产品推荐

