M1-Arborator-NaijaSUD/arborator/lib/conll.py
def trees2conllFile(trees, outfile, columns="u", includeSentenceFeatures=True): # changed default from 10 to u!
	"""
	exports a list of treedics into outfile
	used after tree transformations...
	in conll14 format, the lemma position contains a duplicated t if lemma is not available
	"""
        with codecs.open(outfile,"w","utf-8") as f:
		for tree in trees:
			if columns=="u": # conllu format
				treestring = tree.conllu()
			else:
				
				treestring = ""
				if includeSentenceFeatures:
					for stftkey in sorted(tree.sentencefeatures):
						if stftkey=="_comments":
							treestring+=tree.sentencefeatures[stftkey]
						else:
							treestring+=stftkey+" = "+tree.sentencefeatures[stftkey]				
				for i in sorted(tree.keys()):					
					node = tree[i] 
					gov = node.get("gov",{}).items()
					govid = -1
					func = "_"
					if gov:
						for govid,func in gov:
							if columns==10:
								treestring+="\t".join([str(i), node.get("t","_"), node.get("lemma",""), node.get("tag","_"), node.get("xpos","_"), "_", str(govid),func,"_","_"])+"\n"
							elif columns==14:
								lemma = node.get("lemma","_")
								if lemma == "_": lemma = node.get("t","_")
								treestring+="\t".join([str(i), node.get("t","_"), lemma, lemma or node.get("t","_"), node.get("tag","_"), node.get("tag","_"), node.get("morph","_"), node.get("morph","_"), str(govid),str(govid),func,func,"_","_"])+"\n"
					else:
						if columns==10:
							treestring+="\t".join([str(i), node.get("t","_"), node.get("lemma",""), node.get("tag","_"), node.get("xpos","_"), "_", str(govid),func,"_","_"])+"\n"
							
						elif columns==14:
							lemma = node.get("lemma","_")
							if lemma == "_": lemma = node.get("t","_")
							treestring+="\t".join([str(i), node.get("t","_"), lemma, lemma, node.get("tag","_"), node.get("tag","_"), node.get("morph","_"), node.get("morph","_"), str(govid),str(govid),func,func,"_","_"])+"\n"
			f.write(treestring+"\n")

	exports a list of treedics into outfile
	used after tree transformations...
	in conll14 format, the lemma position contains a duplicated t if lemma is not available
	
exports a list of treedics into outfile
used after tree transformations
in conll14 format, the lemma position contains a duplicated t if lemma is not available
exports a list of treedics into outfile used after tree transformations in conll14 format the lemma position contains a duplicated t if lemma is not available
def trees2conllFile(trees, outfile, columns="u", includeSentenceFeatures=True): 
        with codecs.open(outfile,"w","utf-8") as f:
		for tree in trees:
			if columns=="u": 
				treestring = tree.conllu()
			else:
				treestring = ""
				if includeSentenceFeatures:
					for stftkey in sorted(tree.sentencefeatures):
						if stftkey=="_comments":
							treestring+=tree.sentencefeatures[stftkey]
						else:
							treestring+=stftkey+" = "+tree.sentencefeatures[stftkey]				
				for i in sorted(tree.keys()):					
					node = tree[i] 
					gov = node.get("gov",{}).items()
					govid = -1
					func = "_"
					if gov:
						for govid,func in gov:
							if columns==10:
								treestring+="\t".join([str(i), node.get("t","_"), node.get("lemma",""), node.get("tag","_"), node.get("xpos","_"), "_", str(govid),func,"_","_"])+"\n"
							elif columns==14:
								lemma = node.get("lemma","_")
								if lemma == "_": lemma = node.get("t","_")
								treestring+="\t".join([str(i), node.get("t","_"), lemma, lemma or node.get("t","_"), node.get("tag","_"), node.get("tag","_"), node.get("morph","_"), node.get("morph","_"), str(govid),str(govid),func,func,"_","_"])+"\n"
					else:
						if columns==10:
							treestring+="\t".join([str(i), node.get("t","_"), node.get("lemma",""), node.get("tag","_"), node.get("xpos","_"), "_", str(govid),func,"_","_"])+"\n"
						elif columns==14:
							lemma = node.get("lemma","_")
							if lemma == "_": lemma = node.get("t","_")
							treestring+="\t".join([str(i), node.get("t","_"), lemma, lemma, node.get("tag","_"), node.get("tag","_"), node.get("morph","_"), node.get("morph","_"), str(govid),str(govid),func,func,"_","_"])+"\n"
			f.write(treestring+"\n")
def trees2conllFile ( trees , outfile , columns = "u" , includeSentenceFeatures = True ) : with codecs . open ( outfile , "w" , "utf-8" ) as f : for tree in trees : if columns == "u" : treestring = tree . conllu ( ) else : treestring = "" if includeSentenceFeatures : for stftkey in sorted ( tree . sentencefeatures ) : if stftkey == "_comments" : treestring += tree . sentencefeatures [ stftkey ] else : treestring += stftkey + " = " + tree . sentencefeatures [ stftkey ] for i in sorted ( tree . keys ( ) ) : node = tree [ i ] gov = node . get ( "gov" , { } ) . items ( ) govid = - 1 func = "_" if gov : for govid , func in gov : if columns == 10 : treestring += "\t" . join ( [ str ( i ) , node . get ( "t" , "_" ) , node . get ( "lemma" , "" ) , node . get ( "tag" , "_" ) , node . get ( "xpos" , "_" ) , "_" , str ( govid ) , func , "_" , "_" ] ) + "\n" elif columns == 14 : lemma = node . get ( "lemma" , "_" ) if lemma == "_" : lemma = node . get ( "t" , "_" ) treestring += "\t" . join ( [ str ( i ) , node . get ( "t" , "_" ) , lemma , lemma or node . get ( "t" , "_" ) , node . get ( "tag" , "_" ) , node . get ( "tag" , "_" ) , node . get ( "morph" , "_" ) , node . get ( "morph" , "_" ) , str ( govid ) , str ( govid ) , func , func , "_" , "_" ] ) + "\n" else : if columns == 10 : treestring += "\t" . join ( [ str ( i ) , node . get ( "t" , "_" ) , node . get ( "lemma" , "" ) , node . get ( "tag" , "_" ) , node . get ( "xpos" , "_" ) , "_" , str ( govid ) , func , "_" , "_" ] ) + "\n" elif columns == 14 : lemma = node . get ( "lemma" , "_" ) if lemma == "_" : lemma = node . get ( "t" , "_" ) treestring += "\t" . join ( [ str ( i ) , node . get ( "t" , "_" ) , lemma , lemma , node . get ( "tag" , "_" ) , node . get ( "tag" , "_" ) , node . get ( "morph" , "_" ) , node . get ( "morph" , "_" ) , str ( govid ) , str ( govid ) , func , func , "_" , "_" ] ) + "\n" f . write ( treestring + "\n" )
exports a list of treedics into outfile
used after tree transformations...
in conll14 format, the lemma position contains a duplicated t if lemma is not available
exports a list of treedics into outfile used after tree transformations ... in conll14 format the lemma position contains a duplicated t if lemma is not available
# changed default from 10 to u! """
	exports a list of treedics into outfile
	used after tree transformations...
	in conll14 format, the lemma position contains a duplicated t if lemma is not available
	""" # conllu format
trees
outfile
columns
includeSentenceFeatures