def append(self, name, id , rank=1): from zkit.fanjian import ftoj name = ftoj(name.decode('utf-8', 'ignore')) ID2NAME = self.ID2NAME if rank is None: rank = 0 value = redis.hget(ID2NAME, id) _append = False if value: value_name, value_rank = value.rsplit('`', 1) if value_name != name: ZSET_CID = self.ZSET_CID CACHE = self.CACHE NAME2ID = self.NAME2ID p = redis.pipeline() for i in self._key(value_name): p.delete(CACHE%i) p.zrem(ZSET_CID%i, id) p.hdel(NAME2ID, value_name) p.execute() _append = True elif int(rank) != int(value_rank): _append = True else: _append = True if _append: if name: self._append(name, id, rank) tag_name = name.replace('`', "'").strip() redis.hset(ID2NAME, id, '%s`%s'%(tag_name, rank)) self._name2id_set(name,id )
def replace_name(name): name = ftoj(name.decode('utf-8')) if type(name) is unicode: name = name.encode('utf-8') name = name.replace('大学', '大').replace('科学技术', '科').replace('中国', '中').replace('师范', '师').replace('科技', '科').replace('交通', '交').replace('财经', '财').replace('工业', '工').replace('北京', '北').replace('科学', '科').replace('农业', '农').decode('utf-8') if name.endswith(u"大") and len(name) > 2: name = name[:-1] return name
def replace_name(name): name = ftoj(name.decode('utf-8')) if type(name) is unicode: name = name.encode('utf-8') name = name.replace('大学', '大').replace('科学技术', '科').replace( '中国', '中').replace('师范', '师').replace('科技', '科').replace('交通', '交').replace( '财经', '财').replace('工业', '工').replace('北京', '北').replace( '科学', '科').replace('农业', '农').decode('utf-8') if name.endswith(u"大") and len(name) > 2: name = name[:-1] return name
def append_alias(self, name, id, rank=1): from zkit.fanjian import ftoj name = ftoj(name.decode('utf-8', 'ignore')) self._append(name, id, rank) self._name2id_set(name,id )