gallerifrey.py
def readCategoriesOld(images):
    """Reads the category file and returns a pair of tables listing all
relationships, the first by (category -> file set) and the second by
(file -> category set)
"""
    lines = []
    try:
        with open(CATEGORYFILE, 'r') as f:
            lines = [l.strip().split(',') for l in f]
    except IOError:
        # It's okay if the category file doesn't exist.
        pass
    # These dicts are inverses of each other.
    # The key is an image or a category name, and the value is
    # a set of category or image names.
    imagesByCategory = {}
    categoriesByImage = {}
    # The 'all' category contains all images.
    imagesByCategory['all'] = set(images)
    for i in images:
        categoriesByImage[i] = {'all'}
    # We also always have an 'uncategorized' category.
    imagesByCategory['uncategorized'] = set()

    for line in lines:
        image = line[0]
        categories = set(line[1:])
        categories.add('all')
        categoriesByImage[image] = categories
    for (image,categories) in categoriesByImage.iteritems():
        for c in categories:
            if c in imagesByCategory:
                imagesByCategory[c].add(image)
            else:
                imagesByCategory[c] = {image}

    # The 'uncategorized' category contains all images
    # without other defined categories.
    for (image,cats) in categoriesByImage.iteritems():
        num = len(cats)
        if num == 1:
            # Only the 'all' category, add 'uncategorized'
            categoriesByImage[image].add('uncategorized')
            imagesByCategory['uncategorized'].add(image)
        elif num > 2 and 'uncategorized' in cats:
            # We have 'all', 'uncategorized' and something else;
            # remove uncategorized.
            categoriesByImage[image].remove('uncategorized')
            imagesByCategory['uncategorized'].remove(image)

    ibyc = {}
    cbyi = {}
    for (c,i) in imagesByCategory.iteritems():
        l = list(i)
        l.sort()
        ibyc[c] = l
    for (i,c) in categoriesByImage.iteritems():
        l = list(c)
        l.sort()
        cbyi[i] = l
    return (ibyc, cbyi)
Reads the category file and returns a pair of tables listing all
relationships, the first by (category -> file set) and the second by
(file -> category set)

Reads the category file and returns a pair of tables listing all
relationships, the first by (category -> file set) and the second by
(file -> category set)
Reads the category file and returns a pair of tables listing all relationships the first by ( category - > file set ) and the second by ( file - > category set )
def readCategoriesOld(images):
    lines = []
    try:
        with open(CATEGORYFILE, 'r') as f:
            lines = [l.strip().split(',') for l in f]
    except IOError:
        pass
    imagesByCategory = {}
    categoriesByImage = {}
    imagesByCategory['all'] = set(images)
    for i in images:
        categoriesByImage[i] = {'all'}
    imagesByCategory['uncategorized'] = set()
    for line in lines:
        image = line[0]
        categories = set(line[1:])
        categories.add('all')
        categoriesByImage[image] = categories
    for (image,categories) in categoriesByImage.iteritems():
        for c in categories:
            if c in imagesByCategory:
                imagesByCategory[c].add(image)
            else:
                imagesByCategory[c] = {image}
    for (image,cats) in categoriesByImage.iteritems():
        num = len(cats)
        if num == 1:
            categoriesByImage[image].add('uncategorized')
            imagesByCategory['uncategorized'].add(image)
        elif num > 2 and 'uncategorized' in cats:
            categoriesByImage[image].remove('uncategorized')
            imagesByCategory['uncategorized'].remove(image)
    ibyc = {}
    cbyi = {}
    for (c,i) in imagesByCategory.iteritems():
        l = list(i)
        l.sort()
        ibyc[c] = l
    for (i,c) in categoriesByImage.iteritems():
        l = list(c)
        l.sort()
        cbyi[i] = l
    return (ibyc, cbyi)
def readCategoriesOld ( images ) : lines = [ ] try : with open ( CATEGORYFILE , 'r' ) as f : lines = [ l . strip ( ) . split ( ',' ) for l in f ] except IOError : pass imagesByCategory = { } categoriesByImage = { } imagesByCategory [ 'all' ] = set ( images ) for i in images : categoriesByImage [ i ] = { 'all' } imagesByCategory [ 'uncategorized' ] = set ( ) for line in lines : image = line [ 0 ] categories = set ( line [ 1 : ] ) categories . add ( 'all' ) categoriesByImage [ image ] = categories for ( image , categories ) in categoriesByImage . iteritems ( ) : for c in categories : if c in imagesByCategory : imagesByCategory [ c ] . add ( image ) else : imagesByCategory [ c ] = { image } for ( image , cats ) in categoriesByImage . iteritems ( ) : num = len ( cats ) if num == 1 : categoriesByImage [ image ] . add ( 'uncategorized' ) imagesByCategory [ 'uncategorized' ] . add ( image ) elif num > 2 and 'uncategorized' in cats : categoriesByImage [ image ] . remove ( 'uncategorized' ) imagesByCategory [ 'uncategorized' ] . remove ( image ) ibyc = { } cbyi = { } for ( c , i ) in imagesByCategory . iteritems ( ) : l = list ( i ) l . sort ( ) ibyc [ c ] = l for ( i , c ) in categoriesByImage . iteritems ( ) : l = list ( c ) l . sort ( ) cbyi [ i ] = l return ( ibyc , cbyi )
Reads the category file and returns a pair of tables listing all
relationships, the first by (category -> file set) and the second by
(file -> category set)
Reads the category file and returns a pair of tables listing all relationships the first by ( category - > file set ) and the second by ( file - > category set )
"""Reads the category file and returns a pair of tables listing all
relationships, the first by (category -> file set) and the second by
(file -> category set)
""" # It's okay if the category file doesn't exist. # These dicts are inverses of each other. # The key is an image or a category name, and the value is # a set of category or image names. # The 'all' category contains all images. # We also always have an 'uncategorized' category. # The 'uncategorized' category contains all images # without other defined categories. # Only the 'all' category, add 'uncategorized' # We have 'all', 'uncategorized' and something else; # remove uncategorized.
images