Exemplo n.º 1
0
def subevents():
    """获取子事件信息
    """
    subevents = []
    events = em.getEvents()
    for event in events:
        e = Event(event['_id'])
        subevents.extend(e.getSubEvents())

    results_dict = dict()
    for s in subevents:
        feature = Feature(s['_id'])
        fwords = feature.get_newest()
        words = sorted(fwords.iteritems(), key=lambda (k, v): v,
                       reverse=True)[:5]
        name = ','.join([k for k, v in words])
        subevent = {
            '_id': s['_id'],
            'eventid': str(s['eventid']),
            'name': name
        }
        try:
            results_dict[str(s['eventid'])].append(subevent)
        except KeyError:
            results_dict[str(s['eventid'])] = [subevent]

    return json.dumps(results_dict)
Exemplo n.º 2
0
def subevents():
    """获取子事件信息
    """
    subevents = []
    events = em.getEvents()
    for event in events:
        e = Event(event['_id'])
        subevents.extend(e.getSubEvents())

    results_dict = dict()
    for s in subevents:
        feature = Feature(s['_id'])
        fwords = feature.get_newest()
        words = sorted(fwords.iteritems(), key=lambda(k, v): v, reverse=True)[:5]
        name = ','.join([k for k, v in words])
        subevent = {'_id': s['_id'], 'eventid': str(s['eventid']), 'name': name}
        try:
            results_dict[str(s['eventid'])].append(subevent)
        except KeyError:
            results_dict[str(s['eventid'])] = [subevent]

    return json.dumps(results_dict)
Exemplo n.º 3
0
def opinion_keywords():
    """关键词云数据
    """
    topic_name = request.args.get('query', default_topic_name)  # 话题名
    end_ts = request.args.get('ts', None)
    during = request.args.get('during', None)

    subevent_status = request.args.get('subevent', 'global')
    topk_keywords = request.args.get('topk', 50)  # topk keywords

    if subevent_status != 'global':
        subeventid = subevent_status
        feature = Feature(subeventid)
        counter = Counter()
        counter.update(feature.get_newest())
        top_keywords_count = counter.most_common(topk_keywords)

        subevent_keywords = dict(top_keywords_count)

        return json.dumps(subevent_keywords)
    else:
        topicid = em.getEventIDByName(topic_name)
        event = Event(topicid)
        if end_ts:
            end_ts = int(end_ts)

        if during:
            during = int(during)

        counter = Counter()
        subevents = event.getSubEvents()
        for subevent in subevents:
            feature = Feature(subevent["_id"])
            counter.update(feature.get_newest())

        top_keywords_count = counter.most_common(topk_keywords)

        return json.dumps(dict(top_keywords_count))
Exemplo n.º 4
0
def opinion_keywords():
    """关键词云数据
    """
    topic_name = request.args.get('query', default_topic_name) # 话题名
    end_ts = request.args.get('ts', None)
    during = request.args.get('during', None)

    subevent_status = request.args.get('subevent', 'global')
    topk_keywords = request.args.get('topk', 50) # topk keywords

    if subevent_status != 'global':
        subeventid = subevent_status
        feature = Feature(subeventid)
        counter = Counter()
        counter.update(feature.get_newest())
        top_keywords_count = counter.most_common(topk_keywords)

        subevent_keywords = dict(top_keywords_count)

        return json.dumps(subevent_keywords)
    else:
        topicid = em.getEventIDByName(topic_name)
        event = Event(topicid)
        if end_ts:
            end_ts = int(end_ts)

        if during:
            during = int(during)

        counter = Counter()
        subevents = event.getSubEvents()
        for subevent in subevents:
            feature = Feature(subevent["_id"])
            counter.update(feature.get_newest())

        top_keywords_count = counter.most_common(topk_keywords)

        return json.dumps(dict(top_keywords_count))