当前位置: 首页>>代码示例>>Python>>正文


Python Article.get方法代码示例

本文整理汇总了Python中article.Article.get方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get方法的具体用法?Python Article.get怎么用?Python Article.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在article.Article的用法示例。


在下文中一共展示了Article.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: update_sentiments

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import get [as 别名]
 def update_sentiments(self):
     from watson_developer_cloud import ToneAnalyzerV3Beta
     tone_analyzer = ToneAnalyzerV3Beta(username='03774a07-f588-4619-8801-506d251f384b',
                                password='kkxjxbSSypDJ',
                                version='2016-02-11')
     client = connections.get_connection()
     search = Search(using=client, index='articles', doc_type='article')
     q = Q('bool', must=[Q('missing', field='watson_analyzed')])
     search = search.query(q)
     counter = 0
     for result in search.scan():
         doc = Article.get(result.meta.id)
         try:
             analysis = tone_analyzer.tone(text=doc.body)
             tone_categories = analysis['document_tone']['tone_categories']
             emotion_tones = list(filter(lambda x: x['category_id'] == 'emotion_tone', tone_categories))[0]
             doc.tone = {}
             for tone in emotion_tones['tones']:
                 doc.tone[tone['tone_id']] = tone['score']
             doc.watson_success = True
         except WatsonException:
             continue
         finally:
             doc.watson_analyzed = True
             doc.save()
             counter += 1
         print(counter)
     if counter == 0:
         raise RealError()
开发者ID:dballesteros7,项目名称:alius,代码行数:31,代码来源:database.py

示例2: __init__

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import get [as 别名]
 def __init__(self, user_id, article_id):
     self.user_id = user_id
     es = ElasticStorage.get_instance(dev=False)
     doc = ESArticle.get(article_id)
     self.anger = doc.tone.anger
     self.disgust = doc.tone.disgust
     self.fear = doc.tone.fear
     self.joy = doc.tone.anger
     self.sadness = doc.tone.anger
     self.total_articles = 1
开发者ID:dballesteros7,项目名称:alius,代码行数:12,代码来源:server.py

示例3: post

# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import get [as 别名]
 def post(self):
     user_id = json.loads(request.data.decode('utf-8'))['user_id']
     article_id = json.loads(request.data.decode('utf-8'))['article_id']
     user = Users.query.filter_by(user_id=user_id).first()
     if user:
         es = ElasticStorage.get_instance(dev=False)
         doc = ESArticle.get(article_id)
         user.anger += doc.tone.anger
         user.disgust += doc.tone.disgust
         user.fear += doc.tone.fear
         user.joy += doc.tone.anger
         user.sadness += doc.tone.anger
         user.total_articles += 1
     else:
         u = Users(user_id, article_id)
         db.session.add(u)
     db.session.commit()
     return ('', 204)
开发者ID:dballesteros7,项目名称:alius,代码行数:20,代码来源:server.py


注:本文中的article.Article.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。