import sys def tdl_make_orth (orth) : orth_split = [ '"' + x + '"' for x in orth.split(" ") ] return "< " + ", ".join(orth_split) + " >" tdl_lex_set = set() lines = [ line for line in sys.stdin.readlines () if line.find("\t") != -1 ] START_I = int(sys.argv[1]) for i, line in enumerate(lines) : tabs = line[:-1].split("\t") try : pos = tabs[0] lt = tabs[1] syn_roles = tabs[2] lemma = tabs[3] infl = tabs[4] orth = tabs[5] key1 = tabs[6] value1 = tabs[7] if lemma == "" : lemma = orth except Exception : sys.stderr.write ("Input line: " + str(i) + '\n') raise if pos != "" : lex_lst = ["lex", pos] if lt != "" : lex_lst.append (lt) if lemma != "" : lex_lst.append (lemma.replace(" ", "_")) if infl != "" : lex_lst.append (infl) tdl_lex = "-".join (lex_lst) + '-' # Make sure no duplicates will be made. i = START_I while tdl_lex + str(i) in tdl_lex_set : i += 1 tdl_lex = tdl_lex + str(i) tdl_lex_set.add(tdl_lex) lt_lst = ["lt", pos] if lt != "" : lt_lst.append (lt) tdl_lt = '-'.join (lt_lst) pred_lst = [pos, lemma.replace(" ", "+"), syn_roles, "rel"] tdl_pred = '"_' + "_".join(pred_lst) + '"' tdl_orth = tdl_make_orth (orth) if infl == "" : sys.stdout.write (tdl_lex + " := " + tdl_lt + " &\n") sys.stdout.write ('[ SYNSEM.LOCAL [ CONT.RELS ],\n') sys.stdout.write (" STEM " + tdl_orth) if key1 != "" : sys.stdout.write (",\n LKEYS." + key1 + " " + value1) sys.stdout.write (" ].\n\n") else : infl_lst = ["infl"] infl_lst.append(pos) if infl != "" : infl_lst.append (infl) tdl_infl = "-".join(infl_lst) sys.stdout.write (tdl_lex + " := " + tdl_lt + " &\n") sys.stdout.write ("[ SYNSEM.LOCAL [ CAT.HEAD " + tdl_infl + ",\n") sys.stdout.write (' CONT.RELS ],\n') sys.stdout.write (" STEM " + tdl_orth) if key1 != "" : sys.stdout.write (",\n LKEYS." + key1 + " " + value1) sys.stdout.write (" ].\n\n")