我想使用Python来使用AlchemyAPI进行情感分析。
from alchemyapi import AlchemyAPI
alchemyapi = AlchemyAPI()
demo_text = 'I am happy'
alchemyapi.emotion('text', demo_text)给出此错误:
AttributeError: AlchemyAPI instance has no attribute 'emotion'如何进行API调用以检测情绪,如所述的这里

发布于 2016-04-05 11:58:16
请遵循上述所有步骤:
SDK。提示:
mkdir -p ~/src/test
cd ~/src/test
git clone https://github.com/AlchemyAPI/alchemyapi_python.git
cd alchemyapi_python/3.将Python配置为使用API --只需将其配置为使用API:
python alchemyapi.py YOUR_API_KEY4.运行一个简单的示例:
python example.py此时,您应该在终端窗口中获得大量的输出,因为每个函数都被调用,并且输出被解析。
现在,要能够使用AlchemyAPI功能,只需将alchemyapi.py文件复制并粘贴到您的项目中,在将处理文本分析的文件中包括以下几行:
from alchemyapi import AlchemyAPI
alchemyapi = AlchemyAPI()现在您可以使用alchemyapi对象访问任何文本分析函数:
myText = "I'm excited to get started with AlchemyAPI!"
response = alchemyapi.sentiment("text", myText)
print "Sentiment: ", response["docSentiment"]["type"]免责声明:确保您遵循所有这些步骤,以便能够访问API。
https://stackoverflow.com/questions/36425344
复制相似问题