当前位置: 首页>>代码示例>>Python>>正文


Python TreeNode.key方法代码示例

本文整理汇总了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
开发者ID:jasenmh,项目名称:290D-Yelp,代码行数:35,代码来源:YelpDataContainer.py

示例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)
开发者ID:jasenmh,项目名称:290D-Yelp,代码行数:37,代码来源:yelpdata.py


注:本文中的TreeNode.TreeNode.key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。