本文整理汇总了Python中programy.utils.text.text.TextUtils.get_tabs方法的典型用法代码示例。如果您正苦于以下问题:Python TextUtils.get_tabs方法的具体用法?Python TextUtils.get_tabs怎么用?Python TextUtils.get_tabs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类programy.utils.text.text.TextUtils
的用法示例。
在下文中一共展示了TextUtils.get_tabs方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_tabs
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import get_tabs [as 别名]
def test_get_tabs(self):
tabs = TextUtils.get_tabs(0)
self.assertEqual(tabs, "")
tabs = TextUtils.get_tabs(1, tabs="\t")
self.assertEqual(tabs, "\t")
tabs = TextUtils.get_tabs(5, tabs="\t")
self.assertEqual(tabs, "\t\t\t\t\t")
示例2: consume
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import get_tabs [as 别名]
def consume(self, bot, clientid, context, words, word_no, type, depth):
tabs = TextUtils.get_tabs(word_no)
if depth > context.max_search_depth:
logging.error("%sMax search depth [%d]exceeded" % (tabs, context.max_search_depth))
return None
if words.word(word_no) == PatternTopicNode.TOPIC:
logging.debug("%sTopic matched %s" % (tabs, words.word(word_no)))
return super(PatternTopicNode, self).consume(bot, clientid, context, words, word_no+1, type, depth+1)
logging.debug("%sTopic NOT matched %s" % (tabs, words.word(word_no)))
return None
示例3: get_tabs
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import get_tabs [as 别名]
def get_tabs(self, client_context, depth):
if client_context.bot.configuration.tab_parse_output is True:
return TextUtils.get_tabs(depth)
return ""
示例4: consume
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import get_tabs [as 别名]
def consume(self, bot, clientid, context, words, word_no, type, depth):
tabs = TextUtils.get_tabs(word_no)
if depth > context.max_search_depth:
logging.error("%sMax search depth [%d]exceeded" % (tabs, context.max_search_depth))
return None
context_match = Match(type, self, None)
context.add_match(context_match)
matches_added = 1
if self._0ormore_hash is not None:
logging.debug("%sWildcard is next node, moving on!"%(tabs))
match = self._0ormore_hash.consume(bot, clientid, context, words, word_no+1, type, depth+1)
if match is not None:
return match
if self._1ormore_underline is not None:
logging.debug("%sWildcard is next node, moving on!"%(tabs))
match = self._1ormore_underline.consume(bot, clientid, context, words, word_no+1, type, depth+1)
if match is not None:
return match
if self._0ormore_arrow is not None:
logging.debug("%sWildcard is next node, moving on!"%(tabs))
match = self._0ormore_arrow.consume(bot, clientid, context, words, word_no+1, type, depth+1)
if match is not None:
return match
if self._1ormore_star is not None:
logging.debug("%sWildcard is next node, moving on!"%(tabs))
match = self._1ormore_star.consume(bot, clientid, context, words, word_no+1, type, depth+1)
if match is not None:
return match
# TODO Add priority words first
word = words.word(word_no)
if len(self._children) > 0:
for child in self._children:
if child.equals(bot, clientid, word):
logging.debug ("%sWildcard child %s matched %s"%(tabs, child._word, word))
logging.debug("%s*MATCH -> %s" % (tabs, word))
context_match2 = Match(Match.WORD, child, word)
context.add_match(context_match2)
matches_added += 1
match = child.consume(bot, clientid, context, words, word_no+1, type, depth+1)
if match is not None:
return match
if word == PatternTopicNode.TOPIC or word == PatternThatNode.THAT:
logging.debug ("Found a topic or that ar the wrong place....")
context.pop_matches(matches_added)
return None
logging.debug("%sWildcard %s consumed %s" % (tabs, self._wildcard, word))
logging.debug("%s*MATCH -> %s" % (tabs, word))
context_match.add_word(word)
match = super(PatternZeroOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no + 1, type, depth+1)
if match is not None:
return match
word_no += 1
word = words.word(word_no)
if word == PatternTopicNode.TOPIC or word == PatternThatNode.THAT:
logging.debug("Found a topic or that ar the wrong place....")
context.pop_matches(matches_added)
return None
logging.debug("%sWildcard %s consumed %s" % (tabs, self._wildcard, word))
logging.debug("%s*MATCH -> %s" % (tabs, word))
context_match.add_word(word)
match = super(PatternZeroOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no + 1, type, depth+1)
if match is not None:
return match
word_no += 1
if word_no >= words.num_words():
context.pop_matches(matches_added)
return None
word = words.word(word_no)
logging.debug("%sNo children, consume words until next break point" % (tabs))
while word_no < words.num_words() - 1:
match = super(PatternZeroOrMoreWildCardNode, self).consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
return match
if word == PatternTopicNode.TOPIC or word == PatternThatNode.THAT:
logging.debug("Found a topic or that ar the wrong place....")
context.pop_matches(matches_added)
return None
#.........这里部分代码省略.........
示例5: consume
# 需要导入模块: from programy.utils.text.text import TextUtils [as 别名]
# 或者: from programy.utils.text.text.TextUtils import get_tabs [as 别名]
def consume(self, bot, clientid, context, words, word_no, type, depth):
tabs = TextUtils.get_tabs(word_no)
if depth > context.max_search_depth:
logging.error("%sMax search depth [%d]exceeded" % (tabs, context.max_search_depth))
return None
if word_no >= words.num_words():
if self._template is not None:
logging.debug("%sFound a template, success!" % (tabs))
return self._template
else:
logging.debug("%sNo more words and no template, no match found!" % (tabs))
#context.pop_match()
return None
if self._topic is not None:
match = self._topic.consume(bot, clientid, context, words, word_no, Match.TOPIC, depth+1)
if match is not None:
return match
if words.word(word_no) == PatternNode.TOPIC:
logging.debug("%s Looking for a %s, none give, no match found!" % (tabs, PatternNode.TOPIC))
#context.pop_match()
return None
if self._that is not None:
match = self._that.consume(bot, clientid, context, words, word_no, Match.THAT, depth+1)
if match is not None:
return match
if words.word(word_no) == PatternNode.THAT:
logging.debug("%s Looking for a %s, none give, no match found!" % (tabs, PatternNode.THAT))
#context.pop_match()
return None
for child in self._priority_words:
if child.equals(bot, clientid, words.word(word_no)):
logging.debug("%sPriority %s matched %s" % (tabs, child._word, words.word(word_no)))
logging.debug("%sMATCH -> %s" % (tabs, words.word(word_no)))
match_node = Match(type, child, words.word(word_no))
context.add_match(match_node)
match = child.consume(bot, clientid, context, words, word_no + 1, type, depth+1)
if match is not None:
return match
else:
context.pop_match ()
if self._0ormore_hash is not None:
match = self._0ormore_hash.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
return match
#else:
# context.pop_match ()
if self._1ormore_underline is not None:
match = self._1ormore_underline.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
return match
#else:
# context.pop_match ()
for child in self._children:
if child.equals(bot, clientid, words.word(word_no)):
logging.debug("%sChild %s matched %s" % (tabs, child._word, words.word(word_no)))
logging.debug("%sMATCH -> %s" % (tabs, words.word(word_no)))
match_node = Match(type, child, words.word(word_no))
context.add_match(match_node)
match = child.consume(bot, clientid, context, words, word_no + 1, type, depth+1)
if match is not None:
return match
else:
context.pop_match ()
if self._0ormore_arrow is not None:
match = self._0ormore_arrow.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
return match
#else:
# context.pop_match ()
if self._1ormore_star is not None:
match = self._1ormore_star.consume(bot, clientid, context, words, word_no, type, depth+1)
if match is not None:
return match
#else:
# context.pop_match ()
logging.debug("%sNo match for %s, trying another path" % (tabs, words.word(word_no)))
return None