def __new__(cls, items=None, relations=None): items = as_tuple(items) if relations: items = cls.reorder(items, relations) obj = super(PartialOrderTuple, cls).__new__(cls, items) obj._relations = set(tuple(i) for i in as_tuple(relations)) return obj
def __new__(cls, items=None, relations=None): items = as_tuple(items) if relations: items = cls.reorder(items, relations) obj = super(PartialOrderTuple, cls).__new__(cls, items) obj._relations = set(tuple(i) for i in as_tuple(relations)) return obj
def __init__(self, nodes=None, edges=None): self.graph = OrderedDict() self.labels = DefaultOrderedDict(dict) for node in as_tuple(nodes): self.add_node(node) for i in as_tuple(edges): try: ind_node, dep_node = i except ValueError: ind_node, dep_node, label = i self.labels[ind_node][dep_node] = label self.add_edge(ind_node, dep_node)
def __init__(self, *items): # Normalize input nitems = [] for i in as_tuple(items): if isinstance(i, Iterable): nitems.append(tuple(i)) else: raise ValueError("Expected sequence, got %s" % type(i)) self.items = tuple(nitems) self.tip = -1 self.curiter = None
def __init__(self, nodes=None, edges=None): self.graph = OrderedDict() for node in as_tuple(nodes): self.add_node(node) for ind_node, dep_node in as_tuple(edges): self.add_edge(ind_node, dep_node)
def __init__(self, nodes=None, edges=None): self.graph = OrderedDict() for node in as_tuple(nodes): self.add_node(node) for ind_node, dep_node in as_tuple(edges): self.add_edge(ind_node, dep_node)