def main(argv):
first_col = <NUM_LIT:3><EOL>last_col = -<NUM_LIT:1><EOL>def print_usage():<EOL><INDENT>"""<STR_LIT>"""<EOL>sys.stdout.write(<EOL>'<STR_LIT>' + '<STR_LIT>'<EOL>)<EOL>sys.exit(<NUM_LIT:2>)<EOL><DEDENT>def binarize(num):<EOL><INDENT>"""<STR_LIT>"""<EOL>if num == '<STR_LIT:0>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif num == '<STR_LIT>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif num == '<STR_LIT:1>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>elif num == '<STR_LIT:2>':  <EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT><DEDENT>def init_termdicts():<EOL><INDENT>"""<STR_LIT>"""<EOL>ifile = codecs.open('<STR_LIT>', '<STR_LIT:r>', '<STR_LIT:utf-8>')<EOL>feature_mask = {}<EOL>keyline = ifile.readline().strip().split('<STR_LIT:U+002C>')[first_col:last_col]<EOL>mag = len(keyline)<EOL>for i in range(len(keyline)):<EOL><INDENT>features = '<STR_LIT>' + ('<STR_LIT>' * i) + '<STR_LIT>' + ('<STR_LIT>' * (mag - i - <NUM_LIT:1>))<EOL>feature_mask[keyline[i]] = int(features, <NUM_LIT:2>)<EOL><DEDENT>termdict = {}<EOL>for line in ifile:<EOL><INDENT>line = line.strip().rstrip('<STR_LIT:U+002C>')<EOL>if '<STR_LIT:#>' in line:<EOL><INDENT>line = line[: line.find('<STR_LIT:#>')].strip()<EOL><DEDENT>if line:<EOL><INDENT>line = line.split('<STR_LIT:U+002C>')<EOL>term = line[last_col]<EOL>features = '<STR_LIT>' + '<STR_LIT>'.join(<EOL>[binarize(val) for val in line[first_col:last_col]]<EOL>)<EOL>termdict[term] = int(features, <NUM_LIT:2>)<EOL><DEDENT><DEDENT>return termdict, feature_mask<EOL><DEDENT>def check_terms(sym, features, name, termdict):<EOL><INDENT>"""<STR_LIT>"""<EOL>if '<STR_LIT:#>' in name:<EOL><INDENT>name = name[: name.find('<STR_LIT:#>')].strip()<EOL><DEDENT>for term in name.split():<EOL><INDENT>if term in termdict:<EOL><INDENT>if termdict[term] & features != termdict[term]:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ term<EOL>+ '<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT:\n>'<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ term<EOL>+ '<STR_LIT>'<EOL>+ name<EOL>+ '<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT:\n>'<EOL>)<EOL><DEDENT><DEDENT><DEDENT>def check_entailments(sym, features, feature_mask):<EOL><INDENT>"""<STR_LIT>"""<EOL>entailments = {<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>'),<EOL>'<STR_LIT>': ('<STR_LIT>',),<EOL>'<STR_LIT>': ('<STR_LIT>',),<EOL>}<EOL>for feature in entailments:<EOL><INDENT>fname = feature[<NUM_LIT:1>:]<EOL>if feature[<NUM_LIT:0>] == '<STR_LIT:+>':<EOL><INDENT>fm = (feature_mask[fname] >> <NUM_LIT:1>) & feature_mask[fname]<EOL><DEDENT>else:<EOL><INDENT>fm = (feature_mask[fname] << <NUM_LIT:1>) & feature_mask[fname]<EOL><DEDENT>if (features & fm) == fm:<EOL><INDENT>for ent in entailments[feature]:<EOL><INDENT>ename = ent[<NUM_LIT:1>:]<EOL>if ent[<NUM_LIT:0>] == '<STR_LIT:+>':<EOL><INDENT>efm = (feature_mask[ename] >> <NUM_LIT:1>) & feature_mask[ename]<EOL><DEDENT>elif ent[<NUM_LIT:0>] == '<STR_LIT:->':<EOL><INDENT>efm = (feature_mask[ename] << <NUM_LIT:1>) & feature_mask[ename]<EOL><DEDENT>elif ent[<NUM_LIT:0>] == '<STR_LIT:0>':<EOL><INDENT>efm = <NUM_LIT:0><EOL><DEDENT>elif ent[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>efm = feature_mask[ename]<EOL><DEDENT>if ent[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>if (features & efm) == <NUM_LIT:0>:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT>'<EOL>+ fname<EOL>+ '<STR_LIT>'<EOL>+ ename<EOL>)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if (features & efm) != efm:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ sym<EOL>+ '<STR_LIT>'<EOL>+ fname<EOL>+ '<STR_LIT>'<EOL>+ ename<EOL>)<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>checkdict = {}  <EOL>checkset_s = set()  <EOL>checkset_f = set()  <EOL>termdict, feature_mask = init_termdicts()<EOL>ifile = '<STR_LIT>'<EOL>ofile = '<STR_LIT>'<EOL>try:<EOL><INDENT>opts = getopt.getopt(argv, '<STR_LIT>', ['<STR_LIT>', '<STR_LIT>'])[<NUM_LIT:0>]<EOL><DEDENT>except getopt.GetoptError:<EOL><INDENT>print_usage()<EOL><DEDENT>for opt, arg in opts:<EOL><INDENT>if opt == '<STR_LIT>':<EOL><INDENT>print_usage()<EOL><DEDENT>elif opt in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>ifile = codecs.open(arg, '<STR_LIT:r>', '<STR_LIT:utf-8>')<EOL><DEDENT>elif opt in ('<STR_LIT>', '<STR_LIT>'):<EOL><INDENT>ofile = codecs.open(arg, '<STR_LIT:w>', '<STR_LIT:utf-8>')<EOL><DEDENT><DEDENT>if not ifile:<EOL><INDENT>print_usage()<EOL><DEDENT>oline = '<STR_LIT>'<EOL>if not ofile:<EOL><INDENT>ofile = sys.stdout<EOL><DEDENT>ofile.write(oline + '<STR_LIT:\n>')<EOL>keyline = ifile.readline().strip().split('<STR_LIT:U+002C>')[first_col:last_col]<EOL>for line in ifile:<EOL><INDENT>line = line.strip().rstrip('<STR_LIT:U+002C>')<EOL>if line.startswith('<STR_LIT>'):<EOL><INDENT>break<EOL><DEDENT>line = unicodedata.normalize('<STR_LIT>', line)<EOL>if not line or line.startswith('<STR_LIT:#>'):<EOL><INDENT>oline = '<STR_LIT:U+0020>' + line<EOL><DEDENT>else:<EOL><INDENT>line = line.strip().split('<STR_LIT:U+002C>')<EOL>if '<STR_LIT:#>' in line:<EOL><INDENT>line = line[: line.find('<STR_LIT:#>')]<EOL><DEDENT>symbol = line[<NUM_LIT:0>]<EOL>variant = int(line[<NUM_LIT:1>])<EOL>segmental = bool(line[<NUM_LIT:2>])<EOL>features = '<STR_LIT>' + '<STR_LIT>'.join(<EOL>[binarize(val) for val in line[first_col:last_col]]<EOL>)<EOL>name = line[-<NUM_LIT:1>].strip()<EOL>if not segmental:<EOL><INDENT>features = '<STR_LIT:->' + features<EOL><DEDENT>featint = int(features, <NUM_LIT:2>)<EOL>check_terms(symbol, featint, name, termdict)<EOL>check_entailments(symbol, featint, feature_mask)<EOL>if symbol in checkset_s:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>' + symbol + '<STR_LIT>'<EOL>)<EOL><DEDENT>else:<EOL><INDENT>checkset_s.add(symbol)<EOL><DEDENT>if variant < <NUM_LIT:2>:<EOL><INDENT>if featint in checkset_f:<EOL><INDENT>sys.stdout.write(<EOL>'<STR_LIT>'<EOL>+ str(featint)<EOL>+ '<STR_LIT>'<EOL>+ '<STR_LIT>'<EOL>+ symbol<EOL>+ '<STR_LIT>'<EOL>+ checkdict[featint]<EOL>)<EOL><DEDENT>else:<EOL><INDENT>checkdict[featint] = symbol<EOL>checkset_f.add(featint)<EOL><DEDENT><DEDENT>if variant < <NUM_LIT:5>:<EOL><INDENT>oline = '<STR_LIT>'.format(<EOL>symbol, featint<EOL>)<EOL><DEDENT>else:<EOL><INDENT>oline = '<STR_LIT>'<EOL><DEDENT><DEDENT>if oline:<EOL><INDENT>ofile.write(oline + '<STR_LIT:\n>')<EOL><DEDENT><DEDENT>ofile.write('<STR_LIT>')<EOL>mag = len(keyline)<EOL>for i in range(len(keyline)):<EOL><INDENT>features = int('<STR_LIT>' + ('<STR_LIT>' * i) + '<STR_LIT>' + ('<STR_LIT>' * (mag - i - <NUM_LIT:1>)), <NUM_LIT:2>)<EOL>oline = '<STR_LIT>'.format(keyline[i], features)<EOL>ofile.write(oline + '<STR_LIT:\n>')<EOL><DEDENT>ofile.write('<STR_LIT>')<EOL>
Read input file and write to output.

    Parameters
    ----------
    argv : list
        Arguments to the script