#print longest_common_substring(Tree(simpfi[0]).leaves(), Tree(compfi[0]).leaves()) for i in xrange(0, len(simpfi)): simptree = ParentedTree(simpfi[i].lower()) comptree = ParentedTree(compfi[i].lower()) chunk_list = get_substrings(comptree.leaves(), simptree.leaves(), ([''], (0, 0), (0, 0)), []) #print chunk_list #print comptree alignlist = [] for chunk in chunk_list: #print chunk comprange = chunk[1] simprange = chunk[2] simpidx = simprange[0] for j in xrange(comprange[0], comprange[1]): alignlist.append(str(simpidx) + '-' + str(j)) simpidx += 1 try: compposition = comptree.treeposition_spanning_leaves( comprange[0], comprange[1]) #print comptree.root[compposition] except: pass try: simpposition = simptree.treeposition_spanning_leaves( simprange[0], simprange[1]) except: pass print ' '.join(alignlist)
chunk_list.append(mychunk) myposlist = [] if DEBUG: print 'chunk list ...' print chunk_list for chunk in chunk_list: comprange = (chunk[0][0], chunk[-1][0] + 1) simprange = (chunk[0][1], chunk[-1][1] + 1) if DEBUG: print 'comprange of chunk', chunk, '...' print comprange print 'simprange ...' print simprange compposition = comptree.treeposition_spanning_leaves( comprange[0], comprange[1]) simpposition = simptree.treeposition_spanning_leaves( simprange[0], simprange[1]) if DEBUG: print 'derived comp subtree ...' print comptree.root()[compposition] print 'derived simp subtree ...' print simptree.root()[simpposition] #print comptree.leaves()[comprange[1]-1] if not isinstance(comptree.root()[compposition], str) and not isinstance( simptree.root()[simpposition], str): if len(ParentedTree(comptree.root()[compposition].pprint()).leaves()) != comprange[1]-comprange[0] or \ len(ParentedTree(simptree.root()[simpposition].pprint()).leaves()) != simprange[1]-simprange[0]: raw_input('mah tree is too big! ') if compposition == (0, ) and comptree.pos()[comprange[1] -