<commit_before>"""
Module for handling parameters and defaults.

This module is a placeholder for our params/defaults database system
(whatever that ends up being).  Right now it just holds one function.
$Id$
"""


"""
applytuple -- takes in an argument, if its a tuple, it treats it 
                as a function and applies it over the arguments
                otherwise it treats it as a literal
"""

def applytuple(func):
    # print "Called apply tuple on: ", func
    if(type(func) != tuple): 
        return func
    else:
        return (apply(func[0],func[1:]))



def get_param(param_name,dict,default=None):
  """
  Get the named parameter from a dictionary, else return the default.
  """
  if param_name in dict:
    return dict[param_name]
  elif '__defaults__' in dict:
    return get_param(param_name,dict['__defaults__'],default)
  else:
    return default

def setup_params(obj,cls,**params):

  #print "Setting params for ", obj, " of class ", cls
  for var,val in cls.__dict__.items():
    if var[:2] != '__':
      try:
        #print "Trying to set ", var
        obj.__dict__[var] = applytuple(params[var])
        #print "Set ", var, " to ", obj.__dict__[var]
      except KeyError:
        pass
<commit_msg>Change params back to the original.<commit_after>"""
Module for handling parameters and defaults.

This module is a placeholder for our params/defaults database system
(whatever that ends up being).  Right now it just holds one function.
$Id$
"""

def get_param(param_name,dict,default=None):
  """
  Get the named parameter from a dictionary, else return the default.
  """
  if param_name in dict:
    return dict[param_name]
  elif '__defaults__' in dict:
    return get_param(param_name,dict['__defaults__'],default)
  else:
    return default

def setup_params(obj,cls,**params):

  #print "Setting params for ", obj, " of class ", cls
  for var,val in cls.__dict__.items():
    if var[:2] != '__':
      try:
        #print "Trying to set ", var
        obj.__dict__[var] = params[var]
        #print "Set ", var, " to ", obj.__dict__[var]
      except KeyError:
        pass

{'fraction_non_alphanumeric': 0.1110586011342155, 'fraction_numerical': 0.001890359168241966, 'mean_word_length': 3.142857142857143, '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': '1624448', 'n_tokens_mistral': 636, 'n_tokens_neox': 627, 'n_words': 228}