query-fcf43ce9cb80ce61e6bc41d2897887af
Working on a flag list for the Royal Navy SELECT DISTINCT ?person ?personLabel ?fleet ?timeAdmiral ?timeVice ?timeRear ?timeCaptain ?threeID { # allow the report to work for different years BIND ("1769-01-01"^^xsd:dateTime AS ?timeReport) .
# person in Royal Navy ?person wdt:P241 wd:Q172771 .
# human instead of fictional ?person wdt:P31 wd:Q5 .
# ?person wdt:P410 ?rank . # ?rank wdt:P279 wd:Q977459 . # admiral of the fleet (of the Royal Navy) subclass of admiral of the fleet Q842486 # ?person wdt:P410 wd:Q2501631 . # use P279 to pick up the subclass
# military rank -- should have a start time # admiral of the fleet wd:Q842486 . # admiral of the fleet (Royal Navy) wd:Q2501631 # admiral # admiral (Royal Navy) wd:Q2916006 # vice admiral wd:Q214443 . # vice admiral (Royal Navy) wd:Q4902790 # rear admiral wd:Q156945 # rear admiral (Royal Navy) wd:Q15615347 # captain # captain (Royal Navy) wd:Q5036514 # flag officer (watch out: rear admiral is an instance of military rank) wd:Q977459 .
# get statements about the person's rank optional { ?person p:P410 ?stmtFleet . ?stmtFleet ps:P410 wd:Q2501631 . BIND(1 AS ?fleet) . }
optional { ?person p:P410 ?stmtAdmiral . ?stmtAdmiral ps:P410 wd:Q2916006 . ?stmtAdmiral pq:P580 ?timeAdmiral . }
optional { ?person p:P410 ?stmtVice . ?stmtVice ps:P410 wd:Q4902790 . ?stmtVice pq:P580 ?timeVice . }
optional { # ?person p:P410 ?stmtRear . # ?stmtRear ps:P410 wd:Q15615347 . # ?stmtRear pq:P580 ?timeRear . # # use a SELECT to find the earliest date as a rear admiral SELECT ?person (MIN(?dRear) AS ?timeRear) WHERE { # there is a statement about the rank ?person p:P410 ?stmtRear . # that rank is a subclass of rear admiral ?stmtRear ps:P410/wdt:P279* wd:Q15615347 . # the rank has a date qualifier ?stmtRear pq:P580 ?dRear . # filter out superannuated rear admirals... filter not exists {?stmtRear ps:P410 wd:Q125940783 . }. } GROUP BY ?person }
optional { # person has a rank ?person p:P410 ?stmtCaptain . # the rank is captain or a subclass of captain (i.e., captain or post-captain) ?stmtCaptain ps:P410/wdt:P279* wd:Q5036514 . # the statement has a start time ?stmtCaptain pq:P580 ?timeCaptain . # the statement is not deprecrated ?stmtCaptain wikibase:rank ?rank . FILTER(?rank != wikibase:DeprecatedRank) . }
# Three Decks ID optional { ?person wdt:P7389 ?threeID . }
# get time of death (some have multiple death dates) ?person wdt:P570 ?timeDeath . filter ( ?timeReport <= ?timeDeath) .
filter ( ?timeReport >= ?timeRear) .
# occupation naval officer # ?person wdt:P106 wd:Q10669499 # occupation military officer # ?person wdt:P106 wd:Q189290 .
SERVICE wikibase:label { bd:serviceParam wikibase:language "en" . }
} ORDER BY ?timeRear ?timeCaptain
Use at
- https://query.wikidata.org/sparql
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX ps: <http://www.wikidata.org/prop/statement/>
PREFIX pq: <http://www.wikidata.org/prop/qualifier/>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX bd: <http://www.bigdata.com/rdf#>
# Working on a flag list for the Royal Navy
SELECT DISTINCT ?person ?personLabel ?fleet ?timeAdmiral ?timeVice ?timeRear ?timeCaptain ?threeID
{
# allow the report to work for different years
BIND ("1769-01-01"^^xsd:date AS ?timeReport) .
# person in Royal Navy
?person wdt:P241 wd:Q172771 .
# human instead of fictional
?person wdt:P31 wd:Q5 .
# ?person wdt:P410 ?rank .
# ?rank wdt:P279 wd:Q977459 .
# admiral of the fleet (of the Royal Navy) subclass of admiral of the fleet Q842486
# ?person wdt:P410 wd:Q2501631 .
# use P279 to pick up the subclass
# military rank -- should have a start time
# admiral of the fleet wd:Q842486 .
# admiral of the fleet (Royal Navy) wd:Q2501631
# admiral
# admiral (Royal Navy) wd:Q2916006
# vice admiral wd:Q214443 .
# vice admiral (Royal Navy) wd:Q4902790
# rear admiral wd:Q156945
# rear admiral (Royal Navy) wd:Q15615347
# captain
# captain (Royal Navy) wd:Q5036514
# flag officer (watch out: rear admiral is an instance of military rank) wd:Q977459 .
# get statements about the person's rank
optional {
?person p:P410 ?stmtFleet .
?stmtFleet ps:P410 wd:Q2501631 .
BIND(1 AS ?fleet) .
}
optional {
?person p:P410 ?stmtAdmiral .
?stmtAdmiral ps:P410 wd:Q2916006 .
?stmtAdmiral pq:P580 ?timeAdmiral .
}
optional {
?person p:P410 ?stmtVice .
?stmtVice ps:P410 wd:Q4902790 .
?stmtVice pq:P580 ?timeVice .
}
optional {
# ?person p:P410 ?stmtRear .
# ?stmtRear ps:P410 wd:Q15615347 .
# ?stmtRear pq:P580 ?timeRear .
#
# use a SELECT to find the earliest date as a rear admiral
SELECT ?person (MIN(?dRear) AS ?timeRear) WHERE {
# there is a statement about the rank
?person p:P410 ?stmtRear .
# that rank is a subclass of rear admiral
?stmtRear ps:P410/wdt:P279* wd:Q15615347 .
# the rank has a date qualifier
?stmtRear pq:P580 ?dRear .
# filter out superannuated rear admirals...
filter not exists {?stmtRear ps:P410 wd:Q125940783 . }.
} GROUP BY ?person
}
optional {
# person has a rank
?person p:P410 ?stmtCaptain .
# the rank is captain or a subclass of captain (i.e., captain or post-captain)
?stmtCaptain ps:P410/wdt:P279* wd:Q5036514 .
# the statement has a start time
?stmtCaptain pq:P580 ?timeCaptain .
# the statement is not deprecrated
?stmtCaptain wikibase:rank ?rank . FILTER(?rank != wikibase:DeprecatedRank) .
}
# Three Decks ID
optional {
?person wdt:P7389 ?threeID .
}
# get time of death (some have multiple death dates)
?person wdt:P570 ?timeDeath .
filter ( ?timeReport <= ?timeDeath) .
filter ( ?timeReport >= ?timeRear) .
# occupation naval officer
# ?person wdt:P106 wd:Q10669499
# occupation military officer
# ?person wdt:P106 wd:Q189290 .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
} ORDER BY ?timeRear ?timeCaptain