Gavagai API帮助程序库。
Gavagai的Python项目详细描述
一个Gavagaiapi帮助程序库。
安装
$ pip install gavagai
API键
在Gavagai Developer Portal免费获取自己的api密钥。
在实例化客户机时可以指定api密钥,请参见示例 下面。或者,您可以设置gavagai_apikey环境 变量,只需调用GavagaiClient()。
API方法
此版本支持的gavagai rest api方法:
- /keywords-从 文本。
- /lexicon-在Gavagai Living Lexicon中查找单词。
- /tonality-多维情绪分析。
- /topics&;/stories-多文本摘要:获取 你的文本集的要点不必阅读每一个 一句话。
使用
见Gavagai API documentation 有关可用API资源的详细信息。
示例:对一组文本的api调用
/keywords资源从集合中提取突出的概念 文本。按出现次数排序。
fromgavagai.clientimportGavagaiClientfrompprintimportpprinttexts=['Stayed here for 3 nights at the beginning of a trip of California. Could not say enough good things about the hotel Monaco. Amazing staff, amazing rooms and the location is brilliant! First stay at a Kimpton hotel, but definitely not the last!!!','I did a lot of research looking for a hotel suite for our family vacation in San Francisco. The Hotel Monaco was a perfect choice. What friendly and delightful staff. I will miss the Grand Cafe, but I will make sure to come back to see their new offerings.','My partner and I spent four nights here over New Years and loved it. Super staff; lovely, quiet room; excellent location within easy walking to much of Downtown and an overall experience that was perfect.']client=GavagaiClient('use_your_own_api_key')result=client.keywords(texts)keywords=result.json()pprint(keywords)
示例:指定语言
的api调用/tonality资源测量多维情绪,基于 词汇分析。默认语言为英语,但对于其他语言的文本 语言,应指定语言选项。
romgavagai.clientimportGavagaiClientfrompprintimportpprinttexts=[u'Din idiot!',u'Jag älskar dig.',u'Hen hatar det.']client=GavagaiClient('use_your_own_api_key')result=client.tonality(texts,language='sv')# swedish language optionkeywords=result.json()pprint(keywords)
为开发而设置
来自此存储库的根目录:
$ pip install -r requirements.txt
运行测试
$ py.test
释放
我用zest.releaser来释放这个包。