def response(self, input_text, parts): keywords = [] for word, part in parts: if morph.isKeyword(part): keywords.append(word) count = len(keywords) if count > 0 and not self.dictionary.template[count] == []: templates = self.dictionary.template[count] template = bot.select_random(templates) for key in keywords: template.replace('<noun>', key, 1) return template random_list = self.dictionary.random return bot.select_random(random_list)
def response(self, input_text, parts): ptn_items = [] ptn_items = self.dictionary.pattern for ptn_item in ptn_items: m = ptn_item.match(input_text) if m: return ptn_item.choice() #[End of for] random_list = self.dictionary.random return bot.select_random(random_list)
def generate(self, keyword): if not self.dic: return prefix1 = '' words = [] if self.dic.get(keyword): prefix1 = keyword else: prefix1 = self.__select_start() keys = list(self.dic.get(prefix1).keys()) prefix2 = bot.select_random(keys) words.append(prefix1) words.append(prefix2) for _ in range(self.CHAIN_MAX): suffix = bot.select_random(self.dic.get(prefix1).get(prefix2)) if suffix == self.ENDMARK: break words.append(suffix) prefix1 = prefix2 prefix2 = suffix return ''.join(map(str, words))
def response(self, input_text, parts): random_list = [] random_list = self.dictionary.random return bot.select_random(random_list)
def choice(self): return bot.select_random(self.phrases)
def __select_start(self): keys = list(self.starts.keys()) return bot.select_random(keys)