Welcome to Software Development on Codidact!
Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.
Wikidata: How do I ask for the start date of a property in SPARQL?
I have a SPARQL query to Wikidata that returns the names and handles and parties of politicians for whom a Mastodon address is stored at Wikidata. Filtered by nationality and with an output of the name field in the corresponding language.
I would like to extend this so that the start date (P580) of the Mastodon address (P4033) is output in a field in order to be able to sort the result by new members. Does anyone know how to add the question? joinedfediverse
should tell the start date.
SELECT ?name ?partyLabel ?mastodon ?joinedfediverse
WHERE {
?politician wdt:P31 wd:Q5; # instance of human
wdt:P106 wd:Q82955; # occupation politician
wdt:P27 wd:Q183; # country of citizenship Germany
wdt:P4033 ?mastodon. # Mastodon address
OPTIONAL {?politician wdt:P580 ?joinedfediverse. } # Fediverse joining date
OPTIONAL {?politician wdt:P39 ?position. # position held
?position wdt:P279* wd:Q13217683. # subclass of member of parliament
?position wdt:P1001 ?parliament.} # applies to jurisdiction
OPTIONAL {?politician wdt:P102 ?party.} # member of political party
OPTIONAL {?politician rdfs:label ?name. # name
FILTER(LANG(?name) = "de")} # in German language
SERVICE wikibase:label { bd:serviceParam wikibase:language "de". } # labels in German language
}
1 answer
You can query for P580 (start time) qualifiers on P4033 (Mastodon address) statements like this:
p:P4033 ?mastoStatement.
?mastoStatement pq:P580 ?joinedfediverse.
Note the use of p:
instead of wdt:
.
Your full query would be:
SELECT ?politicianLabel ?partyLabel ?mastodon ?joinedfediverse
{
?politician wdt:P31 wd:Q5; # instance of human
wdt:P106 wd:Q82955; # occupation politician
wdt:P27 wd:Q183; # country of citizenship Germany
p:P4033 ?mastoStatement.
?mastoStatement a wikibase:BestRank; ps:P4033 ?mastodon. # Mastodon address
OPTIONAL {?mastoStatement pq:P580 ?joinedfediverse.} # start time of Mastodon address
OPTIONAL {?politician wdt:P102 ?party.} # member of political party
SERVICE wikibase:label { bd:serviceParam wikibase:language "de". } # labels in German language
}
0 comment threads