示例#1
0
	def translate_tag_ids_to_user_language_map(self, tag_ids, language, session = None) :
		tag_objs = self.db.tags.find({'id': {'$in': tag_ids}}, session = session)
		tagid_to_tag_map = {}
		for obj in tag_objs :
			tag_in_user_language = translateTagToPreferredLanguage(obj, language)
			tagid_to_tag_map[obj['id']] = tag_in_user_language
		return tagid_to_tag_map
示例#2
0
	def translate_tag_ids_to_user_language_with_count(self, tag_ids, language, session = None) :
		tag_objs = self.db.tags.find({'id': {'$in': tag_ids}}, session = session)
		category_tag_map = defaultdict(list)
		tag_category_map = {}
		tags = []
		for obj in tag_objs :
			tag_in_user_language = translateTagToPreferredLanguage(obj, language)
			tags.append({'tag': tag_in_user_language, 'count': obj['count']})
			category_tag_map[obj['category']].append(tag_in_user_language)
			tag_category_map[tag_in_user_language] = obj['category']
		return tags, category_tag_map, tag_category_map
示例#3
0
	def translate_tag_ids_to_user_language(self, tag_ids, language, session = None, id_data_map = None) :
		tag_objs = self.db.tags.find({'id': {'$in': tag_ids}}, session = session)
		category_tag_map = defaultdict(list)
		tag_category_map = {}
		tags = []
		for obj in tag_objs :
			tag_in_user_language = translateTagToPreferredLanguage(obj, language)
			if id_data_map :
				tags.append((tag_in_user_language, id_data_map[str(obj['id'])]))
			else :
				tags.append(tag_in_user_language)
			category_tag_map[obj['category']].append(tag_in_user_language)
			tag_category_map[tag_in_user_language] = obj['category']
		return tags, category_tag_map, tag_category_map
示例#4
0
	def retrive_item_with_tag_category_map(self, tag_query_or_item_id, language, session = None) :
		if isinstance(tag_query_or_item_id, ObjectId) or isinstance(tag_query_or_item_id, str):
			item_obj = self.db.items.find_one({'_id': ObjectId(tag_query_or_item_id)}, session = session)
		elif isinstance(tag_query_or_item_id, dict) :
			item_obj = tag_query_or_item_id
		else:
			item_obj = self.db.items.find_one(tag_query_or_item_id, session = session)
		if item_obj is None :
			raise UserError('ITEM_NOT_EXIST')
		tag_objs = self.db.tags.find({'id': {'$in': item_obj['tags']}}, session = session)
		category_tag_map = defaultdict(list)
		tag_category_map = {}
		tags = []
		for obj in tag_objs :
			tag_in_user_language = translateTagToPreferredLanguage(obj, language)
			tags.append(tag_in_user_language)
			category_tag_map[obj['category']].append(tag_in_user_language)
			tag_category_map[tag_in_user_language] = obj['category']
		return item_obj, tags, category_tag_map, tag_category_map