获取此话题的父话题。
        注意：由于没找到有很多父话题的话题来测试，
        所以本方法可能再某些时候出现问题，请不吝反馈。

        :return: 此话题的父话题，返回生成器
        :rtype: Topic.Iterable
547478
def parents(self):
        
        self._make_soup()
        parent_topic_tag = self.soup.find('div', class_='parent-topic')
        if parent_topic_tag is None:
            yield []
        else:
            for topic_tag in parent_topic_tag.find_all('a'):
                yield Topic(Zhihu_URL + topic_tag['href'],
                            topic_tag.text.strip(),
                            session=self._session)
645083
def get_most_relevant_words_for_topic(vocab, rel_mat, topic, n=None):
    
    _check_relevant_words_for_topic_args(vocab, rel_mat, topic)
    return _words_by_score(vocab, rel_mat[topic], least_to_most=False, n=n)
901009
def get_topic(self):
        
        if not hasattr(self, 'topic'):
            self.topic = get_object_or_404(
                Topic.objects.select_related('forum').all(), pk=self.kwargs['pk'],
            )
        return self.topic
317632
def find_topics(token_lists, num_topics=10):
    
    dictionary = Dictionary(token_lists)
    print('Number of unique words in original documents:', len(dictionary))

    dictionary.filter_extremes(no_below=2, no_above=0.7)
    print('Number of unique words after removing rare and common words:', len(dictionary))

    corpus = [dictionary.doc2bow(tokens) for tokens in token_lists]
    model = LdaModel(corpus=corpus, id2word=dictionary, num_topics=num_topics, chunksize=100, passes=5, random_state=1)

    print_topics(model)

    return model, dictionary
464580
def get_component_types_from_topic(topic_id, db_conn=None):
    """"""
    db_conn = db_conn or flask.g.db_conn
    query = sql.select([models.TOPICS]).\
        where(models.TOPICS.c.id == topic_id)
    topic = db_conn.execute(query).fetchone()
    topic = dict(topic)
    return topic['component_types']
238708
def reply_topic(self, topic_id, content):
        
        data = {
            'body': content,
            'csrfmiddlewaretoken': self._request.cookies.get('csrftoken')
        }
        url = 'http://www.shanbay.com/api/v1/forum/thread/%s/post/' % topic_id
        r = self.request(url, 'post', data=data)
        j = r.json()
        if j['status_code'] == 0:
            return j['data']['thread']['id']
1060874
def query(self, query_samples):

        

        self.sampled_topics = np.zeros((self.samples, self.N),
                                       dtype=np.int)

        for s in range(self.samples):            

            self.sampled_topics[s, :] = \
                samplers_lda.sampler_query(self.docid, self.tokens,
                                           self.topic_seed,
                                           np.ascontiguousarray(
                                               self.tt[:, :, s],
                                               dtype=np.float),
                                           self.N, self.K, self.D,
                                           self.alpha, query_samples)

            print("Sample %d queried" % s)

        self.dt = np.zeros((self.D, self.K, self.samples))

        for s in range(self.samples):            
            self.dt[:, :, s] = \
               samplers_lda.dt_comp(self.docid, self.sampled_topics[s, :],
                                    self.N, self.K, self.D, self.alpha)
590551
def get_context_data(self, **kwargs):
        
        context = super().get_context_data(**kwargs)
        context['question'] = self.question
        topic = self.get_object()
        context['forum'] = topic.forum
        return context
1206684
def new_topic(self, title, content):
        
        data = {
            'title': title,
            'body': content,
            'csrfmiddlewaretoken': self._request.cookies.get('csrftoken')
        }
        url = 'http://www.shanbay.com/api/v1/forum/%s/thread/' % self.forum_id()
        r = self.request(url, 'post', data=data)
        j = r.json()
        if j['status_code'] == 0:
            return j['data']['thread']['id']
830892
def iterator(self):
        
        # FIXME: There is no dependency tracking; objects are iterated in
        #        random order.
        for ent_cls in list(self.__entity_set_map.keys()):
            for ent in self.__entity_set_map[ent_cls]:
                yield EntityState.get_state(ent)
1082365
def QA_util_random_with_topic(topic='Acc', lens=8):
    
    _list = [chr(i) for i in range(65,
                                   91)] + [chr(i) for i in range(97,
                                                                 123)
                                          ] + [str(i) for i in range(10)]

    num = random.sample(_list, lens)
    return '{}_{}'.format(topic, ''.join(num))
821976
def questions(self):
        
        from .question import Question
        question_url = Topic_Questions_Url.format(self.id)
        params = {'page': 1}
        older_time_stamp = int(time.time()) * 1000
        while True:
            res = self._session.get(question_url, params=params)
            soup = BeautifulSoup(res.content)
            if soup.find('div', class_='error') is not None:
                return
            questions = soup.find_all('div', class_='question-item')
            questions = list(filter(
                lambda x: int(x.h2.span['data-timestamp']) < older_time_stamp,
                questions))
            for qu_div in questions:
                url = Zhihu_URL + qu_div.h2.a['href']
                title = qu_div.h2.a.text.strip()
                creation_time = datetime.fromtimestamp(
                        int(qu_div.h2.span['data-timestamp']) // 1000)
                yield Question(url, title, creation_time=creation_time,
                               session=self._session)
            older_time_stamp = int(questions[-1].h2.span['data-timestamp'])
            params['page'] += 1
625288
def get_all_topics(region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    cache_key = _cache_get_key()
    try:
        return __context__[cache_key]
    except KeyError:
        pass

    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)
    __context__[cache_key] = {}
    # TODO: support >100 SNS topics (via NextToken)
    topics = conn.get_all_topics()
    for t in topics['ListTopicsResponse']['ListTopicsResult']['Topics']:
        short_name = t['TopicArn'].split(':')[-1]
        __context__[cache_key][short_name] = t['TopicArn']
    return __context__[cache_key]
250990
def get_topic_count(self):
        
        total = 0
        if self.kind == content_kinds.TOPIC or self.kind == "Channel":
            total = 1
            for child in self.children:
                total += child.get_topic_count()
        return total
1088555
def event_from_item(self, sequenced_item):
        
        assert isinstance(sequenced_item, self.sequenced_item_class), (
            self.sequenced_item_class, type(sequenced_item)
        )

        # Get the topic and state.
        topic = getattr(sequenced_item, self.field_names.topic)
        state = getattr(sequenced_item, self.field_names.state)

        return self.event_from_topic_and_state(topic, state)
1076703
def topic(self, channel, topic=None):
        
        with self.lock:
            self.is_in_channel(channel)

            if topic:
                self.send('TOPIC %s :%s' % (channel, topic))
                if self.readable():
                    msg = self._recv(expected_replies=('TOPIC',))
                    if msg[0] == 'TOPIC' and self.hide_called_events:
                        channel = msg[1]
                        self.channels[channel]['TOPIC'] = \
                        msg[2].replace(':', '', 1)
                        if not self.hide_called_events:
                            self.stepback()
            else:
                topic = ''
                set_by = ''
                time_set = ''
                self.send('TOPIC %s' % channel)
                while self.readable():
                    msg = self._recv(expected_replies=('332', '333', '331'))
                    if msg[0] == '332':
                        topic = msg[2].split(':', 1)[1]
                    elif msg[0] == '333':
                        set_by, time_set = msg[2].split()[1:]
                        if self.UTC == False:
                            time_set = self._m_time.localtime(int(time_set))
                        else:
                            time_set = self._m_time.gmtime(int(time_set))
                        set_by = self._from_(set_by)
                    elif msg[0] == '331':
                        topic = ''

                return topic, set_by, time_set
487038
def get_queryset(self):
        
        forums = self.request.forum_permission_handler.get_readable_forums(
            Forum.objects.all(), self.request.user,
        )
        topics = Topic.objects.filter(forum__in=forums)
        topics_pk = map(lambda t: t.pk, track_handler.get_unread_topics(topics, self.request.user))
        return Topic.approved_objects.filter(pk__in=topics_pk).order_by('-last_post_on')