<commit_before>class CapitolWord

  class << self
    def construct_url(congress_person, namespace, method, options)
      options = options.dup
      case namespace
      when "lawmaker"
        case method
        when "latest"
          options[:results] ||= 5
          "http://www.capitolwords.org/api/#{namespace}/#{congress_person.bioguide_id}/latest/top#{options[:results]}.json"
        end
      end
    end

    def latest_for(congress_person, options={})
      latest_words = HTTParty.get(construct_url(congress_person, "lawmaker", "latest", options))
      latest_words.map do |latest_word|
        CapitolWord.new(latest_word)
      end
    end
  end

  attr_reader :word, :count

  def initialize(attributes)
    @word  = attributes["word"]
    @count = attributes["word_count"].to_i
  end

  def to_s
    @word
  end
end<commit_msg>Guard against CapitolWords timeout<commit_after>class CapitolWord

  class << self
    def construct_url(congress_person, namespace, method, options)
      options = options.dup
      case namespace
      when "lawmaker"
        case method
        when "latest"
          options[:results] ||= 5
          "http://www.capitolwords.org/api/#{namespace}/#{congress_person.bioguide_id}/latest/top#{options[:results]}.json"
        end
      end
    end

    def latest_for(congress_person, options={})
      begin
        Timeout.timeout(10) do
          latest_words = HTTParty.get(construct_url(congress_person, "lawmaker", "latest", options))
          latest_words.map do |latest_word|
            CapitolWord.new(latest_word)
          end
        end
      rescue OpenURI::HTTPError, Timeout::Error
        []
      end
    end
  end

  attr_reader :word, :count

  def initialize(attributes)
    @word  = attributes["word"]
    @count = attributes["word_count"].to_i
  end

  def to_s
    @word
  end
end
{'fraction_non_alphanumeric': 0.10446957458266021, 'fraction_numerical': 0.002154011847065159, 'mean_word_length': 2.65748031496063, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4781102', 'n_tokens_mistral': 577, 'n_tokens_neox': 565, 'n_words': 120}