14.3.124. crate_anon.crateweb.extra.salutation

crate_anon/crateweb/extra/salutation.py


Copyright (C) 2015, University of Cambridge, Department of Psychiatry. Created by Rudolf Cardinal (rnc1001@cam.ac.uk).

This file is part of CRATE.

CRATE is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CRATE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CRATE. If not, see <https://www.gnu.org/licenses/>.


Converts names to salutations and parses names into component parts.

crate_anon.crateweb.extra.salutation.forename_surname(forename: str | None, surname: str | None) str[source]

For use when reporting names.

Parameters:
  • forename – forename

  • surname – surname

Returns:

a string of the style Forename Surname

Return type:

str

crate_anon.crateweb.extra.salutation.get_initial_surname_tuple_from_string(s: str) Tuple[str, str][source]

Parses a name-like string into plausible parts. Try:

get_initial_surname_tuple_from_string("AJ VAN DEN BERG")
get_initial_surname_tuple_from_string("VAN DEN BERG AJ")
get_initial_surname_tuple_from_string("J Smith")
get_initial_surname_tuple_from_string("J. Smith")
get_initial_surname_tuple_from_string("Smith J.")
get_initial_surname_tuple_from_string("Smith JKC")
get_initial_surname_tuple_from_string("Dr Bob Smith")
get_initial_surname_tuple_from_string("LINTON H C (PL)")
Returns:

initial, surname

Return type:

tuple

crate_anon.crateweb.extra.salutation.salutation(title: str | None, forename: str | None, surname: str | None, sex: str = '', assume_dr: bool = False) str[source]

For salutations: “Dear …”

Parameters:
  • title – title

  • forename – forename

  • surname – surname

  • sex"M" or "F" or other/unknown

  • assume_dr – assume the person has the title “Dr”?

Returns:

a salutation like Prof. Smith

crate_anon.crateweb.extra.salutation.salutation_default_title(sex: str = '', assume_dr: bool = False) str[source]

Returns a guess as to someone’s title.

Parameters:
  • sex"M" or "F" or other/unknown

  • assume_dr – assume the person has the title “Dr”?

Returns:

a title

crate_anon.crateweb.extra.salutation.title_forename_surname(title: str | None, forename: str | None, surname: str | None, always_title: bool = False, sex: str = '', assume_dr: bool = False) str[source]

Used when reporting names. Returns a string of the format Title Forename Surname, as far as we can work it out.

Parameters:
  • title – title

  • forename – forename

  • surname – surname

  • always_title – if we don’t know the title, guess one?

  • sex"M" or "F" or other/unknown

  • assume_dr – assume the person has the title “Dr”?

Returns:

a string of a format like

Prof. John Smith
John Smith
Prof. Smith

etc.

Return type:

str