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


Python Node.add_child方法代码示例

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


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

示例1: generate_adjacency_list

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import add_child [as 别名]
    def generate_adjacency_list(file_path):
        adjacency_dictionary = {}
        f = open(file_path, 'r')

        for line in f:
            split = line.replace('\n', '').split(' ')
            node1 = None
            node2 = None

            # Get the first node.
            if split[0] not in adjacency_dictionary.keys():
                node1 = Node(split[0])
                adjacency_dictionary[split[0]] = node1
            else:
                node1 = adjacency_dictionary[split[0]]

            # Get the second node.
            if split[1] not in adjacency_dictionary.keys():
                node2 = Node(split[1])
                adjacency_dictionary[split[1]] = node2
            else:
                node2 = adjacency_dictionary[split[1]]

            if not node1.has_child(node2):
                node1.add_child(node2, split[2])

            if not node2.has_child(node1):
                node2.add_child(node1, split[2])

        return adjacency_dictionary
开发者ID:akshaykamath,项目名称:AI-Search-Algorithms,代码行数:32,代码来源:GraphBuilder.py

示例2: create

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import add_child [as 别名]
    def create(self, node, children):
        current_node = Node(node)

        for child in children:
            if child not in self.nodes:
                child_node = Node(child)
                current_node.add_child(child_node)
            else:
                child_node = Node(self.node_hash[child])
                current_node.add_child(child_node)

        return current_node
开发者ID:DanLindeman,项目名称:luthor,代码行数:14,代码来源:Graph.py

示例3: construct_reply_tree

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import add_child [as 别名]
    def construct_reply_tree(self, tweet):

        # Search for replies to the given tweet
        raw_search_results = self.api.search("q='to:{}'".format(tweet.user.screen_name), sinceId = tweet.id)
        filtered_search_results = [result for result in raw_search_results if result.in_reply_to_user_id == tweet.user.id]

        print("q='to:{}'".format(tweet.user.screen_name))
        print("Found {} results, with final {}".format(len(raw_search_results), len(filtered_search_results)))

        # Construct the tree for this tweet
        new_reply_node = Node(tweet)

        # Base case is when there are no found replies to the given tweet
        for reply_tweet in filtered_search_results:
            new_reply_node.add_child(self.construct_reply_tree(reply_tweet))

        return new_reply_node
开发者ID:darkaeon10,项目名称:ms-thesis,代码行数:19,代码来源:TweetHelper.py

示例4: build_network

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import add_child [as 别名]
    def build_network():
        burglary = Node("B")
        earthquake = Node("E")
        alarm = Node("A")
        john = Node("J")
        mary = Node("M")

        burglary.add_child(alarm)
        earthquake.add_child(alarm)
        alarm.add_child(john)
        alarm.add_child(mary)

        cpt_burglary = {'T': 0.001}
        cpt_earthquake = {'T': 0.002}
        cpt_alarm = {('T', 'T'): 0.95, ('T', 'F'): 0.94, ('F', 'T'): 0.29, ('F', 'F'): 0.0010}
        cpt_john_calls = {'T': 0.90, 'F': 0.05}
        cpt_mary_calls = {'T': 0.70, 'F': 0.01}

        burglary.conditional_probability_table = cpt_burglary
        earthquake.conditional_probability_table = cpt_earthquake
        alarm.conditional_probability_table = cpt_alarm
        john.conditional_probability_table = cpt_john_calls
        mary.conditional_probability_table = cpt_mary_calls

        bayes_net_order = [burglary, earthquake, alarm, john, mary]

        return bayes_net_order
开发者ID:akshaykamath,项目名称:Bayes-Network-Inference-Algorithms,代码行数:29,代码来源:BayesNetBuilder.py

示例5: test_node_printing

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import add_child [as 别名]
def test_node_printing():
    node1 = Node("1")
    node2 = Node("2")
    node3 = Node("3")
    node4 = Node("4")
    node5 = Node("5")
    node6 = Node("6")
    node7 = Node("7")
    node8 = Node("8")

    node1.add_child(node2)
    node1.add_child(node3)

    node2.add_child(node4)

    node3.add_child(node5)
    node3.add_child(node6)
    node3.add_child(node7)

    node7.add_child(node8)

    print(node1)

    print("Count of nodes is {}".format(count_nodes(node1)))
开发者ID:darkaeon10,项目名称:ms-thesis,代码行数:26,代码来源:Driver.py

示例6: Tree

# 需要导入模块: from Node import Node [as 别名]
# 或者: from Node.Node import add_child [as 别名]
reg_cost = 0.001
l_rate = 0.1

predictions = None
target = np.array([1, 0])
target = target[:, np.newaxis]


tree = Tree()
tree.root = Node()
node = Node(np.random.rand(dim, 1))
tree.root.add_child(node)
node = Node()
tree.root.add_child(node)
node1 = Node(np.random.rand(dim, 1))
node.add_child(node1)
node1 = Node(np.random.rand(dim, 1))
node.add_child(node1)


tree1 = Tree()
tree1.root = Node()
node = Node(np.random.rand(dim, 1))
tree1.root.add_child(node)
node = Node()
tree1.root.add_child(node)
node1 = Node(np.random.rand(dim, 1))
node.add_child(node1)
node1 = Node(np.random.rand(dim, 1))
node.add_child(node1)
开发者ID:mohummedalee,项目名称:politeness,代码行数:32,代码来源:neural.py


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