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

module(...,package.seeall)

function try(array, arguments)
  if type(arguments) ~= 'string' or type(array) ~= 'table' then
    return nil;
  end

  local result = array;
  
  arguments:gsub('([^%.]+)', function(entry)
    local success, result = pcall(function() result = (result[tonumber(entry) or entry]); end);
  end);
  
  return result;
end

-- to number
function to_n(value)
  value = tostring(value):gsub('[^%d%.%+%-]', '');
  return tonumber(value) or 0;<commit_msg>set variable function added<commit_after>-- Gemeinschaft 5 module: string functions
-- (c) AMOOMA GmbH 2012-2013
-- 

module(...,package.seeall)

function try(array, arguments)
  if type(arguments) ~= 'string' or type(array) ~= 'table' then
    return nil;
  end

  local result = array;
  
  arguments:gsub('([^%.]+)', function(entry)
    local success, result = pcall(function() result = (result[tonumber(entry) or entry]); end);
  end);
  
  return result;
end


function set(array, arguments, value)
  local nop, arguments_count = arguments:gsub('%.', '');
  local structure = array;
  arguments:gsub('([^%.]+)', function(entry)
    if arguments_count <= 0 then
      structure[entry] = value;
    elseif type(structure[entry]) == 'table' then
      structure = structure[entry];
    else
      structure[entry] = {};
      structure = structure[entry];
    end
    arguments_count = arguments_count - 1;
  end);
end

-- to number
function to_n(value)
  value = tostring(value):gsub('[^%d%.%+%-]', '');
  return tonumber(value) or 0;
{'fraction_non_alphanumeric': 0.16656269494697443, 'fraction_numerical': 0.01372426699937617, 'mean_word_length': 3.8313253012048194, 'pattern_counts': {'":': 0, '<': 4, '<?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': '7574172', 'n_tokens_mistral': 554, 'n_tokens_neox': 527, 'n_words': 141}