<commit_before>require 'faraday'
require 'json'

class Discussion
  def self.of_articles(articles)
    articles.map { |article|
      self.for(article).map { |discussion|
        discussion.article = article
        discussion
      }
    }.flatten
  end

  def self.for(article)
    article.identifier_strings.map do |identifier_string|
      for_identifier(identifier_string)
    end.flatten.uniq_by(&:url)
  end

  def self.for_identifier(identifier_string)
    url = "#{JOURNAL_CLUB_ENGINE_URL}/discussions.json?query=#{CGI.escape(identifier_string)}"
    response = get_http(url)
    discussion_hashes = JSON.parse(response.body)
    discussion_hashes.map { |hash| self.new(hash) }
  end

  attr_accessor :article

  def initialize(attributes)
    @attributes = attributes
  end

  def title
    "Discussion on #{hostname}"
  end

  def url
    @attributes["url"]
  end

  def identifier_strings
    @attributes["identifier_strings"] || []
  end

  private

  def hostname
    Addressable::URI.parse(url).host
  end

  def self.get_http(url)
    Faraday.get(url)
  end
end<commit_msg>Show actual discussion title<commit_after>require 'faraday'
require 'json'

class Discussion
  def self.of_articles(articles)
    articles.map { |article|
      self.for(article).map { |discussion|
        discussion.article = article
        discussion
      }
    }.flatten
  end

  def self.for(article)
    article.identifier_strings.map do |identifier_string|
      for_identifier(identifier_string)
    end.flatten.uniq_by(&:url)
  end

  def self.for_identifier(identifier_string)
    url = "#{JOURNAL_CLUB_ENGINE_URL}/discussions.json?query=#{CGI.escape(identifier_string)}"
    response = get_http(url)
    discussion_hashes = JSON.parse(response.body)
    discussion_hashes.map { |hash| self.new(hash) }
  end

  attr_accessor :article

  def initialize(attributes)
    @attributes = attributes
  end

  def title
    @attributes["title"]
  end

  def url
    @attributes["url"]
  end

  def identifier_strings
    @attributes["identifier_strings"] || []
  end

  private

  def hostname
    Addressable::URI.parse(url).host
  end

  def self.get_http(url)
    Faraday.get(url)
  end
end
{'fraction_non_alphanumeric': 0.10247026532479414, 'fraction_numerical': 0.0, 'mean_word_length': 3.4815573770491803, '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': '870083', 'n_tokens_mistral': 732, 'n_tokens_neox': 695, 'n_words': 136}