本文整理汇总了Python中programy.utils.text.text.TextUtils.strip_all_punctuation方法的典型用法代码示例。如果您正苦于以下问题:Python TextUtils.strip_all_punctuation方法的具体用法?Python TextUtils.strip_all_punctuation怎么用?Python TextUtils.strip_all_punctuation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类programy.utils.text.text.TextUtils
的用法示例。
在下文中一共展示了TextUtils.strip_all_punctuation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_last_sentences_from_response
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import strip_all_punctuation [as 别名]
def parse_last_sentences_from_response(self, response):
# TODO Issue here when the response is more than just a simple sentence
# If the response contains punctuation such as "Hello. There" then THAT is none
response = re.sub(r'<\s*br\s*/>\s*', ".", response)
response = re.sub(r'<br></br>*', ".", response)
sentences = response.split(".")
sentences = [x for x in sentences if x]
last_sentence = sentences[-1]
that_pattern = TextUtils.strip_all_punctuation(last_sentence)
that_pattern = that_pattern.strip()
# TODO Added this to catch a failed sentence
if that_pattern == "":
that_pattern = '*'
return that_pattern
示例2: ask_question
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import strip_all_punctuation [as 别名]
def ask_question(self, bot, clientid, sentence) -> str:
conversation = bot.get_conversation(clientid)
topic_pattern = conversation.predicate("topic")
if topic_pattern is None:
logging.info("No Topic pattern default to [*]")
topic_pattern = "*"
else:
logging.info("Topic pattern = [%s]", topic_pattern)
try:
that_question = conversation.nth_question(2)
that_sentence = that_question.current_sentence()
# If the last response was valid, i.e not none and not empty string, then use
# that as the that_pattern, otherwise we default to '*' as pattern
if that_sentence.response is not None and that_sentence.response != '':
that_pattern = TextUtils.strip_all_punctuation(that_sentence.response)
logging.info("That pattern = [%s]", that_pattern)
else:
logging.info("That pattern, no response, default to [*]")
that_pattern = "*"
except Exception:
logging.info("No That pattern default to [*]")
that_pattern = "*"
match_context = self._aiml_parser.match_sentence(bot, clientid,
sentence,
topic_pattern=topic_pattern,
that_pattern=that_pattern)
if match_context is not None:
template_node = match_context.template_node()
logging.debug("AIML Parser evaluating template [%s]", template_node.to_string())
return template_node.template.resolve(bot, clientid)
return None
示例3: process
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import strip_all_punctuation [as 别名]
def process(self, context, word_string):
YLogger.debug(context, "Removing punctuation...")
return TextUtils.strip_all_punctuation(word_string)
示例4: test_strip_all_punctuation
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import strip_all_punctuation [as 别名]
def test_strip_all_punctuation(self):
self.assertEquals("", TextUtils.strip_all_punctuation(""))
self.assertEquals("", TextUtils.strip_all_punctuation(" "))
self.assertEquals("x y z", TextUtils.strip_all_punctuation("x! y? z."))
self.assertEquals("a b c", TextUtils.strip_all_punctuation("!a b c?"))