Exemple #1
0
	def reconstructTree(self,treeString):
		
		wordLst = TreeSentenceFunctions.splitPhrases(treeString)

		for phrase in wordLst:
			if TreeSentenceFunctions.isLeafLevel(phrase): # base case
				decomposedTuple = TreeSentenceFunctions.decomposePhrase(phrase)
				tag = decomposedTuple[0]
				word = decomposedTuple[1]
				#if word[-1] in TreeNode.punctuations:
					#word = word[:-1]
				childNode = TreeNode(tag,word,len(self.children),(self.vertical + 1))
				self.children.append(childNode)
			else:
				topLevelTag = TreeSentenceFunctions.getTopLevelTag(phrase)
				childNode = TreeNode(topLevelTag, None, len(self.children), (self.vertical + 1))
				self.children.append(childNode) 
				childNode.reconstructTree(TreeSentenceFunctions.stripOneLevel(phrase))  
Exemple #2
0
	def treeStringToTree(treeString):
		topLevelTag = TreeSentenceFunctions.getTopLevelTag(treeString)
		root = TreeNode(tag=topLevelTag,hori=0,vert=0)
		root.reconstructTree(TreeSentenceFunctions.stripOneLevel(treeString))
		return root