feature.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:Treehacks 作者: andrewsy97 项目源码 文件源码
def extract_all(data):
    resp = dict(data)
    # text = get_sanitized(data)
    text = data['text']
    # request feature extraction.
    text_hash = hashlib.sha256(text.encode('ascii', 'ignore')).hexdigest()
    print 'text_hash', text_hash
    cache_db = shelve.open(path.join(CACHE_DIR, 'feature'))
    if not cache_db.has_key(text_hash):
        print 'new call'
        call = alchemyapi.combined('text', text)
        cache_db[text_hash] = call
    else:
        print 'cached call'
        call = cache_db[text_hash]
    cache_db.close()
    # filter results.
    whitelist = ['concepts', 'entities', 'keywords', 'taxonomy']
    for key in whitelist:
        if key not in call:
            resp[key] = []
            continue
        resp[key] = call[key]
    return resp
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号