コード例 #1
0
ファイル: ajax.py プロジェクト: w121211/px1
def autotag_post(request):
    """
    Take a post content as input, find matching tags and return.
    {domain}/api/post/autotag/
    """
    resp = {
        'alert': None,
        'tags': [],
        }

    # Validate post content
    f = PostForm(request.POST)
    if not f.is_valid():
        resp['alert'] = "post title or body is not valid"
        return _response(resp)
    post = f.save(commit=False)

    # get matching tags
    g = TagGraph(_miner)
    g.add_text(post.title)
    g.add_text(post.body)
    #    resp['tags'] = list(g.direct_tags)
    resp['tags'] = g.get_recommend_tags()

    return _response(resp)
コード例 #2
0
ファイル: ajax.py プロジェクト: w121211/noodle
def autotag_post(request):
    """
    Take a post content as input, find matching tags and return.
    {domain}/api/post/autotag/
    """
    try:
        resp = {"alert": None, "tags": []}

        # Validate post content
        f = PostForm(request.POST)
        if not f.is_valid():
            return response_errors(f.errors.as_text())
        post = f.save(commit=False)

        # get matching tags
        g = TagGraph(_miner)
        g.add_text(post.title)
        g.add_text(post.body)
        #    resp['tags'] = list(g.direct_tags)
        resp["tags"] = g.get_recommend_tags()
        return response(resp)
    except Exception as e:
        print e
        traceback.print_exc()
        return response_errors(str(e))