<commit_before>module ETSource
  class Edge
    include ActiveDocument

    DIRECTORY = 'edges'

    attribute :type,         Symbol
    attribute :parent_share, Float
    attribute :child_share,  Float
    attribute :reversed,     Boolean, default: false
    attribute :query,        String

    validates :supplier, presence: true
    validates :consumer, presence: true
    validates :carrier,  presence: true

    validates :type, inclusion: { in: [ :share, :flexible, :constant,
                                        :inverse_flexible, :dependent ] }

    attr_reader :supplier
    attr_reader :consumer
    attr_reader :carrier

    # Public: The unique key which identifies this edge.
    #
    # This is a combination of the consumer (left node) and the supplier
    # (right node).
    #
    # Returns a Symbol.
    def key
      :"#{ consumer }-#{ supplier }@#{ carrier }"
    end

    # Public: Sets the key of the consumer ("child" or "left") node.
    #
    # consumer - The consumer node key as a string or symbol.
    #
    # Returns the key.
    def consumer=(consumer)
      @consumer = consumer && consumer.to_sym
    end

    # Public: Sets the key of the supplier ("parent" or "right") node.
    #
    # supplier - The supplier node key as a string or symbol.
    #
    # Returns the key.
    def supplier=(supplier)
      @supplier = supplier && supplier.to_sym
    end

    # Public: Sets the name of the carrier; the type of energy which passes
    # through the edge.
    #
    # carrier - The name of the carrier.
    #
    # Returns the key.
    def carrier=(carrier)
      @carrier = carrier && carrier.to_sym
    end

    #######
    private
    #######

    # Internal: Given the name of the ActiveDocument file, without a
    # subclass suffix or file extension, creates a hash of the attributes
    # extracted from the filename.
    #
    # Returns a hash.
    def attributes_from_basename(name)
      if name.nil? || ! name.match(/^[\w_]+-[\w_]+@[\w_]+$/)
        raise InvalidKeyError.new(name)
      end

      values = name.split(/[-@]/).map(&:to_sym)

      Hash[ [:consumer, :supplier, :carrier].zip(values) ]
    end
  end # Edge
end # ETSource<commit_msg>Add Edge.key<commit_after>module ETSource
  class Edge
    include ActiveDocument

    DIRECTORY = 'edges'

    attribute :type,         Symbol
    attribute :parent_share, Float
    attribute :child_share,  Float
    attribute :reversed,     Boolean, default: false
    attribute :query,        String

    validates :supplier, presence: true
    validates :consumer, presence: true
    validates :carrier,  presence: true

    validates :type, inclusion: { in: [ :share, :flexible, :constant,
                                        :inverse_flexible, :dependent ] }

    attr_reader :supplier
    attr_reader :consumer
    attr_reader :carrier

    # Public: The unique key which identifies this edge.
    #
    # This is a combination of the consumer (left node) and the supplier
    # (right node).
    #
    # Returns a Symbol.
    def key
      self.class.key(consumer, supplier, carrier)
    end

    # Public: Sets the key of the consumer ("child" or "left") node.
    #
    # consumer - The consumer node key as a string or symbol.
    #
    # Returns the key.
    def consumer=(consumer)
      @consumer = consumer && consumer.to_sym
    end

    # Public: Sets the key of the supplier ("parent" or "right") node.
    #
    # supplier - The supplier node key as a string or symbol.
    #
    # Returns the key.
    def supplier=(supplier)
      @supplier = supplier && supplier.to_sym
    end

    # Public: Sets the name of the carrier; the type of energy which passes
    # through the edge.
    #
    # carrier - The name of the carrier.
    #
    # Returns the key.
    def carrier=(carrier)
      @carrier = carrier && carrier.to_sym
    end

    # Public: Given +consumer+ and +supplier+ keys, and a +carrier+, returns
    # the key which would be assigned to an edge with those attributes.
    #
    # consumer - The key of the consumer node.
    # supplier - The key of the supplier node.
    # carrier  - The carrier key.
    #
    # Returns a Symbol.
    def self.key(consumer, supplier, carrier)
      :"#{ consumer }-#{ supplier }@#{ carrier }"
    end

    #######
    private
    #######

    # Internal: Given the name of the ActiveDocument file, without a
    # subclass suffix or file extension, creates a hash of the attributes
    # extracted from the filename.
    #
    # Returns a hash.
    def attributes_from_basename(name)
      if name.nil? || ! name.match(/^[\w_]+-[\w_]+@[\w_]+$/)
        raise InvalidKeyError.new(name)
      end

      values = name.split(/[-@]/).map(&:to_sym)

      Hash[ [:consumer, :supplier, :carrier].zip(values) ]
    end

  end # Edge
end # ETSource
{'fraction_non_alphanumeric': 0.10203657522859517, 'fraction_numerical': 0.0, 'mean_word_length': 2.3307958477508652, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3472928', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1364, 'n_words': 495}