<commit_before>module BeliefExpressions
  def b(user,fact)
    fact.add_opinion(:beliefs,user.graph_user)
  end

  def d(user,fact)
    fact.add_opinion(:disbeliefs,user.graph_user)
  end

  def u(user,fact)
    fact.add_opinion(:doubts,user.graph_user)
  end

  def _(b,d,u,a)
    Opinion.new(:b=>b,:d=>d,:u=>u,:a=>a)
  end

  def a(user)
    FactGraph.reset_values
    FactGraph.recalculate
    GraphUser[user.graph_user.id].authority.to_f.should
  end

  def opinion?(fact)
    FactGraph.reset_values
    FactGraph.recalculate
    # values are recalculated in Redis, so get the object fresh from Redis
    fact = fact.class[fact.id]
    fact.get_opinion.should
  end
end<commit_msg>only recalculate once<commit_after>module BeliefExpressions
  def b(user,fact)
    something_happened
    fact.add_opinion(:beliefs,user.graph_user)
  end

  def d(user,fact)
    something_happened
    fact.add_opinion(:disbeliefs,user.graph_user)
  end

  def u(user,fact)
    something_happened
    fact.add_opinion(:doubts,user.graph_user)
  end

  def _(b,d,u,a)
    Opinion.new(:b=>b,:d=>d,:u=>u,:a=>a)
  end

  def possible_reset
    unless @nothing_happened
      FactGraph.reset_values
      FactGraph.recalculate
      @nothing_happened = true
    end
  end

  def something_happened
    @nothing_happened = false
  end

  def a(user)
    GraphUser[user.graph_user.id].authority.to_f.should
  end

  def opinion?(fact)
    possible_reset
    # values are recalculated in Redis, so get the object fresh from Redis
    fact = fact.class[fact.id]
    fact.get_opinion.should
  end
end
{'fraction_non_alphanumeric': 0.10095238095238095, 'fraction_numerical': 0.0, 'mean_word_length': 3.5813953488372094, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '5435289', 'n_tokens_mistral': 628, 'n_tokens_neox': 576, 'n_words': 106}