DataPipeline/Utilities.py
def parseNames(filenames, ind=0, sep='', match='numeric'):
    """Parse a list of strings to extract a numerical value
       match: whether to match numeric, string or whole word values
       ind: extract the ith instance of a number in the filename
       returns: a dict of the original keys with labels as items
       """

    labels = {}
    if match == 'numeric':
        expr = r'([0-9.]*[0-9]+)'
    elif match == 'text':
        expr = r'[a-z]*[A-Z]+'
    elif match == 'both':
        expr = r'([a-z]*[A-Z]+?)|([0-9.]*[0-9]+?)'
    elif match == 'words':
        expr = r'^\w+'

    #print expr
    r = re.compile(expr,re.I)
    for f in filenames:
        vals = r.findall(f)
        if match == 'both':
            result = []
            for v in vals:
                for i in v:
                    if i != '':
                        result.append(i)
        else:
            result = vals
        labels[f] = result[ind]
        #print result
        #print ind, f, labels[f]
    return labels
Parse a list of strings to extract a numerical value
       match: whether to match numeric, string or whole word values
       ind: extract the ith instance of a number in the filename
       returns: a dict of the original keys with labels as items
       
Parse a list of strings to extract a numerical value
match: whether to match numeric, string or whole word values
ind: extract the ith instance of a number in the filename
returns: a dict of the original keys with labels as items
Parse a list of strings to extract a numerical value match : whether to match numeric string or whole word values ind : extract the ith instance of a number in the filename returns : a dict of the original keys with labels as items
def parseNames(filenames, ind=0, sep='', match='numeric'):
    labels = {}
    if match == 'numeric':
        expr = r'([0-9.]*[0-9]+)'
    elif match == 'text':
        expr = r'[a-z]*[A-Z]+'
    elif match == 'both':
        expr = r'([a-z]*[A-Z]+?)|([0-9.]*[0-9]+?)'
    elif match == 'words':
        expr = r'^\w+'
    r = re.compile(expr,re.I)
    for f in filenames:
        vals = r.findall(f)
        if match == 'both':
            result = []
            for v in vals:
                for i in v:
                    if i != '':
                        result.append(i)
        else:
            result = vals
        labels[f] = result[ind]
    return labels
def parseNames ( filenames , ind = 0 , sep = '' , match = 'numeric' ) : labels = { } if match == 'numeric' : expr = r'([0-9.]*[0-9]+)' elif match == 'text' : expr = r'[a-z]*[A-Z]+' elif match == 'both' : expr = r'([a-z]*[A-Z]+?)|([0-9.]*[0-9]+?)' elif match == 'words' : expr = r'^\w+' r = re . compile ( expr , re . I ) for f in filenames : vals = r . findall ( f ) if match == 'both' : result = [ ] for v in vals : for i in v : if i != '' : result . append ( i ) else : result = vals labels [ f ] = result [ ind ] return labels
Parse a list of strings to extract a numerical value
match: whether to match numeric, string or whole word values
ind: extract the ith instance of a number in the filename
returns: a dict of the original keys with labels as items
Parse a list of strings to extract a numerical value match : whether to match numeric string or whole word values ind : extract the ith instance of a number in the filename returns : a dict of the original keys with labels as items
"""Parse a list of strings to extract a numerical value
       match: whether to match numeric, string or whole word values
       ind: extract the ith instance of a number in the filename
       returns: a dict of the original keys with labels as items
       """ #print expr #print result #print ind, f, labels[f]
filenames
ind
sep
match