query-fcf43ce9cb80ce61e6bc41d2897887af

rq turtle/ttl

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

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

Query found at

graph TD classDef projected fill:lightgreen; classDef literal fill:orange; classDef iri fill:yellow; v14("?dRear") v8("?fleet"):::projected v6("?person"):::projected v5("?rank") v9("?stmtAdmiral") v15("?stmtCaptain") v7("?stmtFleet") v13("?stmtRear") v11("?stmtVice") v16("?threeID"):::projected v10("?timeAdmiral"):::projected v2("?timeCaptain"):::projected v4("?timeDeath") v15("?timeRear"):::projected v6("?timeReport") v12("?timeVice"):::projected a1((" ")) a2((" ")) c9(["wd:Q2916006"]):::iri c11(["wd:Q4902790"]):::iri c22(["en"]):::literal c12(["wd:Q125940783"]):::iri c20(["bd:serviceParam"]):::iri c5(["wd:Q5"]):::iri c14(["wd:Q15615347"]):::iri c8(["wd:Q2501631"]):::iri c3(["wd:Q172771"]):::iri c15(["wd:Q5036514"]):::iri f0[["?timeReport >= ?timeRear"]] f0 --> v6 f0 --> v15 f1[["?timeReport <= ?timeDeath"]] f1 --> v6 f1 --> v4 bind2[/"'1769-01-01^^xsd:date'"/] bind2 --as--o v6 v6 --"p:direct/P241"--> c3 v6 --"p:direct/P31"--> c5 subgraph optional0["(optional)"] style optional0 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:P410".-> v7 v7 --"p:statement/P410"--> c8 bind3[/"'1^^xsd:integer'"/] bind3 --as--o v8 end subgraph optional1["(optional)"] style optional1 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:P410".-> v9 v9 --"p:statement/P410"--> c9 v9 --"p:qualifier/P580"--> v10 end subgraph optional2["(optional)"] style optional2 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:P410".-> v11 v11 --"p:statement/P410"--> c11 v11 --"p:qualifier/P580"--> v12 end subgraph optional3["(optional)"] style optional3 fill:#bbf,stroke-dasharray: 5 5; f4[["not "]] subgraph f4e0["Exists Clause"] e0v1 --"p:statement/P410"--> e0c2 e0v1("?stmtRear"):::projected e0c2(["wd:Q125940783"]):::iri end f4--EXISTS--> f4e0 f4 --> v13 f4 --> c7 f4 --> c12 v13 -."p:statement/P410".-> c12 v6 --"p:P410"--> v13 v13 --"p:statement/P410"--> a1 a1 --"p:direct/P279"--> c14 v13 --"p:qualifier/P580"--> v14 bind6[/"min(?dRear)"/] v14 --o bind6 bind6 --as--o v15 end subgraph optional4["(optional)"] style optional4 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:P410".-> v15 v15 --"p:statement/P410"--> a2 a2 --"p:direct/P279"--> c15 v15 --"p:qualifier/P580"--> v2 v15 --"wikibase:rank"--> v5 end subgraph optional5["(optional)"] style optional5 fill:#bbf,stroke-dasharray: 5 5; v6 -."p:direct/P7389".-> v16 end v6 --"p:direct/P570"--> v4 subgraph s1["http://wikiba.se/ontology#label"] style s1 stroke-width:4px; c20 --"wikibase:language"--> c22 end