Exemplo n.º 1
0
def get_varied_acfg_labels(acfg_list, mainkey='_cfgname', checkname=False):
    """
        >>> from ibeis.expt.annotation_configs import *  # NOQA

    """
    #print(ut.list_str(varied_acfg_list, nl=2))
    for acfg in acfg_list:
        assert acfg['qcfg'][mainkey] == acfg['dcfg'][mainkey], (
            'should be the same for now')
    cfgname_list = [acfg['qcfg'][mainkey] for acfg in acfg_list]
    if checkname and ut.allsame(cfgname_list):
        cfgname_list = [None] * len(cfgname_list)

    # Hack to make common params between q and d appear the same
    _acfg_list = [compress_aidcfg(acfg) for acfg in acfg_list]

    flat_acfg_list = flatten_acfg_list(_acfg_list)
    nonvaried_dict, varied_acfg_list = ut.partition_varied_cfg_list(
        flat_acfg_list)

    SUPER_HACK = True
    if SUPER_HACK:
        # SUPER HACK, recompress remake the varied list after knowing what is varied
        _varied_keys = list(set(ut.flatten(
            [list(ut.flatten(
                [list(x.keys())
                 for x in unflatten_acfgdict(cfg).values()]
            )) for cfg in varied_acfg_list]
        )))
        _acfg_list = [
            compress_aidcfg(acfg, force_noncommon=_varied_keys)
            for acfg in acfg_list]
        flat_acfg_list = flatten_acfg_list(_acfg_list)
        nonvaried_dict, varied_acfg_list = ut.partition_varied_cfg_list(
            flat_acfg_list)

    shortened_cfg_list = [
        #{shorten_to_alias_labels(key): val for key, val in _dict.items()}
        ut.map_dict_keys(shorten_to_alias_labels, _dict)
        for _dict in varied_acfg_list]
    nonlbl_keys = ut.INTERNAL_CFGKEYS
    nonlbl_keys = [prefix +  key for key in nonlbl_keys
                   for prefix in ['', 'q', 'd']]
    # hack for sorting by q/d stuff first

    def get_key_order(cfg):
        keys = [k for k in cfg.keys() if k not in nonlbl_keys]
        sortorder = [2 * k.startswith('q') + 1 * k.startswith('d')
                     for k in keys]
        return ut.sortedby(keys, sortorder)[::-1]

    cfglbl_list = [
        ut.get_cfg_lbl(cfg, name, nonlbl_keys, key_order=get_key_order(cfg))
        for cfg, name in zip(shortened_cfg_list, cfgname_list)]

    if checkname:
        cfglbl_list = [x.lstrip(':') for x in cfglbl_list]
    return cfglbl_list
def compress_acfg_list_for_printing(acfg_list):
    r"""
    CommandLine:
        python -m wbia --tf compress_acfg_list_for_printing

    Ignore:
        >>> from wbia.expt.annotation_configs import *  # NOQA
        >>> qcfg_list = [{'f': 1, 'b': 1}, {'f': 2, 'b': 1}, {'f': 3, 'b': 1, 'z': 4}]
        >>> acfg_list = [{'qcfg': qcfg} for qcfg in qcfg_list]
        >>> nonvaried_dict, varied_dicts = compress_acfg_list_for_printing(acfg_list)
        >>> result = ('varied_dicts = %s\n' % (ut.repr2(varied_dicts),))
        >>> result += ('nonvaried_dict = %s' % (ut.repr2(nonvaried_dict),))
        >>> print(result)
    """
    flat_acfg_list = flatten_acfg_list(acfg_list)
    tup = ut.partition_varied_cfg_list(flat_acfg_list)
    nonvaried_dict, varied_acfg_list = tup
    nonvaried_compressed_dict = compress_aidcfg(
        unflatten_acfgdict(nonvaried_dict), filter_nones=True
    )
    varied_compressed_dict_list = [
        compress_aidcfg(unflatten_acfgdict(cfg), filter_empty=True)
        for cfg in varied_acfg_list
    ]
    return nonvaried_compressed_dict, varied_compressed_dict_list
Exemplo n.º 3
0
def partition_acfg_list(acfg_list):
    for acfg in acfg_list:
        assert acfg['qcfg']['_cfgname'] == acfg['dcfg']['_cfgname'], (
            'should be the same for now')

    # Hack to make common params between q and d appear the same
    _acfg_list = [compress_aidcfg(acfg) for acfg in acfg_list]

    flat_acfg_list = flatten_acfg_list(_acfg_list)
    tup = ut.partition_varied_cfg_list(flat_acfg_list)
    flat_nonvaried_dict, flat_varied_acfg_list = tup
    nonvaried_dict = unflatten_acfgdict(flat_nonvaried_dict)
    varied_acfg_list = [unflatten_acfgdict(acfg)
                        for acfg in flat_varied_acfg_list]
    return nonvaried_dict, varied_acfg_list
def partition_acfg_list(acfg_list):
    for acfg in acfg_list:
        assert (
            acfg['qcfg']['_cfgname'] == acfg['dcfg']['_cfgname']
        ), 'should be the same for now'

    # Hack to make common params between q and d appear the same
    _acfg_list = [compress_aidcfg(acfg) for acfg in acfg_list]

    flat_acfg_list = flatten_acfg_list(_acfg_list)
    tup = ut.partition_varied_cfg_list(flat_acfg_list)
    flat_nonvaried_dict, flat_varied_acfg_list = tup
    nonvaried_dict = unflatten_acfgdict(flat_nonvaried_dict)
    varied_acfg_list = [unflatten_acfgdict(acfg) for acfg in flat_varied_acfg_list]
    return nonvaried_dict, varied_acfg_list
Exemplo n.º 5
0
def compress_acfg_list_for_printing(acfg_list):
    r"""
    CommandLine:
        python -m ibeis --tf compress_acfg_list_for_printing

    Example:
        >>> from ibeis.expt.annotation_configs import *  # NOQA
        >>> qcfg_list = [{'f': 1, 'b': 1}, {'f': 2, 'b': 1}, {'f': 3, 'b': 1, 'z': 4}]
        >>> acfg_list = [{'qcfg': qcfg} for qcfg in qcfg_list]
        >>> nonvaried_dict, varied_dicts = compress_acfg_list_for_printing(acfg_list)
        >>> result = ('varied_dicts = %s\n' % (ut.list_str(varied_dicts),))
        >>> result += ('nonvaried_dict = %s' % (ut.dict_str(nonvaried_dict),))
        >>> print(result)
    """
    flat_acfg_list = flatten_acfg_list(acfg_list)
    tup = ut.partition_varied_cfg_list(flat_acfg_list)
    nonvaried_dict, varied_acfg_list = tup
    nonvaried_compressed_dict = compress_aidcfg(
        unflatten_acfgdict(nonvaried_dict), filter_nones=True)
    varied_compressed_dict_list = [
        compress_aidcfg(unflatten_acfgdict(cfg), filter_empty=True)
        for cfg in varied_acfg_list]
    return nonvaried_compressed_dict, varied_compressed_dict_list
Exemplo n.º 6
0
def get_varied_acfg_labels(acfg_list, mainkey='_cfgname', checkname=False):
    """
        >>> from ibeis.expt.annotation_configs import *  # NOQA

    """
    #print(ut.list_str(varied_acfg_list, nl=2))
    for acfg in acfg_list:
        assert acfg['qcfg'][mainkey] == acfg['dcfg'][mainkey], (
            'should be the same for now')
    cfgname_list = [acfg['qcfg'][mainkey] for acfg in acfg_list]
    if checkname and ut.allsame(cfgname_list):
        cfgname_list = [None] * len(cfgname_list)

    # Hack to make common params between q and d appear the same
    _acfg_list = [compress_aidcfg(acfg) for acfg in acfg_list]

    flat_acfg_list = flatten_acfg_list(_acfg_list)
    nonvaried_dict, varied_acfg_list = ut.partition_varied_cfg_list(
        flat_acfg_list)

    SUPER_HACK = True
    if SUPER_HACK:
        # SUPER HACK, recompress remake the varied list after knowing what is varied
        _varied_keys = list(
            set(
                ut.flatten([
                    list(
                        ut.flatten([
                            list(x.keys())
                            for x in unflatten_acfgdict(cfg).values()
                        ])) for cfg in varied_acfg_list
                ])))
        _acfg_list = [
            compress_aidcfg(acfg, force_noncommon=_varied_keys)
            for acfg in acfg_list
        ]
        flat_acfg_list = flatten_acfg_list(_acfg_list)
        nonvaried_dict, varied_acfg_list = ut.partition_varied_cfg_list(
            flat_acfg_list)

    shortened_cfg_list = [
        #{shorten_to_alias_labels(key): val for key, val in _dict.items()}
        ut.map_dict_keys(shorten_to_alias_labels, _dict)
        for _dict in varied_acfg_list
    ]
    nonlbl_keys = ut.INTERNAL_CFGKEYS
    nonlbl_keys = [
        prefix + key for key in nonlbl_keys for prefix in ['', 'q', 'd']
    ]

    # hack for sorting by q/d stuff first

    def get_key_order(cfg):
        keys = [k for k in cfg.keys() if k not in nonlbl_keys]
        sortorder = [
            2 * k.startswith('q') + 1 * k.startswith('d') for k in keys
        ]
        return ut.sortedby(keys, sortorder)[::-1]

    cfglbl_list = [
        ut.get_cfg_lbl(cfg, name, nonlbl_keys, key_order=get_key_order(cfg))
        for cfg, name in zip(shortened_cfg_list, cfgname_list)
    ]

    if checkname:
        cfglbl_list = [x.lstrip(':') for x in cfglbl_list]
    return cfglbl_list