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


Python Tree.all_nodes方法代码示例

本文整理汇总了Python中treelib.Tree.all_nodes方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.all_nodes方法的具体用法?Python Tree.all_nodes怎么用?Python Tree.all_nodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在treelib.Tree的用法示例。


在下文中一共展示了Tree.all_nodes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: conversation_regarding_language

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import all_nodes [as 别名]
def conversation_regarding_language(cursor):
    conversation_amount = postgres_queries.find_conversation_number(cursor)
    conversation_list = list()
    depth_dict = dict()
    depth_dict_long = dict()
    depth_dict_short = dict()
    number_of_tweets_dict = dict()
    test_i = 0
    for i in range(0, conversation_amount + 1, 1):
        conversation_tree = Tree()
        conversation = postgres_queries.find_conversation(i, cursor)
        test_i += len(conversation)
        for tweet in conversation:
            if tweet[2] is None and tweet[5] is True:
                conversation_tree.create_node(tweet[0], tweet[0])
                tweets_in_conversation = list()
                build_conversation_lang(tweet[0], conversation, conversation_tree, tweets_in_conversation)
                depth = conversation_tree.depth() + 1
                number_of_tweets = len(conversation_tree.all_nodes())
                #short/long
                if number_of_tweets >=20:
                    if depth in depth_dict_long:
                        depth_dict_long[depth] += 1
                    else:
                        depth_dict_long[depth] = 1
                else:
                    if depth in depth_dict_short:
                        depth_dict_short[depth] += 1
                    else:
                        depth_dict_short[depth] = 1

                if number_of_tweets in number_of_tweets_dict:
                    number_of_tweets_dict[number_of_tweets] += 1
                else:
                     number_of_tweets_dict[number_of_tweets] = 1
                if depth in depth_dict:
                    depth_dict[depth] += 1
                else:
                    depth_dict[depth] = 1
        # check if conversation_tree is null- dont add
        if len(conversation_tree.all_nodes())!=0:
            conversation_list.append(conversation_tree)
    # number = 0
    new_tweet_list_id = list()
    for con in conversation_list:
        nodes = con.all_nodes()
        for node in nodes:
            new_tweet_list_id.append(int(node.tag))
        # number += len(con.all_nodes())
    # print len(new_tweet_list_id)
    # for tweet_id in new_tweet_list_id:
    #     print tweet_id
    return new_tweet_list_id, conversation_list
开发者ID:anukat2015,项目名称:Twitter_DA_Recognition,代码行数:55,代码来源:rebuild_conversations.py

示例2: types_of_conversation

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import all_nodes [as 别名]
def types_of_conversation():
    conversation_amount = postgres_queries.find_annotated_conversation_number()
    conversation_list = list()
    depth_dict = dict()
    depth_dict_long = dict()
    depth_dict_short = dict()
    number_of_tweets_dict = dict()
    for i in range (0, conversation_amount + 1, 1):
        conversation_tree = Tree()
        converastion = postgres_queries.find_conversation(i)
        for tweet in converastion:
            if tweet[1] is None:
                conversation_tree.create_node(tweet[0], tweet[0])
                build_conversation(tweet[0], converastion, conversation_tree)
                depth = conversation_tree.depth() + 1
                number_of_tweets = len(conversation_tree.all_nodes())
                #short/long
                if number_of_tweets >=20:
                    if depth in depth_dict_long:
                        depth_dict_long[depth] += 1
                    else:
                        depth_dict_long[depth] = 1
                else:
                    if depth in depth_dict_short:
                        depth_dict_short[depth] += 1
                    else:
                        depth_dict_short[depth] = 1

                if number_of_tweets in number_of_tweets_dict:
                    number_of_tweets_dict[number_of_tweets] += 1
                else:
                     number_of_tweets_dict[number_of_tweets] = 1
                if depth in depth_dict:
                    depth_dict[depth] += 1
                else:
                    depth_dict[depth] = 1
        conversation_list.append(conversation_tree)
    #print depth_dict
    print 'Depth of a conversation'
    for depth, count in depth_dict.iteritems():
        print depth, '\t', count
    print 'Number of tweets in a conversation'
    for number, count in number_of_tweets_dict.iteritems():
        print number, '\t', count
    print 'Depth of a long conversation'
    for depth, count in depth_dict_long.iteritems():
        print depth, '\t', count
    print 'Depth of a short conversation'
    for depth, count in depth_dict_short.iteritems():
        print depth, '\t', count

    return conversation_list
开发者ID:imclab,项目名称:Twitter_DA_Recognition,代码行数:54,代码来源:test.py

示例3: crossOver

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import all_nodes [as 别名]
  def crossOver(individualA, individualB):
    tree = None

    while tree is None or tree.depth(tree.get_node(tree.root)) > TREE_MAX_DEPTH:
      treeA = Tree(tree = individualA.tree, deep=True)
      treeB = Tree(tree = individualB.tree, deep=True)
      regenerate_ids(treeA)
      regenerate_ids(treeB)
      removedNode = random.choice(treeA.all_nodes())
      addedNode = random.choice(treeB.all_nodes())

      addedSubtree = Tree(tree = treeB.subtree(addedNode.identifier), deep=True)

      if treeA.root == removedNode.identifier:
        tree = addedSubtree

      else:
        parent = treeA.parent(removedNode.identifier)
        treeA.remove_subtree(removedNode.identifier)
        treeA.paste(parent.identifier, addedSubtree)
        tree = treeA

    return Individual(tree)
开发者ID:liranr23,项目名称:genersi,代码行数:25,代码来源:individual.py

示例4: conversation_regarding_language

# 需要导入模块: from treelib import Tree [as 别名]
# 或者: from treelib.Tree import all_nodes [as 别名]
def conversation_regarding_language(): # with width and depth
    conversation_amount = postgres_queries.find_annotated_conversation_number()
    conversation_list = list()
    depth_dict = dict()
    depth_dict_long = dict()
    depth_dict_short = dict()
    number_of_tweets_dict = dict()
    test_i = 0
    for i in range(0, conversation_amount + 1, 1):
        conversation_tree = Tree()
        converastion = postgres_queries.find_conversation(i)
        test_i += len(converastion)
        for tweet in converastion:
            if tweet[1] is None and tweet[5] is True:
                conversation_tree.create_node(tweet[0], tweet[0])
                build_conversation_lang(tweet[0], converastion, conversation_tree)
                depth = conversation_tree.depth() + 1
                number_of_tweets = len(conversation_tree.all_nodes())
                #short/long
                if number_of_tweets >=20:
                    if depth in depth_dict_long:
                        depth_dict_long[depth] += 1
                    else:
                        depth_dict_long[depth] = 1
                else:
                    if depth in depth_dict_short:
                        depth_dict_short[depth] += 1
                    else:
                        depth_dict_short[depth] = 1

                if number_of_tweets in number_of_tweets_dict:
                    number_of_tweets_dict[number_of_tweets] += 1
                else:
                     number_of_tweets_dict[number_of_tweets] = 1
                if depth in depth_dict:
                    depth_dict[depth] += 1
                else:
                    depth_dict[depth] = 1
        conversation_list.append(conversation_tree)
    number = 0
    new_tweet_list_id = list()
    for con in conversation_list:
        nodes = con.all_nodes()
        for node in nodes:
            new_tweet_list_id.append(node.tag)
        number += len(con.all_nodes())

    return new_tweet_list_id, conversation_list
开发者ID:imclab,项目名称:Twitter_DA_Recognition,代码行数:50,代码来源:rebuild_conversations.py


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