#! /usr/bin/env python

# Translate CoNLL format with one item per line to,
# with segments separated by blank lines
# to a one-segment-per-line format, with items
# separated by spaces.
# Only output first field of each CoNLL item.

import sys

def main():
    command = sys.argv[1]
    out = sys.stdout
    if command == "to":
        # from CoNLL to lines
        for line in sys.stdin:
            xs = line.split()
            if len(xs) == 0:
                out.write("\n")
            else:
                out.write("%s " % xs[0]) 
        out.write("\n")
    elif command =="from":
        # from lines to CoNLL
        for line in sys.stdin:
            for w in line.split():
                out.write("%s\n" % w)
            out.write("\n")
    
if __name__ == "__main__":
    main()
