<commit_before>-- Gemeinschaft 5 module: string functions
-- (c) AMOOMA GmbH 2012
-- 

module(...,package.seeall)

function try(array, arguments)
  local argument = arguments:match('^(.-)%.') or arguments;
  local remaining_arguments = arguments:match('%.(.-)$');
  
  if argument and type(array) == 'table' then
    if remaining_arguments then
      if type(array[argument]) == 'table' then
        return try(array[argument], remaining_arguments);
      else
        return nil;
      end
    else
      return array[argument];
    end
  end

  return nil;
end

-- to number
function to_n(value)
  value = tostring(value):gsub('[^%d%.%+%-]', '');
  return tonumber(value) or 0;
end

-- to integer
function to_i(value)
  return math.floor(to_n(value)); 
end

-- to string
function to_s(value)
  if value == nil then<commit_msg>support for numeric keys added<commit_after>-- Gemeinschaft 5 module: string functions
-- (c) AMOOMA GmbH 2012
-- 

module(...,package.seeall)

function try(array, arguments)
  local argument = arguments:match('^(.-)%.') or arguments;
  local remaining_arguments = arguments:match('%.(.-)$');
  argument = tonumber(argument) or argument;
  
  if argument and type(array) == 'table' then
    if remaining_arguments then
      if type(array[argument]) == 'table' then
        return try(array[argument], remaining_arguments);
      else
        return nil;
      end
    else
      return array[argument];
    end
  end

  return nil;
end

-- to number
function to_n(value)
  value = tostring(value):gsub('[^%d%.%+%-]', '');
  return tonumber(value) or 0;
end

-- to integer
function to_i(value)
  return math.floor(to_n(value)); 
end

-- to string
function to_s(value)
  if value == nil then
{'fraction_non_alphanumeric': 0.1420256111757858, 'fraction_numerical': 0.006984866123399301, 'mean_word_length': 3.319095477386935, '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': '6256048', 'n_tokens_mistral': 572, 'n_tokens_neox': 546, 'n_words': 159}