@@ -0,0 +1,1923 @@
+# TODO add lines for triplet to matrix%0A# TODO distinguish the partiion of a unary machine from the first partition of a binary machine?%0A%0A%0Afrom collections import defaultdict%0Afrom definition_parser import read%0Aimport sys%0A%0Atry: %0A    lexfile = open(sys.argv%5B1%5D)%0A    mxfile = open(sys.argv%5B2%5D, mode='w')%0A    indexfile = open(sys.argv%5B3%5D, mode='w')%0Aexcept:%0A    raise(Exception('Usage: '+sys.argv%5B0%5D+' mxfile indexfile'))%0A%0Alex_dict = read(lexfile,2) # 2: English printnames%0Amx_dict = defaultdict(lambda: defaultdict(int))%0Alines = set()%0A%0A%0Adef add_mach(definiendum, machine, visited):%0A    if machine in visited:%0A        return%0A    visited.add(machine)%0A    lines.add(machine.printname())%0A    for part_ind in xrange(len(machine.partitions)):%0A        for sub in machine.partitions%5Bpart_ind%5D:%0A            if machine.printname() == definiendum:%0A                triplet = sub.printname()%0A            else:%0A                if part_ind == 0:%0A                    triplet = sub.printname() + ' ' + machine.printname()%0A%0A                else:%0A                    triplet = machine.printname() + ' ' + sub.printname()%0A                mx_dict%5Btriplet%5D%5B'partition' +str(part_ind + 1)%5D = 1%0A                for column in %5Bsub.printname(), machine.printname()%5D:%0A                    mx_dict%5Btriplet%5D%5Bcolumn%5D = 1%0A            mx_dict%5Bdefiniendum%5D%5Btriplet%5D += 1%0A            lines.add(triplet)%0A            lines.add(machine.printname())%0A            add_mach(definiendum,sub, visited)%0A    for  part_ind in xrange(2):%0A        lines.add('partition' +str(part_ind + 1))%0A%0Aif __name__ == %22__main__%22:%0A    for printname, machine in lex_dict.items():%0A        visited = set()%0A        add_mach(printname, machine, visited)%0A    %0A    for index, definiendum in enumerate(lines):%0A        indexfile.write(str(index+1)+'%5Ct'+definiendum+'%5Cn')%0A        for defining in lines:%0A            mxfile.write(str(mx_dict%5Bdefiniendum%5D%5Bdefining%5D)+' ')%0A        mxfile.write('%5Cn')%0A    %0A

transform 4lang to a matrix with columns like 'john HAS'