本文整理汇总了Python中TreeNode.TreeNode.key方法的典型用法代码示例。如果您正苦于以下问题:Python TreeNode.key方法的具体用法?Python TreeNode.key怎么用?Python TreeNode.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TreeNode.TreeNode
的用法示例。
在下文中一共展示了TreeNode.key方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: findSentimentByBusinessID
# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import key [as 别名]
def findSentimentByBusinessID(self, busID):
"""
Finds the sentiment class for a specific business and returns it. If
the sentiment does not exist, one is created.
"""
v = 0
if self.sentRoot == 0: # no sentiments yet
bs = BusinessSentiment(busID)
self.sentiment.append(bs)
s = TreeNode()
s.key = busID
s.value = bs
self.sentRoot = s
v = s.value
else: # there are some sentiments, lets try to find ours
s = self.sentRoot.findValueByKey(busID)
if s == 0: # didn't find one, make it up
bs = BusinessSentiment(busID)
self.sentiment.append(bs)
s = TreeNode()
s.key = busID
s.value = bs
v = s.value
else:
v = s
#try:
# v = s.value
#except AttributeError:
# print "Found broken sentiment for ID", busID
# v = 0
return v
示例2: importJSONbusiness
# 需要导入模块: from TreeNode import TreeNode [as 别名]
# 或者: from TreeNode.TreeNode import key [as 别名]
def importJSONbusiness(dataFile):
"""
parameters:
dataFile - name of file containing business JSON objects
returns:
busData - list containing dictionaries representing Yelp businesses
"""
busData = []
rootNode = 0
try:
bus = open(dataFile)
except IOError:
print "Unable to open data file: ", dataFile
return -1
for line in bus:
try:
data = json.loads(line)
except ValueError:
print "Failed to convert JSON object to dictionary"
return -1
n = TreeNode()
n.key = data["business_id"]
n.value = data
busData.append(n)
if rootNode == 0:
rootNode = n
else:
rootNode.insert(n)
return (busData, rootNode)