<commit_before>-- Gemeinschaft 5 module: configuration table
-- (c) AMOOMA GmbH 2013
-- 

module(...,package.seeall)

-- retrieve configuration from database
function get(database, entity, section)
  if not database or not entity then
    return {};
  end

  require 'common.str'

  local sql_query = 'SELECT * FROM `gs_parameters` WHERE `entity` = "' .. entity .. '"';
  if section then
    sql_query = sql_query .. ' AND `section` = "' .. section .. '"';
  end

  local root = {}
  local parameter_class = '';

  database:query(sql_query, function(parameters)
    if not root[parameters.section] then
      root[parameters.section] = {};
    end
    parameter_class = tostring(parameters.class_type):lower();

    if parameter_class == 'boolean' then
      root[parameters.section][parameters.name] = common.str.to_b(parameters.value);
    elseif parameter_class == 'integer' then
      root[parameters.section][parameters.name] = common.str.to_i(parameters.value);
    else
      root[parameters.section][parameters.name] = tostring(parameters.value);
    end
  end)

  if section then
    return root[section];
  end
  
  return root;
end<commit_msg>strip whitespace<commit_after>-- Gemeinschaft 5 module: configuration table
-- (c) AMOOMA GmbH 2013
-- 

module(...,package.seeall)

-- retrieve configuration from database
function get(database, entity, section)
  if not database or not entity then
    return {};
  end

  require 'common.str'

  local sql_query = 'SELECT * FROM `gs_parameters` WHERE `entity` = "' .. entity .. '"';
  if section then
    sql_query = sql_query .. ' AND `section` = "' .. section .. '"';
  end

  local root = {}
  local parameter_class = '';

  database:query(sql_query, function(parameters)
    local p_section = common.str.strip(parameters.section):lower();
    local p_class_type = common.str.strip(parameters.class_type):lower();
    local p_name = common.str.strip(parameters.name);

    if not root[p_section] then
      root[p_section] = {};
    end

    if p_class_type == 'boolean' then
      root[p_section][p_name] = common.str.to_b(parameters.value);
    elseif p_class_type == 'integer' then
      root[p_section][p_name] = common.str.to_i(parameters.value);
    else
      root[p_section][p_name] = tostring(parameters.value);
    end
  end)

  if section then
    return root[section];
  end
  
  return root;
end
{'fraction_non_alphanumeric': 0.12801013941698353, 'fraction_numerical': 0.004224757076468103, 'mean_word_length': 3.417910447761194, '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': '6032957', 'n_tokens_mistral': 744, 'n_tokens_neox': 716, 'n_words': 181}