<commit_before>class FactGraph
  def self.recalculate
    new.recalculate
  end

  def recalculate
    calculate_authority
    calculate_user_opinions
    calculate_graph
  end

  def calculate_fact_when_user_opinion_changed(fact)
    user_opinion = real_calculate_user_opinion(fact)
    opinion_store.store :Fact, fact.id, :user_opinion, user_opinion

    evidence_opinion = opinion_store.retrieve :Fact, fact.id, :evidence_opinion

    opinion = user_opinion + evidence_opinion
    opinion_store.store :Fact, fact.id, :opinion, opinion
  end

  def calculate_authority
    Authority.run_calculation(authority_calculators)
  end

  def calculate_fact_relation_when_user_opinion_changed(fact_relation)
    user_opinion = real_calculate_user_opinion(fact_relation)
    opinion_store.store :FactRelation, fact_relation.id, :user_opinion, user_opinion
  end

  def user_opinion_for_fact(fact)
    opinion_store.retrieve :Fact, fact.id, :user_opinion
  end

  def user_opinion_for_fact_relation(fact_relation)
    opinion_store.retrieve :FactRelation, fact_relation.id, :user_opinion
  end

  def opinion_for_fact(fact)
    opinion_store.retrieve :Fact, fact.id, :opinion
  end

  private

  def calculate_user_opinions
    Fact.all.each do |fact|
      user_opinion = real_calculate_user_opinion(fact)
      opinion_store.store :Fact, fact.id, :user_opinion, user_opinion
    end

    FactRelation.all.each do |fact_relation|
      user_opinion = real_calculate_user_opinion(fact_relation)
      opinion_store.store :FactRelation, fact_relation.id, :user_opinion, user_opinion
    end
  end

  def calculate_graph
    5.times do |i|
      Fact.all.each do |fact|
        influencing_opinions = fact.fact_relations.all.map do |fact_relation|
          from_fact_opinion = opinion_store.retrieve :Fact, fact_relation.from_fact.id, :opinion
          fr_user_opinion = opinion_store.retrieve :FactRelation, fact_relation.id, :user_opinion
          evidence_type = OpinionType.for_relation_type(fact_relation.type)

          real_calculate_influencing_opinion(from_fact_opinion, fr_user_opinion, evidence_type)
        end

        user_opinion = opinion_store.retrieve :Fact, fact.id, :user_opinion

        evidence_opinion = DeadOpinion.combine(influencing_opinions)
        opinion_store.store :Fact, fact.id, :evidence_opinion, evidence_opinion

        opinion = user_opinion + evidence_opinion
        opinion_store.store :Fact, fact.id, :opinion, opinion<commit_msg>Removed storing and retrieving of opinion<commit_after>class FactGraph
  def self.recalculate
    new.recalculate
  end

  def recalculate
    calculate_authority
    calculate_user_opinions
    calculate_graph
  end

  def calculate_fact_when_user_opinion_changed(fact)
    user_opinion = real_calculate_user_opinion(fact)
    opinion_store.store :Fact, fact.id, :user_opinion, user_opinion
  end

  def calculate_authority
    Authority.run_calculation(authority_calculators)
  end

  def calculate_fact_relation_when_user_opinion_changed(fact_relation)
    user_opinion = real_calculate_user_opinion(fact_relation)
    opinion_store.store :FactRelation, fact_relation.id, :user_opinion, user_opinion
  end

  def user_opinion_for_fact(fact)
    opinion_store.retrieve :Fact, fact.id, :user_opinion
  end

  def user_opinion_for_fact_relation(fact_relation)
    opinion_store.retrieve :FactRelation, fact_relation.id, :user_opinion
  end

  def opinion_for_fact(fact)
    user_opinion = opinion_store.retrieve :Fact, fact.id, :user_opinion
    evidence_opinion = opinion_store.retrieve :Fact, fact.id, :evidence_opinion

    user_opinion + evidence_opinion
  end

  private

  def calculate_user_opinions
    Fact.all.each do |fact|
      user_opinion = real_calculate_user_opinion(fact)
      opinion_store.store :Fact, fact.id, :user_opinion, user_opinion
    end

    FactRelation.all.each do |fact_relation|
      user_opinion = real_calculate_user_opinion(fact_relation)
      opinion_store.store :FactRelation, fact_relation.id, :user_opinion, user_opinion
    end
  end

  def calculate_graph
    5.times do |i|
      Fact.all.each do |fact|
        influencing_opinions = fact.fact_relations.all.map do |fact_relation|
          from_fact_opinion = opinion_for_fact(fact_relation.from_fact)
          user_opinion = opinion_store.retrieve :FactRelation, fact_relation.id, :user_opinion
          evidence_type = OpinionType.for_relation_type(fact_relation.type)

          real_calculate_influencing_opinion(from_fact_opinion, user_opinion, evidence_type)
        end

        evidence_opinion = DeadOpinion.combine(influencing_opinions)
        opinion_store.store :Fact, fact.id, :evidence_opinion, evidence_opinion
{'fraction_non_alphanumeric': 0.06409710391822827, 'fraction_numerical': 0.00042589437819420784, 'mean_word_length': 4.368, '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': '5504587', 'n_tokens_mistral': 1667, 'n_tokens_neox': 1451, 'n_words': 271}