<commit_before>class Channel < OurOhm;end # needed because of removed const_missing from ohm
class Site < OurOhm; end # needed because of removed const_missing from ohm
class FactRelation < OurOhm;end # needed because of removed const_missing from ohm

class Fact < OurOhm
  include Activity::Subject
  include Pavlov::Helpers

  delegate :opinionated_users_ids, :opiniated, :add_opiniated, :remove_opinionateds,
           :people_believes, :people_doubts, :people_disbelieves,
           :to => :believable

  def validate
    assert_present :created_by
  end

  def create
    require_saved_data

    result = super

    add_to_created_facts
    set_own_id_on_saved_data

    result
  end

  reference :created_by, GraphUser
  set :channels, Channel

  def has_site?
    site and site.url and not site.url.blank?
  end

  def to_s
    data.displaystring || ""
  end

  def created_at
    data.created_at.utc.to_s if data
  end

  reference :site, Site # The site on which the factlink should be shown

  reference :data, ->(id) { id && FactData.find(id) }

  def require_saved_data
    return if data_id

    localdata = FactData.new
    localdata.save
    # FactData now has an ID
    self.data = localdata
  end

  def fact_relations
    supporting_facts | weakening_facts
  end

  def evidence(type=:both)
    return fact_relations if type == :both

    send(:"#{type}_facts")
  end

  def add_evidence(type, evidence, user)
    fr = FactRelation.get_or_create(evidence,type,self,user)
    activity(user.graph_user, :"added_#{type}_evidence", evidence, :to, self)
    fr
  end

  def believable
    @believable ||= Believable.new(key)
  end

  def add_opinion(type, user)
    add_opiniated(type,user)
  end

  def remove_opinions(user)
    remove_opinionateds(user)
  end

  #returns whether a given fact should be considered
  #unsuitable for usage/viewing
  def self.invalid(f)
    !f || !f.data_id
  end

  def delete
    fail "Cannot be deleted" unless deletable?

    data.delete
    believable.delete
    remove_from_created_facts
    super
  end

  def deletable?
    opinionated_users_ids - [created_by_id] == [] &&
      supporting_facts.count == 0 &&
      weakening_facts.count  == 0 &&
      FactRelation.find(from_fact_id: id).count == 0<commit_msg>Use similar syntax as for from_fact_id<commit_after>class Channel < OurOhm;end # needed because of removed const_missing from ohm
class Site < OurOhm; end # needed because of removed const_missing from ohm
class FactRelation < OurOhm;end # needed because of removed const_missing from ohm

class Fact < OurOhm
  include Activity::Subject
  include Pavlov::Helpers

  delegate :opinionated_users_ids, :opiniated, :add_opiniated, :remove_opinionateds,
           :people_believes, :people_doubts, :people_disbelieves,
           :to => :believable

  def validate
    assert_present :created_by
  end

  def create
    require_saved_data

    result = super

    add_to_created_facts
    set_own_id_on_saved_data

    result
  end

  reference :created_by, GraphUser
  set :channels, Channel

  def has_site?
    site and site.url and not site.url.blank?
  end

  def to_s
    data.displaystring || ""
  end

  def created_at
    data.created_at.utc.to_s if data
  end

  reference :site, Site # The site on which the factlink should be shown

  reference :data, ->(id) { id && FactData.find(id) }

  def require_saved_data
    return if data_id

    localdata = FactData.new
    localdata.save
    # FactData now has an ID
    self.data = localdata
  end

  def fact_relations
    supporting_facts | weakening_facts
  end

  def evidence(type=:both)
    return fact_relations if type == :both

    send(:"#{type}_facts")
  end

  def add_evidence(type, evidence, user)
    fr = FactRelation.get_or_create(evidence,type,self,user)
    activity(user.graph_user, :"added_#{type}_evidence", evidence, :to, self)
    fr
  end

  def believable
    @believable ||= Believable.new(key)
  end

  def add_opinion(type, user)
    add_opiniated(type,user)
  end

  def remove_opinions(user)
    remove_opinionateds(user)
  end

  #returns whether a given fact should be considered
  #unsuitable for usage/viewing
  def self.invalid(f)
    !f || !f.data_id
  end

  def delete
    fail "Cannot be deleted" unless deletable?

    data.delete
    believable.delete
    remove_from_created_facts
    super
  end

  def deletable?
    opinionated_users_ids - [created_by_id] == [] &&
      FactRelation.find(fact_id: id).count == 0 &&
      FactRelation.find(from_fact_id: id).count == 0
{'fraction_non_alphanumeric': 0.07778757161745262, 'fraction_numerical': 0.0011018069634200088, 'mean_word_length': 3.3812741312741315, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 7, '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': '3486786', 'n_tokens_mistral': 1589, 'n_tokens_neox': 1461, 'n_words': 407}