<commit_before>#encoding: utf-8

class HansardMember
  attr_reader :name, :index_name, :post, :party, :constituency, :search_name, :printed_name, :title
  
  TITLES = /^(Mr |^Ms |^Mrs |^Miss |^Dr |^Sir )/
  
  def initialize(name, search_name="", constituency="", party="", post="")
    @printed_name = name
    if name =~ / Speaker$/
      @search_name = @index_name = name.squeeze(" ").strip
    else
      if search_name == ""
        @search_name = format_search_name(name).squeeze(" ").strip
        @index_name = format_index_name(name).squeeze(" ").strip
      else
        @search_name = name.squeeze(" ").strip
        @index_name = format_index_name(name).squeeze(" ").strip
      end
    end
    @name = name.squeeze(" ").strip
    @constituency = constituency
    @party = party
    @post = post
  end
  
  
  private
  
  def format_search_name(member_name)
    if member_name =~ TITLES
      @title = $1
      parts = member_name.split(" ").reverse
      name = parts.pop
      parts.pop #drop the firstname
      member_name = "#{name} #{parts.reverse.join(" ")}"
    end
    member_name
  end
  
  def format_index_name(member_name)
    if member_name =~ TITLES
      @title = $1
      member_name = member_name.gsub(@title, "").strip
    end
    member_name
  end
end<commit_msg>stripping brackets from member names (HoC 2014-01-07)<commit_after>#encoding: utf-8

class HansardMember
  attr_reader :name, :index_name, :post, :party, :constituency, :search_name, :printed_name, :title
  
  TITLES = /^(Mr |^Ms |^Mrs |^Miss |^Dr |^Sir )/
  
  def initialize(name, search_name="", constituency="", party="", post="")
    @printed_name = name
    if name =~ / Speaker$/
      @search_name = @index_name = name.squeeze(" ").strip
    else
      if search_name == ""
        @search_name = format_search_name(name).squeeze(" ").strip
        @index_name = format_index_name(name).squeeze(" ").strip
      else
        @search_name = name.squeeze(" ").strip
        @index_name = format_index_name(name).squeeze(" ").strip
      end
    end
    @name = name.gsub("(", "").gsub(")", "").squeeze(" ").strip
    @constituency = constituency
    @party = party
    @post = post
  end
  
  
  private
  
  def format_search_name(member_name)
    if member_name =~ TITLES
      @title = $1
      parts = member_name.split(" ").reverse
      name = parts.pop
      parts.pop #drop the firstname
      member_name = "#{name} #{parts.reverse.join(" ")}"
    end
    member_name.gsub("(", "").gsub(")", "")
  end
  
  def format_index_name(member_name)
    if member_name =~ TITLES
      @title = $1
      member_name = member_name.gsub(@title, "").strip
    end
    member_name.gsub("(", "").gsub(")", "")
  end
end
{'fraction_non_alphanumeric': 0.15169366715758467, 'fraction_numerical': 0.005154639175257732, 'mean_word_length': 2.864864864864865, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5252633', 'n_tokens_mistral': 974, 'n_tokens_neox': 954, 'n_words': 209}