本文整理汇总了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
示例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
示例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
示例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
示例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)))
示例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)