M1-Arborator-NaijaSUD/arborator/lib/treebankfiles.py
def correcttree2nodedic(tree,catname="cat"):
		""" 
		takes the conll string representation of a single tree and creates a dictionary for it
		here special format: spacelemmas
		"""
	
		nodedic={}
		for line in tree.split('\n'):
			line=line.strip()
			
			#print "___",line
			if line:
				cells = line.split('\t')
				nrCells = len(cells)
				if nrCells in [6,7]:
					if nrCells == 6:
						nr, t, lemma, tag, head, rel = cells
						#nr,head = int(nr), int(head)
						if int(head)>=0:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{'i'+head: rel} }
						else:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{} }
					elif nrCells == 7:
						nr, t, lemma, tag, head, rel, child = cells
						
						#nr,head = int(nr), int(head)
						#if lemma2!="_": lemma=lemma2 # TODO: find out what the difference between these columns is!!!!!!
						if int(head)>=0:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{'i'+head: rel} }
						else:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{} }
						
						
						if child.strip()=="-":
							nodedic['i'+nr]["child"]=True
						else:
							print child,cells,"--- strange line:"
							print line
				else:
					print "strange line"
					print line
					print "in:"
					print tree
			
					
		return nodedic
 
		takes the conll string representation of a single tree and creates a dictionary for it
		here special format: spacelemmas
		
takes the conll string representation of a single tree and creates a dictionary for it
here special format: spacelemmas
takes the conll string representation of a single tree and creates a dictionary for it here special format : spacelemmas
def correcttree2nodedic(tree,catname="cat"):
		nodedic={}
		for line in tree.split('\n'):
			line=line.strip()
			if line:
				cells = line.split('\t')
				nrCells = len(cells)
				if nrCells in [6,7]:
					if nrCells == 6:
						nr, t, lemma, tag, head, rel = cells
						if int(head)>=0:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{'i'+head: rel} }
						else:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{} }
					elif nrCells == 7:
						nr, t, lemma, tag, head, rel, child = cells
						if int(head)>=0:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{'i'+head: rel} }
						else:nodedic['i'+nr]={'id':'i'+nr,tokenname: t,'lemma': lemma, catname: tag, 'gov':{} }
						if child.strip()=="-":
							nodedic['i'+nr]["child"]=True
						else:
							print child,cells,"--- strange line:"
							print line
				else:
					print "strange line"
					print line
					print "in:"
					print tree
		return nodedic
def correcttree2nodedic ( tree , catname = "cat" ) : nodedic = { } for line in tree . split ( '\n' ) : line = line . strip ( ) if line : cells = line . split ( '\t' ) nrCells = len ( cells ) if nrCells in [ 6 , 7 ] : if nrCells == 6 : nr , t , lemma , tag , head , rel = cells if int ( head ) >= 0 : nodedic [ 'i' + nr ] = { 'id' : 'i' + nr , tokenname : t , 'lemma' : lemma , catname : tag , 'gov' : { 'i' + head : rel } } else : nodedic [ 'i' + nr ] = { 'id' : 'i' + nr , tokenname : t , 'lemma' : lemma , catname : tag , 'gov' : { } } elif nrCells == 7 : nr , t , lemma , tag , head , rel , child = cells if int ( head ) >= 0 : nodedic [ 'i' + nr ] = { 'id' : 'i' + nr , tokenname : t , 'lemma' : lemma , catname : tag , 'gov' : { 'i' + head : rel } } else : nodedic [ 'i' + nr ] = { 'id' : 'i' + nr , tokenname : t , 'lemma' : lemma , catname : tag , 'gov' : { } } if child . strip ( ) == "-" : nodedic [ 'i' + nr ] [ "child" ] = True else : print child , cells , "--- strange line:" print line else : print "strange line" print line print "in:" print tree return nodedic
takes the conll string representation of a single tree and creates a dictionary for it
here special format: spacelemmas
takes the conll string representation of a single tree and creates a dictionary for it here special format : spacelemmas
""" 
		takes the conll string representation of a single tree and creates a dictionary for it
		here special format: spacelemmas
		""" #print "___",line #nr,head = int(nr), int(head) #nr,head = int(nr), int(head) #if lemma2!="_": lemma=lemma2 # TODO: find out what the difference between these columns is!!!!!!
tree
catname