本文整理汇总了Python中tag.Tag.normalise方法的典型用法代码示例。如果您正苦于以下问题:Python Tag.normalise方法的具体用法?Python Tag.normalise怎么用?Python Tag.normalise使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tag.Tag
的用法示例。
在下文中一共展示了Tag.normalise方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SetTags
# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import normalise [as 别名]
def SetTags(self, tag_list):
author_tag = Tag.normalise(u"author:%s" % (self.user.username,))
tags = (set([x for x in tag_list if Map.TAG_RE.search(x)][:5])
- Map.RESERVED_TAGS)
old_tags = set(self.tags)
old_tags.discard(author_tag)
new_tags = set(tags)
# Update tag join counts
# These are used for suggestions, so exclude reserved tags
old_tagjoins = set(TagJoin.GetPowerset(list(old_tags - Map.RESERVED_TAGS)[:5]))
new_tagjoins = set(TagJoin.GetPowerset(list(tags)))
new_tags.update(old_tags.intersection(Map.RESERVED_TAGS))
new_tags.add(author_tag)
# Process added tags
modified_tags = []
for tag_name in new_tags - old_tags:
if Tag.normalise(tag_name):
tag = Tag.get_or_insert_tag(tag_name)
tag.count += 1
modified_tags.append(tag)
# Process removed tags
for tag_name in old_tags - new_tags:
if Tag.normalise(tag_name):
tag = Tag.get_or_insert_tag(tag_name)
tag.count -= 1
modified_tags.append(tag)
if modified_tags:
db.put(modified_tags)
# Process modified tagjoins
TagJoin.update_joins(new_tagjoins, old_tagjoins, 20)
self.tags = new_tags
if tag_list:
self.category = tag_list[0]
else:
self.category = None
示例2: GetUserTags
# 需要导入模块: from tag import Tag [as 别名]
# 或者: from tag.Tag import normalise [as 别名]
def GetUserTags(self):
user_tags = set(self.tags - Map.RESERVED_TAGS)
author_tag = Tag.normalise(u"author:%s" % (self.user.username,))
user_tags.discard(author_tag)
return sorted(user_tags)