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
评论列表
文章目录