:param cat_id_arr:   list of categories. ['0101', '0102']
502069
def __query_with_label(cat_id_arr, label=None, num=8, kind='1'):
        '''
        
        '''
        return TabPost.select().join(
            TabPost2Tag,
            on=(TabPost.uid == TabPost2Tag.post_id)
        ).where(
            (TabPost.kind == kind) &
            (TabPost2Tag.tag_id << cat_id_arr) &  # the "<<" operator signifies an "IN" query
            (TabPost.extinfo['def_tag_arr'].contains(label))
        ).order_by(
            TabPost.time_create.desc()
        ).limit(num)
665766
def array_dim(arr):
    
    dim = []
    while True:
        try:
            dim.append(len(arr))
            arr = arr[0]
        except TypeError:
            return dim
1365793
def update_category(uid, post_data):
    '''
    
    '''

    # deprecated
    # catid = kwargs['catid'] if MCategory.get_by_uid(kwargs.get('catid')) else None
    # post_data = self.get_post_data()
    if 'gcat0' in post_data:
        pass
    else:
        return False

    # Used to update MPost2Category, to keep order.
    the_cats_arr = []
    # Used to update post extinfo.
    the_cats_dict = {}

    # for old page. deprecated
    # def_cate_arr.append('def_cat_uid')

    def_cate_arr = ['gcat{0}'.format(x) for x in range(10)]
    for key in def_cate_arr:
        if key not in post_data:
            continue
        if post_data[key] == '' or post_data[key] == '0':
            continue
        # 有可能选重复了。保留前面的
        if post_data[key] in the_cats_arr:
            continue

        the_cats_arr.append(post_data[key] + ' ' * (4 - len(post_data[key])))
        the_cats_dict[key] = post_data[key] + ' ' * (4 - len(post_data[key]))

    # if catid:
    #     def_cat_id = catid
    if the_cats_arr:
        def_cat_id = the_cats_arr[0]
    else:
        def_cat_id = None

    if def_cat_id:
        the_cats_dict['gcat0'] = def_cat_id
        the_cats_dict['def_cat_uid'] = def_cat_id
        the_cats_dict['def_cat_pid'] = MCategory.get_by_uid(def_cat_id).pid

    # Add the category
    logger.info('Update category: {0}'.format(the_cats_arr))
    logger.info('Update category: {0}'.format(the_cats_dict))

    MPost.update_jsonb(uid, the_cats_dict)

    for index, idx_catid in enumerate(the_cats_arr):
        MPost2Catalog.add_record(uid, idx_catid, index)

    # Delete the old category if not in post requests.
    current_infos = MPost2Catalog.query_by_entity_uid(uid, kind='').objects()
    for cur_info in current_infos:
        if cur_info.tag_id not in the_cats_arr:
            MPost2Catalog.remove_relation(uid, cur_info.tag_id)
693944
def update_count(cat_id):
        '''
        
        '''
        # Todo: the record not valid should not be counted.
        entry2 = TabTag.update(
            count=TabPost2Tag.select().where(
                TabPost2Tag.tag_id == cat_id
            ).count()
        ).where(TabTag.uid == cat_id)
        entry2.execute()
1076963
def cat(self):
        
        categories = self._series.categories

        if categories.are_numeric:
            return parse_xml(
                self._numRef_cat_tmpl.format(**{
                    'wksht_ref':     self._series.categories_ref,
                    'number_format': categories.number_format,
                    'cat_count':     categories.leaf_count,
                    'cat_pt_xml':    self._cat_num_pt_xml,
                    'nsdecls':       ' %s' % nsdecls('c'),
                })
            )

        if categories.depth == 1:
            return parse_xml(
                self._cat_tmpl.format(**{
                    'wksht_ref':  self._series.categories_ref,
                    'cat_count':  categories.leaf_count,
                    'cat_pt_xml': self._cat_pt_xml,
                    'nsdecls':    ' %s' % nsdecls('c'),
                })
            )

        return parse_xml(
            self._multiLvl_cat_tmpl.format(**{
                'wksht_ref': self._series.categories_ref,
                'cat_count': categories.leaf_count,
                'lvl_xml':   self._lvl_xml(categories),
                'nsdecls':   ' %s' % nsdecls('c'),
            })
        )
914353
def unique_categories(categories):
    """"""
    categories = np.unique(categories)
    categories = np.setdiff1d(categories, np.array(settings.categories_to_ignore))
    categories = np.array(natsorted(categories, key=lambda v: v.upper()))
    return categories
321297
def get_category(category_string, model=Category):
    
    model_class = get_cat_model(model)
    category = str(category_string).strip("'\"")
    category = category.strip('/')

    cat_list = category.split('/')
    if len(cat_list) == 0:
        return None
    try:
        categories = model_class.objects.filter(name=cat_list[-1], level=len(cat_list) - 1)
        if len(cat_list) == 1 and len(categories) > 1:
            return None
        # If there is only one, use it. If there is more than one, check
        # if the parent matches the parent passed in the string
        if len(categories) == 1:
            return categories[0]
        else:
            for item in categories:
                if item.parent.name == cat_list[-2]:
                    return item
    except model_class.DoesNotExist:
        return None
309868
def search_cat(self, catid, keyword, p_index=1):
        '''
        
        '''
        catid = 'sid' + catid
        logger.info('-' * 20)
        logger.info('search cat')
        logger.info('catid: {0}'.format(catid))
        logger.info('keyword: {0}'.format(keyword))

        # catid = ''
        if p_index == '' or p_index == '-1':
            current_page_number = 1
        else:
            current_page_number = int(p_index)
        res_all = self.ysearch.get_all_num(keyword, catid=catid)

        results = self.ysearch.search_pager(
            keyword,
            catid=catid,
            page_index=current_page_number,
            doc_per_page=CMS_CFG['list_num']
        )
        page_num = int(res_all / CMS_CFG['list_num'])

        kwd = {'title': '查找结果',
               'pager': '',
               'count': res_all,
               'current_page': current_page_number,
               'catid': catid,
               'keyword': keyword}

        self.render('misc/search/search_list.html',
                    kwd=kwd,
                    srecs=results,
                    pager=gen_pager_bootstrap_url(
                        '/search/{0}/{1}'.format(catid, keyword),
                        page_num,
                        current_page_number
                    ),
                    userinfo=self.userinfo,
                    cfg=CMS_CFG)
173342
def series2cat(df:DataFrame, *col_names):
    ""
    for c in listify(col_names): df[c] = df[c].astype('category').cat.as_ordered()
454779
def get_netid_categories(netid, category_codes):
    
    url = _netid_category_url(netid, category_codes)
    response = get_resource(url)
    return _json_to_categories(response)
1318483
def categories(self):
        
        r = [ch for ch in self._channels.values() if isinstance(ch, CategoryChannel)]
        r.sort(key=lambda c: (c.position, c.id))
        return r
1125048
def loadCats(self, ids=[]):
        
        if type(ids) == list:
            return [self.cats[id] for id in ids]
        elif type(ids) == int:
            return [self.cats[ids]]
83901
def catalog_object_id(self, catalog_object_id):
        

        if catalog_object_id is None:
            raise ValueError("Invalid value for `catalog_object_id`, must not be `None`")
        if len(catalog_object_id) > 192:
            raise ValueError("Invalid value for `catalog_object_id`, length must be less than `192`")

        self._catalog_object_id = catalog_object_id
1062936
private static String list(String[] arr, int from, int len) {
	StringBuffer sb = new StringBuffer();
	for (int i = from; i < len; i++) {
	    sb.append(arr[i]);
	    if (i + 1 != arr.length) sb.append('/');
	}
	return sb.toString();
    }
664151
def getImgIds(self, imgIds=[], catIds=[]):
        '''
        
        '''
        imgIds = imgIds if _isArrayLike(imgIds) else [imgIds]
        catIds = catIds if _isArrayLike(catIds) else [catIds]

        if len(imgIds) == len(catIds) == 0:
            ids = self.imgs.keys()
        else:
            ids = set(imgIds)
            for i, catId in enumerate(catIds):
                if i == 0 and len(ids) == 0:
                    ids = set(self.catToImgs[catId])
                else:
                    ids &= set(self.catToImgs[catId])
        return list(ids)
354957
def category(msg):
    

    if common.typecode(msg) < 1 or common.typecode(msg) > 4:
        raise RuntimeError("%s: Not a identification message" % msg)

    msgbin = common.hex2bin(msg)
    return common.bin2int(msgbin[5:8])
1051292
def fetch_additional_posts(self, uid):
        '''
        
        '''
        cats = MPost2Catalog.query_by_entity_uid(uid, kind=self.kind)
        cat_uid_arr = []
        for cat_rec in cats:
            cat_uid = cat_rec.tag_id
            cat_uid_arr.append(cat_uid)
        logger.info('info category: {0}'.format(cat_uid_arr))
        rel_recs = MRelation.get_app_relations(uid, 8, kind=self.kind).objects()

        logger.info('rel_recs count: {0}'.format(rel_recs.count()))
        if cat_uid_arr:
            rand_recs = MPost.query_cat_random(cat_uid_arr[0], limit=4 - rel_recs.count() + 4)
        else:
            rand_recs = MPost.query_random(num=4 - rel_recs.count() + 4, kind=self.kind)
        return rand_recs, rel_recs