<commit_before>-- Overall Configuration
-- =====================

-- This module returns an object describing the overall configuration.
-- It tries to load files named `cosy.json` or `cosy.yaml` located in directories
-- listed in `Platform.configuration.paths` (in order).
--
-- All the found configurations are merged to obtain the result. It allows to
-- preset some configuration variables system-wide.

local Platform  = require "cosy.platform"

local Configuration = {}

-- This function imports the `source` table inside the `target` one.
local function import (source, target)
  assert (type (source) == "table")
  assert (type (target) == "table")
  for k, v in pairs (source) do
    if type (v) == "table" then
      if target [k] == nil then
        target [k] = v
      else
        import (v, target [k])
      end
    else
      target [k] = v
    end
  end
end

for _, path in ipairs (Platform.configuration.paths) do
  local found = false
  for name, loader in pairs {
    ["cosy.yaml"] = Platform.yaml.decode,
    ["cosy.json"] = Platform.json.decode,
  } do
    local content = Platform.configuration.read (path .. "/" .. name)
    if content then
      -- If a directory contains both `cosy.json` and `cosy.yaml` files, an error is raised
      -- as there is no way to known which one should be used.
      if found then
        Platform.logger.error {
          "configuration_conflict",
          path = path,
        }
        error "Invalid configuration"
      end
      import (loader (content), Configuration)
      found = true
      Platform.logger.debug {
        "configuration_using",
        path = path,
      }
    end
  end
end

return Configuration<commit_msg>Namespace i18n messages.<commit_after>-- Overall Configuration
-- =====================

-- This module returns an object describing the overall configuration.
-- It tries to load files named `cosy.json` or `cosy.yaml` located in directories
-- listed in `Platform.configuration.paths` (in order).
--
-- All the found configurations are merged to obtain the result. It allows to
-- preset some configuration variables system-wide.

local Platform  = require "cosy.platform"

local Configuration = {}

-- This function imports the `source` table inside the `target` one.
local function import (source, target)
  assert (type (source) == "table")
  assert (type (target) == "table")
  for k, v in pairs (source) do
    if type (v) == "table" then
      if target [k] == nil then
        target [k] = v
      else
        import (v, target [k])
      end
    else
      target [k] = v
    end
  end
end

for _, path in ipairs (Platform.configuration.paths) do
  local found = false
  for name, loader in pairs {
    ["cosy.yaml"] = Platform.yaml.decode,
    ["cosy.json"] = Platform.json.decode,
  } do
    local content = Platform.configuration.read (path .. "/" .. name)
    if content then
      -- If a directory contains both `cosy.json` and `cosy.yaml` files, an error is raised
      -- as there is no way to known which one should be used.
      if found then
        Platform.logger.error {
          "configuration:conflict",
          path = path,
        }
        error "Invalid configuration"
      end
      import (loader (content), Configuration)
      found = true
      Platform.logger.debug {
        "configuration:using",
        path = path,
      }
    end
  end
end

return Configuration
{'fraction_non_alphanumeric': 0.11300264162019372, 'fraction_numerical': 0.000587026709715292, 'mean_word_length': 2.527950310559006, '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': '784964', 'n_tokens_mistral': 940, 'n_tokens_neox': 934, 'n_words': 375}