<commit_before># encoding: UTF-8

# Copyright 2012-2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'lockfile'

module Ki

  class DirectoryBase
    attr_chain :parent, :require

    def initialize(path)
      init_from_path(path)
    end

    def self.find!(path, *locations)
      locations.each do |loc|
        dest = loc.go(path)
        if dest.exist?
          return dest
        end
      end
      raise "Could not find '#{path}' from '#{locations.map { |l| l.path }.join("', '")}'"
    end


    def init_from_path(path)
      if path.kind_of?(DirectoryBase)
        @path = path.path
      else
        @path = path
      end
    end

    def name
      File.basename(@path)
    end

    def go(*path)
      if path.empty?
        self
      else
        path = File.join(path).split(File::Separator)
        child = child(path.delete_at(0)).parent(self)
        if path.empty?
          child
        else
          child.go(*path)
        end
      end
    end

    def exist?(*sub_path)
      File.exist?(go(*sub_path).path)
    end

    def mkdir(*path)
      dest = go(*path)
      if !dest.exist?
        FileUtils.mkdir_p(dest.path)
      end
      dest
    end

    def path(*sub_paths)
      new_path = [@path, sub_paths].flatten
      if defined? @parent<commit_msg>DirectoryBase constructor takes DirectoryBase instance as parameter and handles parent<commit_after># encoding: UTF-8

# Copyright 2012-2013 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

require 'lockfile'

module Ki

  class DirectoryBase
    attr_chain :parent, :require

    def initialize(path)
      init_from_path(path)
    end

    def self.find!(path, *locations)
      locations.each do |loc|
        dest = loc.go(path)
        if dest.exist?
          return dest
        end
      end
      raise "Could not find '#{path}' from '#{locations.map { |l| l.path }.join("', '")}'"
    end


    def init_from_path(path)
      if path.kind_of?(DirectoryBase)
        if path.parent
          parent(path.parent)
        end
        @path = path.own_path
      else
        @path = path
      end
    end

    def name
      File.basename(@path)
    end

    def own_path
      @path
    end

    def go(*path)
      if path.empty?
        self
      else
        path = File.join(path).split(File::Separator)
        child = child(path.delete_at(0)).parent(self)
        if path.empty?
          child
        else
          child.go(*path)
        end
      end
    end

    def exist?(*sub_path)
      File.exist?(go(*sub_path).path)
    end

    def mkdir(*path)
      dest = go(*path)
      if !dest.exist?
        FileUtils.mkdir_p(dest.path)
      end
      dest
    end

    def path(*sub_paths)
      new_path = [@path, sub_paths].flatten
      if defined? @parent
{'fraction_non_alphanumeric': 0.09472295514511873, 'fraction_numerical': 0.007387862796833773, 'mean_word_length': 2.2596732588134136, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5081708', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1119, 'n_words': 370}