<commit_before>class FactRelation < Basefact
  
  reference :from_fact, Fact
  reference :fact, Fact

  attribute :type # => :supporting || :weakening
  index :type

  def validate
    assert_present :from_fact_id
    assert_present :fact_id
    assert_present :type # TODO check if it's one of the permitted values
  end

  #TODO add proper index for get_or_create
  def FactRelation.get_or_create(from, type, to, user)
    if FactRelation.exists_already?(from,type,to)
      FactRelation.get_relation(from,type,to)
    else
      FactRelation.create_new(from,type,to, user)
    end
  end

  def FactRelation.exists_already?(from,type,to)
    key['gcby'][from.id][type][to.id].exists
  end

  def FactRelation.get_relation(from,type,to)
    id = key['gcby'][from.id][type][to.id].get()
    FactRelation[id]
  end

  def FactRelation.create_new(from,type,to,user)
    fl = FactRelation.create(
      :created_by => user.graph_user,
      :from_fact => from,
      :fact => to,
      :type => type
    )

    #TODO this should use a collection
    to.evidence(type) << fl
    key['gcby'][from.id][type][to.id].set(fl.id)

    fl
  end

  def FactRelation.redis_key(evidence, type, fact)
    "factlink:#{evidence.id}:#{type}:#{fact.id}"
  end

  def evidenced_facts
    [fact]
  end


  def percentage
    if self.fact.get_opinion.weight == 0
      return 0
    else<commit_msg>removed long-unused method<commit_after>class FactRelation < Basefact
  
  reference :from_fact, Fact
  reference :fact, Fact

  attribute :type # => :supporting || :weakening
  index :type

  def validate
    assert_present :from_fact_id
    assert_present :fact_id
    assert_present :type # TODO check if it's one of the permitted values
  end

  #TODO add proper index for get_or_create
  def FactRelation.get_or_create(from, type, to, user)
    if FactRelation.exists_already?(from,type,to)
      FactRelation.get_relation(from,type,to)
    else
      FactRelation.create_new(from,type,to, user)
    end
  end

  def FactRelation.exists_already?(from,type,to)
    key['gcby'][from.id][type][to.id].exists
  end

  def FactRelation.get_relation(from,type,to)
    id = key['gcby'][from.id][type][to.id].get()
    FactRelation[id]
  end

  def FactRelation.create_new(from,type,to,user)
    fl = FactRelation.create(
      :created_by => user.graph_user,
      :from_fact => from,
      :fact => to,
      :type => type
    )

    #TODO this should use a collection
    to.evidence(type) << fl
    key['gcby'][from.id][type][to.id].set(fl.id)

    fl
  end

  def evidenced_facts
    [fact]
  end


  def percentage
    if self.fact.get_opinion.weight == 0
      return 0
    else
{'fraction_non_alphanumeric': 0.11587659894657637, 'fraction_numerical': 0.0015048908954100827, 'mean_word_length': 3.3165584415584415, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, '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': '3935491', 'n_tokens_mistral': 987, 'n_tokens_neox': 928, 'n_words': 201}