Advertisement
Guest User

skill

a guest
Mar 26th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.37 KB | None | 0 0
  1. from __future__ import unicode_literals
  2. from sberbot.core.service import SkillService
  3. from yargy import Parser, rule
  4. from yargy.predicates import dictionary
  5. import requests
  6.  
  7.  
  8.  
  9.  
  10. class Headortail(SkillService):
  11.     #def __init__(self, host, port, app_name):
  12.         #super(SkillService, self).__init__(host, port, app_name)
  13.         #self.headortail = Parser(self.head_rule())
  14.        
  15.     def __call__(self, utterances_batch, states_batch=None, history_batch=None, **kwargs):
  16.         output = ['head', 'tail']
  17.         responce = np.random.choice(output)
  18.         return responce
  19.    
  20.    
  21.  
  22.     def classify(self, utterances_batch, states_batch=None, history_batch=None):
  23.         print("head or tail intent")
  24.         user_text = utterances_batch[0]
  25.         matches = list(self.headortail.findall(user_text))
  26.         if len(matches) >= 1:
  27.             return {'name': 'Headortail'}
  28.         return {}
  29.    
  30.     @classmethod
  31.     def fit(cls, *args, **kwargs):
  32.         """Don't need fit"""
  33.         return None
  34.    
  35.     @staticmethod
  36.     def head_rule():
  37.         return rule(
  38.             dictionary({
  39.                 'орел',
  40.                 'решка',
  41.                 'монетку',
  42.                 'подбрось',
  43.                 'head',
  44.                 'tail',
  45.                 'toss',
  46.                 'coin'
  47.             })
  48.         ).named('Headortail')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement