예제 #1
0
    def dfs_walk(self):
        stack = Stack()
        stack.push(next(iter(self.nodes.values())))
        while stack.size() > 0:
            first = stack.pop()
            if first.mark:
                continue
            else:
                print(first.name)
                first.mark = True

            for neighbour in first.connections:
                stack.push(self.nodes[neighbour])
예제 #2
0
def check_relation(label, x):
    # todo : need to add negation to each label.
    # label : a list of time_signature
    # x : a query for its label
    stack = Stack()
    unpop = []
    modified = True
    for node in label:
        if node < x:
            if node.type == 'start':
                stack.push(node)
                # print('push')
            if node.type == 'end':
                if node.relation == stack.peek().relation:
                    stack.pop()
                    # print('pop')
                    while (unpop and unpop[-1] == stack.peek().relation):
                        stack.pop()
                        # print('pop')
                        unpop = unpop[:-1]
                else:
                    unpop.append(node.relation)
        else:
            if not modified:
                if node.type == 'end' and stack.peek(
                ).relation[:3] == 'NOT' and node.relation[:3] != 'NOT':
                    stack.push(
                        time_signature('0000-00-00', relation=node.relation))
                if stack.size() == 1:
                    rel = node.relation
                else:
                    rel = stack.peek().relation
                return rel
            else:
                rel = stack.peek().relation
                return rel