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


Python StateMachine.add_state方法代码示例

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


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

示例1: startthegoddamnedgame

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
def startthegoddamnedgame():
    m = StateMachine()
    m.add_state("GameStarts", game_started)
    m.add_state("p1TurnStart", p1_turn_start)
    m.add_state("p2TurnStart", p2_turn_start)
    m.add_state("p1TurnEnd", p1_turn_end)
    m.add_state("p2TurnEnd", p2_turn_end)
    m.add_state("p1Win", p1_win)
    m.add_state("p2Win", p2_win)
    m.add_state("Game_Over", None, end_state=1)
    m.set_start("GameStarts")
    m.run(allTiles)
开发者ID:boomcan90,项目名称:smahjong,代码行数:14,代码来源:mahjongStates_vFINAL.py

示例2: run

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
def run(fpin, fpout):

	global fpindex

	fpindex = fpout
	m = StateMachine();
	m.add_state(parse)
	m.add_state(NOTES)
	m.add_state(QUOTES)
	m.add_state(segment)
	m.add_state(error, end_state=1)
	m.add_state(eof, end_state=1)
	m.set_start(parse)
	m.run((fpin, ''))	
开发者ID:gauthiier,项目名称:nnnotes,代码行数:16,代码来源:parse.py

示例3: TestStateMachine

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
class TestStateMachine(object):

	def setUp(self):
		self.sm = StateMachine()

	def test_can_transition_to_initial_state(self):
		on_state_enter = call_counter()
		self.sm.add_state("state1", on_enter=on_state_enter)
		self.sm.tick()
		assert on_state_enter.count == 1

	def test_can_transition_to_second_state(self):
		on_state2_enter = call_counter()
		state1 = self.sm.add_state("state1")
		state2 = self.sm.add_state("state2", on_enter=on_state2_enter)
		self.sm.add_transition(state1, state2, "gone foobar")
		self.sm.tick()
		assert on_state2_enter.count == 0
		self.sm.send_event("gone foobar")
		self.sm.tick()
		assert on_state2_enter.count == 1

	def test_can_transition_to_itself(self):
		on_state2_enter = call_counter()
		state1 = self.sm.add_state("state1", on_enter=on_state2_enter)
		self.sm.add_transition(state1, state1, "gone foobar")
		self.sm.tick()
		assert on_state2_enter.count == 1
		self.sm.send_event("gone foobar")
		self.sm.tick()
		assert on_state2_enter.count == 2

	def test_no_transition_until_state_done(self):
		def on_state_enter():
			return False
		state1 = self.sm.add_state("state1", on_enter=on_state_enter)
		state2 = self.sm.add_state("state2")
		self.sm.add_transition(state1, state2, "gone foobar")
		self.sm.tick()
		self.sm.send_event("gone foobar")
		self.sm.tick()
		assert self.sm.current_state() == state1
		self.sm.set_state_done()
		self.sm.tick()
		assert self.sm.current_state() == state2

	def test_transition_triggers_callback(self):
		on_transit = call_counter()
		state1 = self.sm.add_state("state1")
		state2 = self.sm.add_state("state2")
		self.sm.add_transition(state1, state2, "gone foobar", on_transit=on_transit)
		self.sm.tick()
		assert on_transit.count == 0
		self.sm.send_event("gone foobar")
		self.sm.tick()
		assert on_transit.count == 1
开发者ID:wotmods,项目名称:wot-teamspeak-mod,代码行数:58,代码来源:statemachine_test.py

示例4: handle

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
    def handle (self):
        m = StateMachine()
        try:
            m.add_state('greeting', greeting)
            m.add_state('helo', helo)
            m.add_state('mail', mail)
            m.add_state('rcpt', rcpt)
            m.add_state('data', data)
            m.add_state('process', process)
            m.add_state('done', None, end_state=1)
            m.set_start('greeting')

            m.run((self, {}))

        # in the event of an exception, capture the current
        # state and cargo dict and use the information
        # as part of the message sent to stdout
        except Exception as e:
            exception_data = {'state':m.current_state}
            if m.current_cargo:
                exception_data['data'] = m.current_cargo[1]
            e.args = (exception_data,)
            raise
开发者ID:simbha,项目名称:intelligent-smtp-responder,代码行数:25,代码来源:smtp_server.py

示例5: math_func

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
            val = math_func(val)
        print " >>"
    return (newState, val)

def twenties_counter(val):
    print "TWENTIES State:",
    while 1:
        if val <= 0  or  val >= 30:
            newState =  "Out_of_Range"; break
        elif 1 <= val < 10:
            newState =  "ONES"; break
        elif 10 <= val < 20:
            newState =  "TENS"; break
        else:
            print " *%2.1f+" % val,
            val = math_func(val)
        print " >>"
    return (newState, val)

def math_func(n):
     from math import sin
     return abs(sin(n))*31

if __name__== "__main__":
       m = StateMachine()
       m.add_state("ONES", ones_counter)
       m.add_state("TENS", tens_counter)
       m.add_state("TWENTIES", twenties_counter)
       m.add_state("OUT_OF_RANGE", None, end_state=1)
       m.set_start("ONES")
       m.run(1)
开发者ID:Geordie-Jon,项目名称:My_Python,代码行数:33,代码来源:statemachine_test.py

示例6: __init__

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
class SamParaParser:
    def __init__(self):
        # These attributes are set by the parse method
        self.doc = None
        self.para = None
        self.current_string = None
        self.flow = None

        self.stateMachine = StateMachine()
        self.stateMachine.add_state("PARA", self._para)
        self.stateMachine.add_state("ESCAPE", self._escape)
        self.stateMachine.add_state("END", None, end_state=1)
        self.stateMachine.add_state("ANNOTATION-START", self._annotation_start)
        self.stateMachine.add_state("CITATION-START", self._citation_start)
        self.stateMachine.add_state("BOLD-START", self._bold_start)
        self.stateMachine.add_state("ITALIC-START", self._italic_start)
        self.stateMachine.add_state("MONO-START", self._mono_start)
        self.stateMachine.add_state("QUOTES-START", self._quotes_start)
        self.stateMachine.add_state("INLINE-INSERT", self._inline_insert)
        self.stateMachine.set_start("PARA")
        self.patterns = {
            "escape": re.compile(r"\\"),
            "escaped-chars": re.compile(r"[\\\(\{\}\[\]_\*,`]"),
            "annotation": re.compile(
                r'(?<!\\)\{(?P<text>.*?)(?<!\\)\}(\(\s*(?P<type>\S*?\s*[^\\"\']?)(["\'](?P<specifically>.*?)["\'])??\s*(\((?P<namespace>\w+)\))?\))?'
            ),
            "bold": re.compile(r"\*(?P<text>\S.+?\S)\*"),
            "italic": re.compile(r"_(?P<text>\S.*?\S)_"),
            "mono": re.compile(r"`(?P<text>\S.*?\S)`"),
            "quotes": re.compile(r'"(?P<text>\S.*?\S)"'),
            "inline-insert": re.compile(r">>\((?P<attributes>.*?)\)"),
            "citation": re.compile(
                r"(\[\s*\*(?P<id>\S+)(\s+(?P<id_extra>.+?))?\])|(\[\s*\#(?P<name_name>\S+)(\s+(?P<extra>.+?))?\])|(\[\s*(?P<citation>.*?)\])"
            ),
        }

    def parse(self, para, doc, strip=True):
        if para is None:
            return None
        self.doc = doc
        self.para = Para(para, strip)
        self.current_string = ""
        self.flow = Flow()
        self.stateMachine.run(self.para)
        return self.flow

    def _para(self, para):
        try:
            char = para.next_char
        except IndexError:
            self.flow.append(self.current_string)
            self.current_string = ""
            return "END", para
        if char == "\\":
            return "ESCAPE", para
        elif char == "{":
            return "ANNOTATION-START", para
        elif char == "[":
            return "CITATION-START", para
        elif char == "*":
            return "BOLD-START", para
        elif char == "_":
            return "ITALIC-START", para
        elif char == "`":
            return "MONO-START", para
        elif char == '"':
            return "QUOTES-START", para
        elif char == ">":
            return "INLINE-INSERT", para
        else:
            self.current_string += char
            return "PARA", para

    def _annotation_start(self, para):
        match = self.patterns["annotation"].match(para.rest_of_para)
        if match:
            self.flow.append(self.current_string)
            self.current_string = ""
            annotation_type = match.group("type")
            text = match.group("text")

            # If there is an annotated phrase with no annotation, look back
            # to see if it has been annotated already, and if so, copy the
            # closest preceding annotation.
            if annotation_type is None:
                # First look back in the current flow
                # (which is not part of the doc structure yet).
                previous = self.flow.find_last_annotation(text)
                if previous is not None:
                    self.flow.append(previous)
                else:
                    # Then look back in the document.
                    previous = self.doc.find_last_annotation(text)
                    if previous is not None:
                        self.flow.append(previous)

                    # Else raise an exception.
                    else:
                        raise SAMParserError(
                            "Blank annotation found: {"
#.........这里部分代码省略.........
开发者ID:nakohdo,项目名称:sam,代码行数:103,代码来源:samparser.py

示例7: return

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
    print 'player 2 wins!'
    newState = 'game_end'

    return(newState, inpList)


def game_end(inpList):
    print 'End of game!'
    return None


##########################################################################
# Setting up game:
allTiles = []
allTiles.extend(User1.tiles)
allTiles.extend(User2.tiles)

if __name__ == "__main__":
    m = StateMachine()
    m.add_state("GameStarts", game_started)
    m.add_state("p1TurnStart", p1_turn_start)
    m.add_state("p2TurnStart", p2_turn_start)
    m.add_state("p1TurnEnd", p1_turn_end)
    m.add_state("p2TurnEnd", p2_turn_end)
    m.add_state("p1Win", p1_win)
    m.add_state("p2Win", p2_win)
    m.add_state("GameOver", game_end)
    m.add_state("Out of range", None, end_state=1)
    m.set_start("GameStarts")
    m.run(allTiles)
开发者ID:boomcan90,项目名称:smahjong,代码行数:32,代码来源:mahjongStates_v1.py

示例8: math_func

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
        else:
            val = math_func(val)
    return (newState, val)

def twenties_counter(val):
    while True:
        if val <= 0 or val >= 30:
            newState = STATE_OUT_OF_RANGE
            break
        elif 1 <= val < 10:
            newState = STATE_ONES
            break
        elif 10 <= val < 20:
            newState = STATE_TENS
            break
        else:
            val = math_func(val)
    return (newState, val)

def math_func(n):
    return abs(math.sin(n))*31

if __name__== '__main__':
    m = StateMachine()
    m.add_state(STATE_ONES, ones_counter, end_state=False)
    m.add_state(STATE_TENS, tens_counter, end_state=False)
    m.add_state(STATE_TWENTIES, twenties_counter, end_state=False)
    m.add_state(STATE_OUT_OF_RANGE, None, end_state=True)
    m.set_start(STATE_ONES)
    m.run(1)
开发者ID:rokujyouhitoma,项目名称:tips,代码行数:32,代码来源:statemachine_test.py

示例9: return

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
    currentPos = m.currentpos
    msg = json.dumps(currentPos)
    msg = m.tractor.encrypt(msg)
    xmpp.send_message(mto="[email protected]", mbody=msg)

    #time.sleep(1)
    
    newState = "AT_REST"
    print "///////////////////////////////////////////"
    return (newState, cargo)

if __name__ == '__main__':
	try:
	    q = Queue(1)     
	    xmpp = EchoBot('[email protected]', 'Q9MTZx14we',q)
	    xmpp.connect()
	    xmpp.process(block=False)
	    m = StateMachine(xmpp, q)
	    
	    m.add_state("AT_REST", at_rest)
	    m.add_state("DOWNLOAD_PATH", download_path)
	    m.add_state("EXECUTE_PATH", execute_path)
	    m.add_state("UPLOAD_DATA", upload_data)
	    m.add_state("SHUTTING_DOWN", shutdown)
	    m.add_state("OFF", None, end_state = 1)
	    
	    m.set_start("AT_REST")
	    m.run(1)
	finally:
	    xmpp.disconnect()
开发者ID:JeremyLWright,项目名称:cse548-RoboTractor,代码行数:32,代码来源:statemachine_test.py

示例10: __init__

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
class SamParaParser:
    def __init__(self):
        # These attributes are set by the parse method
        self.doc = None
        self.para = None
        self.current_string = None
        self.flow = None

        self.stateMachine = StateMachine()
        self.stateMachine.add_state("PARA", self._para)
        self.stateMachine.add_state("ESCAPE", self._escape)
        self.stateMachine.add_state("END", None, end_state=1)
        self.stateMachine.add_state("ANNOTATION-START", self._annotation_start)
        self.stateMachine.add_state("CITATION-START", self._citation_start)
        self.stateMachine.add_state("BOLD-START", self._bold_start)
        self.stateMachine.add_state("ITALIC-START", self._italic_start)
        self.stateMachine.add_state("CODE-START", self._code_start)
        self.stateMachine.add_state("QUOTES-START", self._quotes_start)
        self.stateMachine.add_state("INLINE-INSERT", self._inline_insert)
        self.stateMachine.add_state("CHARACTER-ENTITY", self._character_entity)
        self.stateMachine.set_start("PARA")
        self.patterns = {
            'escape': re.compile(r'\\', re.U),
            'escaped-chars': re.compile(r'[\\\(\{\}\[\]_\*,\.\*`"&]', re.U),
            'annotation': re.compile(
                r'(?<!\\)\{(?P<text>.*?)(?<!\\)\}(\(\s*(?P<type>\S*?\s*[^\\"\']?)(["\'](?P<specifically>.*?)["\'])??\s*(\((?P<namespace>\w+)\))?\s*(~(?P<language>[\w-]+))?\))?', re.U),
            'bold': re.compile(r'\*(?P<text>((?<=\\)\*|[^\*])*)(?<!\\)\*', re.U),
            'italic': re.compile(r'_(?P<text>((?<=\\)_|[^_])*)(?<!\\)_', re.U),
            'code': re.compile(r'`(?P<text>(``|[^`])*)`', re.U),
            'quotes': re.compile(r'"(?P<text>((?<=\\)"|[^"])*)(?<!\\)"', re.U),
            'inline-insert': re.compile(r'>\((?P<attributes>.*?)\)', re.U),
            'character-entity': re.compile(r'&(\#[0-9]+|#[xX][0-9a-fA-F]+|[\w]+);'),
            'citation': re.compile(r'(\[\s*\*(?P<id>\S+)(\s+(?P<id_extra>.+?))?\])|(\[\s*\#(?P<name_name>\S+)(\s+(?P<extra>.+?))?\])|(\[\s*(?P<citation>.*?)\])', re.U)
        }

    def parse(self, para, doc, strip=True):
        if para is None:
            return None
        self.doc = doc
        self.para = Para(para, strip)
        self.current_string = ''
        self.flow = Flow()
        self.stateMachine.run(self.para)
        return self.flow

    def _para(self, para):
        try:
            char = para.next_char
        except IndexError:
            self.flow.append(self.current_string)
            self.current_string = ''
            return "END", para
        if char == '\\':
            return "ESCAPE", para
        elif char == '{':
            return "ANNOTATION-START", para
        elif char == '[':
            return "CITATION-START", para
        elif char == "*":
            return "BOLD-START", para
        elif char == "_":
            return "ITALIC-START", para
        elif char == "`":
            return "CODE-START", para
        elif char == '"':
            return "QUOTES-START", para
        elif char == ">":
            return "INLINE-INSERT", para
        elif char == "&":
            return "CHARACTER-ENTITY", para
        else:
            self.current_string += char
            return "PARA", para

    def _annotation_start(self, para):
        match = self.patterns['annotation'].match(para.rest_of_para)
        if match:
            self.flow.append(self.current_string)
            self.current_string = ''
            annotation_type = match.group('type')
            language = match.group('language')
            text = self._unescape(match.group("text"))

            # If there is an annotated phrase with no annotation, look back
            # to see if it has been annotated already, and if so, copy the
            # closest preceding annotation.
            if annotation_type is None and not language:
                # First look back in the current flow
                # (which is not part of the doc structure yet).
                previous = self.flow.find_last_annotation(text)
                if previous is not None:
                    self.flow.append(previous)
                else:
                    # Then look back in the document.
                    previous = self.doc.find_last_annotation(text)
                    if previous is not None:
                        self.flow.append(previous)

                    # Else output a warning.
                    else:
#.........这里部分代码省略.........
开发者ID:dustinrb,项目名称:sam,代码行数:103,代码来源:samparser.py

示例11: __init__

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
class SamParser:
    def __init__(self):

        self.stateMachine = StateMachine()
        self.stateMachine.add_state("NEW", self._new_file)
        self.stateMachine.add_state("SAM", self._sam)
        self.stateMachine.add_state("BLOCK", self._block)
        self.stateMachine.add_state("CODEBLOCK-START", self._codeblock_start)
        self.stateMachine.add_state("CODEBLOCK", self._codeblock)
        self.stateMachine.add_state("PARAGRAPH-START", self._paragraph_start)
        self.stateMachine.add_state("PARAGRAPH", self._paragraph)
        self.stateMachine.add_state("RECORD-START", self._record_start)
        self.stateMachine.add_state("RECORD", self._record)
        self.stateMachine.add_state("LIST-ITEM", self._list_item)
        self.stateMachine.add_state("NUM-LIST-ITEM", self._num_list_item)
        self.stateMachine.add_state("BLOCK-INSERT", self._block_insert)
        self.stateMachine.add_state("END", None, end_state=1)
        self.stateMachine.set_start("NEW")
        self.current_paragraph = None
        self.doc = DocStructure()
        self.source = None
        self.patterns = {
            'comment': re.compile(r'\s*#.*'),
            'block-start': re.compile(r'(\s*)([a-zA-Z0-9-_]+):(?:\((.*?)\))?(.*)'),
            'codeblock-start': re.compile(r'(\s*)```(.*)'),
            'codeblock-end': re.compile(r'(\s*)```\s*$'),
            'paragraph-start': re.compile(r'\w*'),
            'blank-line': re.compile(r'^\s*$'),
            'record-start': re.compile(r'\s*[a-zA-Z0-9-_]+::(.*)'),
            'list-item': re.compile(r'(\s*)(\*\s+)(.*)'),
            'num-list-item': re.compile(r'(\s*)([0-9]+\.\s+)(.*)'),
            'block-insert': re.compile(r'(\s*)>>\(.*?\)\w*')
        }

    def parse(self, source):
        self.source = source
        try:
            self.stateMachine.run(self.source)
        except EOFError:
            raise Exception("Document ended before structure was complete. At:\n\n"
                            + self.current_paragraph)

    def paragraph_start(self, line):
        self.current_paragraph = line.strip()

    def paragraph_append(self, line):
        self.current_paragraph += " " + line.strip()

    def pre_start(self, line):
        self.current_paragraph = line

    def pre_append(self, line):
        self.current_paragraph += line

    def _new_file(self, source):
        line = source.next_line
        if line[:4] == 'sam:':
            self.doc.new_root('sam', line[5:])
            return "SAM", source
        else:
            raise Exception("Not a SAM file!")

    def _block(self, source):
        line = source.currentLine
        match = self.patterns['block-start'].match(line)
        indent = len(match.group(1))
        element = match.group(2).strip()
        attributes = match.group(3)
        content = match.group(4).strip()

        if content[:1] == ':':
            return "RECORD-START", source
        else:
            self.doc.new_block(element, attributes, content, indent)
            return "SAM", source

    def _codeblock_start(self, source):
        line = source.currentLine
        local_indent = len(line) - len(line.lstrip())
        match = self.patterns['codeblock-start'].match(line)
        attributes = re.compile(r'\((.*?)\)').match(match.group(2).strip())
        language = attributes.group(1)
        self.doc.new_block('codeblock', language, None, local_indent)
        self.pre_start('')
        return "CODEBLOCK", source

    def _codeblock(self, source):
        line = source.next_line
        if self.patterns['codeblock-end'].match(line):
            self.doc.new_flow(Pre(self.current_paragraph))
            return "SAM", source
        else:
            self.pre_append(line)
            return "CODEBLOCK", source

    def _paragraph_start(self, source):
        line = source.currentLine
        local_indent = len(line) - len(line.lstrip())
        self.doc.new_block('p', None, '', local_indent)
        self.paragraph_start(line)
#.........这里部分代码省略.........
开发者ID:dustinrb,项目名称:sam,代码行数:103,代码来源:samsparser.py

示例12: return

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
            newState = "pos_state"
        elif word in negative_adjectives:
            newState = "neg_state"
        else:
            newState = "error_state"
        return (newState, txt)
    elif state == "not_state":
        if word in positive_adjectives:
            newState = "neg_state"
        elif word in negative_adjectives:
            newState = "pos_state"
        else:
            newState = "error_state"
        return (newState, txt)


if __name__ == "__main__":
    m = StateMachine()
    m.add_state("Start", transitions)
    m.add_state("Python_state", transitions)
    m.add_state("is_state", transitions)
    m.add_state("not_state", transitions)
    m.add_state("neg_state", None, end_state=1)
    m.add_state("pos_state", None, end_state=1)
    m.add_state("error_state", None, end_state=1)
    m.set_start("Start")
    m.run("Python is great")
    """
    m.run("Python is difficult")
    m.run("Perl is ugly")
    """
开发者ID:freetonat,项目名称:python,代码行数:33,代码来源:statemachine_test.py

示例13: in

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
			if char in ("路","街"):
				newState = "street_state"
			else:
				newState = "town_state"
			break

	if breakIndex <> -1:
		restStr = doc[breakIndex+1:]
		detailList.append((newState,doc[:breakIndex + 1]))
	return (newState,restStr,detailList)



if __name__ == "__main__":
	m = StateMachine()
	m.add_state("start_state",start_transitions)
	m.add_state("province_state",province_transitions)
	m.add_state("city_state",city_transitions)
	m.add_state("region_state",region_transitions)
	m.add_state("state_state",state_transitions)
	m.add_state("town_state",town_transitions,end_state=1)
	m.add_state("street_state",street_transitions,end_state = 1)
	m.add_state("doorplate_state",None,end_state = 1)

	m.set_start("start_state")

	#m.process("浙江杭州市西湖区城区文三路黄龙国际G座18层")
	#m.process("浙江省杭州市西湖区城区文三路黄龙国际G座18层")
	#m.process("北京市北三环东路8号静安中心大厦")
	#m.process("黑龙江省哈尔滨市呼兰区南京路美兰家园5栋2单元303")
	#m.process("广东省深圳市罗湖区金稻田路1228号理想新城9栋A单元301室")
开发者ID:m3n78am,项目名称:fsm,代码行数:33,代码来源:location_machine_detective.py

示例14: go

# 需要导入模块: from statemachine import StateMachine [as 别名]
# 或者: from statemachine.StateMachine import add_state [as 别名]
    def go(self):
        m = StateMachine()
        # for  tmp in self.__cargos:
        #     print(tmp)
        '''Present'''
        m.add_state("Start", self.start_transitions)
        m.add_state('1A_state', self._1A_state_transitions)
        m.add_state('1C_state', None, end_state=1)
        m.add_state('2A_state', self._2A_state_transitions)
        m.add_state('2B_state', None, end_state=1)
        m.add_state('2C_state', None, end_state=1)

        m.add_state('Z1_VBP_state', self._Z1_VBP_state_transitions)
        m.add_state('Z1_VBZ_state', self._Z1_VBZ_state_transitions)
        m.add_state('1B_VBP_state', None, end_state=1)
        m.add_state('1B_VBZ_state', None, end_state=1)
        m.add_state('1D_state', None, end_state=1)  ### TODO: review, we add quan-subj state for uw-166

        m.add_state('Z2_state', self._Z2_state_transitions)
        m.add_state('3A_state', self._3A_state_transitions)
        m.add_state('3B_state', None, end_state=1)
        m.add_state('3C_state', None, end_state=1)
        m.add_state('4A_state', self._4A_state_transitions)
        m.add_state('4B_state', None, end_state=1)
        m.add_state('4C_state', None, end_state=1)

        '''Past'''
        m.add_state('5A_state', self._5A_state_transitions)
        m.add_state('5C_state', None, end_state=1)
        m.add_state('6A_state', self._6A_state_transitions)
        m.add_state('6B_state', None, end_state=1)
        m.add_state('6C_state', None, end_state=1)

        m.add_state('Z3_state', self._Z3_state_transitions)
        m.add_state('5B_state', None, end_state=1)

        m.add_state('Z4_state', self._Z4_state_transitions)
        m.add_state('7A_state', self._7A_state_transitions)
        m.add_state('7B_state', None, end_state=1)
        m.add_state('7C_state', None, end_state=1)
        m.add_state('8A_state', self._8A_state_transitions)
        m.add_state('8B_state', None, end_state=1)
        m.add_state('8C_state', None, end_state=1)

        '''Future and MD'''
        m.add_state('ZM_state', self._ZM_state_transitions)
        m.add_state('9A_state', self._9A_state_transitions)
        m.add_state('9C_state', None, end_state=1)
        m.add_state('10A_state', self._10A_state_transitions)
        m.add_state('10B_state', None, end_state=1)
        m.add_state('10C_state', None, end_state=1)

        # m.add_state('Z3_state', self._Z3_state_transitions)
        m.add_state('9B_state', self._9B_state_transitions)

        # m.add_state('Z5_state', self._Z5_state_transitions) Z5 merged with 9B
        m.add_state('11A_state', self._11A_state_transitions)
        m.add_state('11B_state', None, end_state=1)
        m.add_state('11C_state', None, end_state=1)
        m.add_state('12A_state', self._12A_state_transitions)
        m.add_state('12B_state', None, end_state=1)
        m.add_state('12C_state', None, end_state=1)
        m.add_state('error_state', None, end_state=1)

        m.set_start("Start")
        m.run(self.__cargos, actions)

        return m.get_tvstate(), m.get_action()
开发者ID:Joecth,项目名称:MWP_ExplanationGenerator,代码行数:70,代码来源:statemachine_tv.py


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