Esempio n. 1
0
def new_microblog():
    form = MicroblogForm()

    if form.validate_on_submit():
        microblog = Microblog(body=form.microblog.data,author=current_user)
        db.session.add(microblog)
        db.session.commit()
        flash('Your microblog is now live!')
        return redirect(url_for('main.new_microblog'))

    page = request.args.get('page',1,type=int)
    pagination = current_user.followed_microblogs().paginate(
        page,current_app.config['POSTS_PER_PAGE'])
    microblogs = pagination.items
    return render_template('microblog/new_microblog.html',form=form, microblogs=microblogs, pagination=pagination)
Esempio n. 2
0
def test_feature():
    microblogId, microblog_text, polarity = "234", "我不喜欢你, 你这个愚昧的家伙,脑子有毛病", 1
    feature_extracter = FeatureExtractor()
    words, taggings = feature_extracter.pos_tagging(microblog_text)
    posCount, negCount = feature_extracter.polarity_count(microblog_text)
    single_microblog = Microblog(microblogId=microblogId,
                                 text=microblog_text,
                                 polarity=polarity,
                                 negCount=negCount,
                                 posCount=posCount,
                                 words=words,
                                 taggings=taggings,
                                 microblogType=1,
                                 topic=None,
                                 sentiment=None)
    single_microblog.save()
Esempio n. 3
0
def complete_microblog():
    microblogs = Microblog.objects(polarity='pos', microblogType='training')
    print(len(microblogs))
    new_microblogs = []
    for microblog in microblogs:
        newone = Microblog(microblogId=microblog.microblogId,
                           text=microblog.text,
                           polarity=microblog.polarity,
                           negCount=microblog.negCount,
                           posCount=microblog.posCount,
                           words=microblog.words,
                           taggings=microblog.taggings,
                           microblogType=microblog.microblogType,
                           topic='',
                           sentiment='')
        new_microblogs.append(newone)
    Microblog.objects.insert(new_microblogs)
Esempio n. 4
0
def microblog_data_handler(microblog_type):

    data_filter = DataFilter()
    microblogs = data_filter.read_and_filter_api_microblog_data(microblog_type)

    result = []

    feature_extractor = FeatureExtractor()
    for polarity in microblogs:
        microblog_list = microblogs[polarity]
        for microblog in microblog_list:

            #feature extractor
            microblogId, microblog_raw_text, microblog_text, polarity = microblog[
                0], microblog[1], microblog[2], microblog[3]
            posCount, negCount = feature_extractor.polarity_count(
                microblog_text)
            words, taggings = feature_extractor.pos_tagging(microblog_text)
            raw_words, raw_taggings = feature_extractor.pos_tagging(
                microblog_raw_text)

            single_microblog = Microblog(microblogId=microblogId,
                                         text=microblog_text,
                                         polarity=polarity,
                                         microblogType=microblog_type,
                                         topic='',
                                         posCount=posCount,
                                         negCount=negCount,
                                         words=words,
                                         taggings=taggings,
                                         raw_words=raw_words,
                                         raw_taggings=raw_taggings,
                                         sentiment='')

            result.append(single_microblog)

    return result