<commit_before>module Neo4jr
  class DelayedCostAccumulator
    include org.neo4j.graphalgo.shortestpath.CostAccumulator

    def initialize
      @disjunct_cost = 1000.0
    end

    def addCosts(o1, o2)
      r1 = o1.relationship
      r2 = o2.relationship
      if r1 and r2
        DelayedCost.new(nil, o1.cost + o2.cost + overlap_cost(r1, r2))
      else
        DelayedCost.new(r1 || r2, o1.cost + o2.cost)
      end
    end

    def overlap_cost r1, r2
#      raise "Cannot add cost for non adjacent paths" unless r1.getEndNode == r2.getEndNode
      days = darr('end_date', r1, r2, true) - darr('start_date', r1, r2, false)
      days > 0 ? 1.0/days : @disjunct_cost
    end

    private
    def darr property, r1, r2, min
      d1 = Date.parse(r1.getProperty(property), true)
      d2 = Date.parse(r2.getProperty(property), true)

      if d1 < d2
          min ? d1 : d2
      else
          min ? d2 : d1
      end
    end
  end
end<commit_msg>cleanup<commit_after>module Neo4jr
  class DelayedCostAccumulator
    include org.neo4j.graphalgo.shortestpath.CostAccumulator

    def initialize
      @disjunct_cost = 1000.0
    end

    def addCosts(o1, o2)
      r1 = o1.relationship
      r2 = o2.relationship
      if r1 and r2
        DelayedCost.new(nil, o1.cost + o2.cost + overlap_cost(r1, r2))
      else
        DelayedCost.new(r1 || r2, o1.cost + o2.cost)
      end
    end

    def overlap_cost r1, r2
      days = darr('end_date', r1, r2, true) - darr('start_date', r1, r2, false)
      days > 0 ? 1.0/days : @disjunct_cost
    end

    private
    def darr property, r1, r2, min
      d1 = Date.parse(r1.getProperty(property), true)
      d2 = Date.parse(r2.getProperty(property), true)

      if d1 < d2
          min ? d1 : d2
      else
          min ? d2 : d1
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.09657836644591611, 'fraction_numerical': 0.04966887417218543, 'mean_word_length': 2.1204819277108435, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '7650549', 'n_tokens_mistral': 710, 'n_tokens_neox': 679, 'n_words': 169}