#! /bin/env python corpus = "man.conll" def make_xml_line(word,tag): outline = '' + word + '' return outline file = open(corpus,'r') line = file.readline() Heads = {} Words = {} while line: line = line.rstrip() list = line.split() if list: id = list[0] word = list[1] head_id = list[6] Words[id] = word Heads[id] = head_id else: # end of sentence for id in Heads: head_id = Heads[id] if head_id != "0": if int(id) < int(head_id): print "DH:\t" + Words[id] + '\t' + Words[head_id] else: print "HD:\t" + Words[head_id] + '\t' + Words[id] line = file.readline() file.close() # if not an ending newline for id in Heads: head_id = Heads[id] if head_id != "0": if int(id) < int(head_id): print "DH:\t" + Words[id] + '\t' + Words[head_id] else: print "HD:\t" + Words[head_id] + '\t' + Words[id]