<commit_before>class CSVDiff

    # Implements the CSV diff algorithm.
    module Algorithm

        # Holds the details of a single difference
        class Diff

            attr_accessor :diff_type
            attr_reader :fields
            attr_reader :row
            attr_reader :sibling_position

            def initialize(diff_type, fields, row_idx, pos_idx)
                @diff_type = diff_type
                @fields = fields
                @row = row_idx + 1
                self.sibling_position = pos_idx
            end


            def sibling_position=(pos_idx)
                if pos_idx.is_a?(Array)
                    pos_idx.compact!
                    if pos_idx.first != pos_idx.last
                        @sibling_position = pos_idx.map{ |pos| pos + 1 }
                    else
                        @sibling_position = pos_idx.first + 1
                    end
                else
                    @sibling_position = pos_idx + 1
                end
            end


            # For backwards compatibility and access to fields with differences
            def [](key)
                case key
                when :action
                    a = diff_type.to_s
                    a[0] = a[0].upcase
                    a
                when :row
                    @row
                when :sibling_position
                    @sibling_position
                else
                    @fields[key]<commit_msg>Support access to diff fields by String or Symbol<commit_after>class CSVDiff

    # Implements the CSV diff algorithm.
    module Algorithm

        # Holds the details of a single difference
        class Diff

            attr_accessor :diff_type
            attr_reader :fields
            attr_reader :row
            attr_reader :sibling_position

            def initialize(diff_type, fields, row_idx, pos_idx)
                @diff_type = diff_type
                @fields = fields
                @row = row_idx + 1
                self.sibling_position = pos_idx
            end


            def sibling_position=(pos_idx)
                if pos_idx.is_a?(Array)
                    pos_idx.compact!
                    if pos_idx.first != pos_idx.last
                        @sibling_position = pos_idx.map{ |pos| pos + 1 }
                    else
                        @sibling_position = pos_idx.first + 1
                    end
                else
                    @sibling_position = pos_idx + 1
                end
            end


            # For backwards compatibility and access to fields with differences
            def [](key)
                case key
                when :action
                    a = diff_type.to_s
                    a[0] = a[0].upcase
                    a
                when :row
                    @row
                when :sibling_position
                    @sibling_position
                else
                    @fields[key] || @fields[key.to_s.intern] || @fields[key.to_s]
{'fraction_non_alphanumeric': 0.05287662121715996, 'fraction_numerical': 0.0039906883937479215, 'mean_word_length': 1.0324324324324323, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2234144', 'n_tokens_mistral': 780, 'n_tokens_neox': 713, 'n_words': 195}