def _parse(self, input): lines = [DependencyGraph._normalize(line) for line in input.split('\n') if line.strip()] temp = [] for index, line in enumerate(lines): cells = line.split('\t') _, word, _, tag, _, _, head, rel, _, _ = cells head = int(head) self.nodelist.append({'address': index+1, 'word': word, 'tag': tag, 'head': head, 'rel': rel, 'deps': [d for (d,h) in temp if h == index+1]}) try: self.nodelist[head]['deps'].append(index+1) except IndexError: temp.append((index+1, head)) root_address = self.nodelist[0]['deps'][0] self.root = self.nodelist[root_address]