python 用句子树练习

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 用句子树练习相关的知识,希望对你有一定的参考价值。

#Sentence Tree
#The sentence tree is a special data structure that can group sentences together n a space optimized tree
#This means that, when a sentence is split by spaces, using the .split() method of strings,
#the tree can storage and look up these words in N words per sentence.
#The tree specifically uses dictionaries for this purpose as opposed to nodes



class SentenceTrie:
	
	def __init__(self):
		self.trie = {}
	def __repr__(self):
		return str(self.trie)
	def __str__(self):
		return str(self.trie)
	def statement(self, phrase):
		pass
	def has_statement(self, phrase):
	  pass
  
"""   f = SentenceTrie()
=> None
   f.statement("Hello Aarsh what's up?")
=> None
   f.trie
=> {'Hello': {'Aarsh': {"what's": {'up?': {}}}}}
   f.statement("Want to play table tennis?")
=> None
   f
=> {'Hello': {'Aarsh': {"what's": {'up?': {}}}}, 'Want': {'to': {'play': {'table': {'tennis?': {}}}}}}
   f.statement("Hello world!")
=> None
   f.trie
=> {'Hello': {'Aarsh': {"what's": {'up?': {}}}, 'world!': {}}, 'Want': {'to': {'play': {'table': {'tennis?': {}}}}}}
   f.has_statement("Hello world!")
=> True
   f.has_statement("Hello world")
=> False
   """

以上是关于python 用句子树练习的主要内容,如果未能解决你的问题,请参考以下文章

练习题三:句子反转

Python中字符的练习

华为机试练习句子逆序

如何为 NLTK 中的歧义句子生成多个解析树?

《python从入门到实践》--第四章基本操作列表 重点及课后练习

Python算法练习--把搜索树转成双向链表