def transform_tree(array): if isinstance(array[0], tuple): tree = np.array([]) for tupl in array: n = Node() n.set_name(tupl[0]) n.set_freq(tupl[1]) tree = np.append(tree, n) else : tree = np.array(array) return tree
def __init__(self, source): self.nodes = [] root = source.getroot() for node in root: newNode = Node() for field in node: if field.tag == 'id': newNode.set_id(field.text) elif field.tag == 'name': newNode.set_name(field.text) elif field.tag == 'parent': newNode.set_parent(field.text) elif field.tag == 'probability': newNode.set_probability(field.attrib, field.text) self.nodes.append(newNode)