示例#1
0
  def to_cache(self):
    for tag in Tag.objects():
      name = tag.name
      parents = getattr(tag, 'parents', [])
      items = tag.get_items()['places']
      self.tags.update({
        name: {
          'parents': parents,
          'items': items
        }
      })

      for item in items:
        if not item['class'] in Tag.mapping:
          continue

        if self.has_slug(item['slug']):
          continue

        obj = Place.get_by_slug(item['slug'], json_format=True)
        if not obj:
          continue

        slug = obj.get('slug', '')
        if not slug:
          continue

        self.items.update({slug: obj})
示例#2
0
  def handle(self, *args, **options):
    if args:
      path = args[0]
    else:
      path = DEFAULT_PATH

    tags = Tag.objects()
    first_line = '名字\t权重\t父标签\t等同于\t对应的元素\n'

    file = open(path, 'w')
    file.write(first_line.encode('utf-8'))
    for tag in tags:
      line = self.do_tag(tag)
      file.write(line)
    file.close()
示例#3
0
 def to_cache(self):
   """
   考虑load的时候通过文件
   """
   for tag in Tag.objects():
     self.add_tag(tag)
示例#4
0
 def _load(self):
   for tag in Tag.objects():
     score = getattr(tag, 'score', settings.NEW_WORD_DEFAULT_VALUE)
     self.add_word(tag.name, score)