M1-Arborator-NaijaSUD/arborator/lib/treebankfiles.py
def unclutter(conllfilename):
	"""
	separate trees that cross branches or join the same conll package
	"""
	trees=conll.conllFile2trees(conllfilename)
	print len(trees),"sentences read"
	newtrees = []
	for tree in trees:
		rootindices = [i for i in tree if tree[i].get('gov',{}).keys()[0] not in tree]
		if len(rootindices)>1:
			ptrees={}
			ordreptrees=[]
			for i in tree:
				root=i
				while tree[root].get('gov',{}).keys()[0] in tree:
					root = tree[root].get('gov',{}).keys()[0]
				if root not in ordreptrees: ordreptrees+=[root]
				ptrees[root]=ptrees.get(root,[]) + [i]
			for r in ordreptrees:
				ptree=conll.Tree()
				for nr,jj in enumerate(ptrees[r]):
					ptree[jj]=tree[jj].copy()
				ptree = corrigerNumerotation(ptree)
				newtrees+=[tree]
		
		else:
			newtrees+=[tree]
	
		
	conll.trees2conllFile(newtrees, conllfilename+".uncluttered")
	print "written",len(newtrees),"sentences into",conllfilename+".uncluttered"

	separate trees that cross branches or join the same conll package
	
separate trees that cross branches or join the same conll package
separate trees that cross branches or join the same conll package
def unclutter(conllfilename):
	trees=conll.conllFile2trees(conllfilename)
	print len(trees),"sentences read"
	newtrees = []
	for tree in trees:
		rootindices = [i for i in tree if tree[i].get('gov',{}).keys()[0] not in tree]
		if len(rootindices)>1:
			ptrees={}
			ordreptrees=[]
			for i in tree:
				root=i
				while tree[root].get('gov',{}).keys()[0] in tree:
					root = tree[root].get('gov',{}).keys()[0]
				if root not in ordreptrees: ordreptrees+=[root]
				ptrees[root]=ptrees.get(root,[]) + [i]
			for r in ordreptrees:
				ptree=conll.Tree()
				for nr,jj in enumerate(ptrees[r]):
					ptree[jj]=tree[jj].copy()
				ptree = corrigerNumerotation(ptree)
				newtrees+=[tree]
		else:
			newtrees+=[tree]
	conll.trees2conllFile(newtrees, conllfilename+".uncluttered")
	print "written",len(newtrees),"sentences into",conllfilename+".uncluttered"
def unclutter ( conllfilename ) : trees = conll . conllFile2trees ( conllfilename ) print len ( trees ) , "sentences read" newtrees = [ ] for tree in trees : rootindices = [ i for i in tree if tree [ i ] . get ( 'gov' , { } ) . keys ( ) [ 0 ] not in tree ] if len ( rootindices ) > 1 : ptrees = { } ordreptrees = [ ] for i in tree : root = i while tree [ root ] . get ( 'gov' , { } ) . keys ( ) [ 0 ] in tree : root = tree [ root ] . get ( 'gov' , { } ) . keys ( ) [ 0 ] if root not in ordreptrees : ordreptrees += [ root ] ptrees [ root ] = ptrees . get ( root , [ ] ) + [ i ] for r in ordreptrees : ptree = conll . Tree ( ) for nr , jj in enumerate ( ptrees [ r ] ) : ptree [ jj ] = tree [ jj ] . copy ( ) ptree = corrigerNumerotation ( ptree ) newtrees += [ tree ] else : newtrees += [ tree ] conll . trees2conllFile ( newtrees , conllfilename + ".uncluttered" ) print "written" , len ( newtrees ) , "sentences into" , conllfilename + ".uncluttered"
separate trees that cross branches or join the same conll package
separate trees that cross branches or join the same conll package
"""
	separate trees that cross branches or join the same conll package
	"""
conllfilename