from string import punctuation
import re


def normalize_text(text, method='str'):  
    """
    Parameters
    ----------
    text : str
    method : {'str', 'regex'}, default 'str'
        str: cleans digits and puntuations only ('!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~')
        regex : clean digits and all special characters 
        
    Returns
    -------
    text : str
    """
    
    # Conver to lower case
    text = text.lower()
        
    if method=='str':    
        # Remove digits
        text = ''.join(c for c in text if not c.isdigit())            
        # Remove punctuation
        text = ''.join(c for c in text if c not in punctuation)        
        # Remove extra spaces
        text = " ".join(text.split())
    
    elif method=='regex':
        # Remove digits
        text = re.sub(r'\d+', ' ', text) 
        # Remove all special characters
        text = re.sub(r'\W+', ' ', text) 
        # Remove extra spaces
        text = re.sub('\s\s+', ' ', text)
        
    return text