<commit_before><commit_msg>missed concerns<commit_after>module HkNames
  extend ActiveSupport::Concern

  ## Names
  #
  # With Anglo-Chinese Hong Kong names it is difficult to be sure of the right presentation for each individual.
  #
  # We hold the name in three fields: title, given name and family name. People with both a Chinese and an
  # English forename are encouraged to enter their given name in the form <NAME>, Jimmy. The family_name 
  # should always be a single, usually Chinese, surname: Chan or Smith.
  #
  # When a comma is found in the given name, we assume that they have followed the chinese, english format.
  # If not, we assume the whole name is Chinese.
  #
  # ### Polite informality
  #
  # People with an English forename would normally be addressed as <NAME>. People with only a Chinese
  # forename should be addressed as <NAME>ai Wan.
  #
  def informal_name
    # The standard form of the given name is <NAME>, Ray
    # But some people are known only as Ray.
    chinese, english = given_name.split(/,\s*/)
    parts = chinese.split(/\s+/)

    # Here we can't tell the difference between people with one chinese given name and one anglo given name
    # but the order of names is reversed in the latter case. For now we assume that the presence of a chinese
    # name or two given names indicates that the chinese word ordering should be used.
    unless chinese_name? || parts.length > 1
      english ||= chinese
    end
    if english
      # People with an english name are called <NAME>, by default
      [english, family_name].join(' ')
    else
      # People without are called <NAME>
      [family_name, chinese].join(' ')
    end
  end
  alias :name :informal_name

  # ### Formality
  #
  # The family name is held separately because for most purposes we will address people using the relatively 
  # reliable 'Dr Chan' or 'Mr Smith'.
  #
  def title_ordinary?
    ['Mr', 'Ms', 'Mrs', '', nil].include?(title)
  end
  
  def title_if_it_matters
    title unless title_ordinary?
  end

  def formal_name
    [title, family_name].compact.join(' ')
  end

  # This is our best shot at a representation of how this person would normally be referred to. It combines
  # the informal name (which includes some logic to show chinese, anglo and mixed names correctly) with the title.
  #
  def colloquial_name
    [title, informal_name].compact.join(' ')
  end

  # ### Completeness
  #
  # For record-keeping purposes we show the whole name: <NAME>, Jimmy.
  #
  def whole_name
    [family_name, given_name].compact.join(' ')
  end

  # ### Compatibility
  #
  # An HKID card will normally show only the translitered Chinese name: <NAME>
  #
  def official_name
    chinese, english = given_name.split(/,\s*/)
    [family_name, chinese].join(' ')
  end

end
{'fraction_non_alphanumeric': 0.08002858163629868, 'fraction_numerical': 0.0003572704537334762, 'mean_word_length': 3.185351270553064, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6936021', 'n_tokens_mistral': 831, 'n_tokens_neox': 796, 'n_words': 358}