'hm'
This commit is contained in:
parent
03cd256a2c
commit
fd3ed6c4ed
23
TaskB01/run
23
TaskB01/run
@ -7,7 +7,7 @@ class automata:
|
|||||||
# class variables init
|
# class variables init
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
# dictionary of connections between nodes
|
# dictionary of connections between nodes
|
||||||
self.storage = {}
|
self.graph = {}
|
||||||
# list of accepting states
|
# list of accepting states
|
||||||
self.accepting_states = []
|
self.accepting_states = []
|
||||||
# list of current states
|
# list of current states
|
||||||
@ -15,18 +15,18 @@ class automata:
|
|||||||
|
|
||||||
# print for debug purposes
|
# print for debug purposes
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return('%s\n\n%s\n\n%s\n\n' % (self.storage, self.accepting_states, self.state))
|
return('%s\n\n%s\n\n%s\n\n' % (self.graph, self.accepting_states, self.state))
|
||||||
|
|
||||||
# add node in open fst format
|
# add node in open fst format
|
||||||
def add_node(self, line):
|
def add_node(self, line):
|
||||||
node = line.replace('\n', '').split(' ')
|
node = line.replace('\n', '').split(' ')
|
||||||
if len(node) == 3:
|
if len(node) == 3:
|
||||||
if node[0] in self.storage:
|
if node[0] in self.graph:
|
||||||
# add value to existing node
|
# add value to existing node
|
||||||
self.storage[node[0]].append({node[2]: node[1]})
|
self.graph[node[0]].append({node[2]: node[1]})
|
||||||
else:
|
else:
|
||||||
# create new node
|
# create new node
|
||||||
self.storage[node[0]] = [{node[2]: node[1]}]
|
self.graph[node[0]] = [{node[2]: node[1]}]
|
||||||
elif len(node) == 1:
|
elif len(node) == 1:
|
||||||
# add accepting state
|
# add accepting state
|
||||||
self.accepting_states.append(node[0])
|
self.accepting_states.append(node[0])
|
||||||
@ -50,7 +50,18 @@ class automata:
|
|||||||
return not set(self.state).isdisjoint(self.accepting_states)
|
return not set(self.state).isdisjoint(self.accepting_states)
|
||||||
|
|
||||||
def get_node_transition(self, q, i):
|
def get_node_transition(self, q, i):
|
||||||
return [] if not self.storage[q][i] else self.storage[q][i]
|
result = []
|
||||||
|
# if the node exists
|
||||||
|
if self.graph[q]:
|
||||||
|
# search through all its connections to find value
|
||||||
|
for transition in self.graph[q]:
|
||||||
|
print(transition)
|
||||||
|
# if value is like searched for
|
||||||
|
if transition[0] == i:
|
||||||
|
# append next node
|
||||||
|
result.append(transition[1])
|
||||||
|
# return list of next nodes
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
||||||
auto = automata()
|
auto = automata()
|
||||||
|
Loading…
Reference in New Issue
Block a user