-
Notifications
You must be signed in to change notification settings - Fork 4
/
relatednesstest.py
51 lines (47 loc) · 1.79 KB
/
relatednesstest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import matplotlib.pyplot as plt
import networkx as nx
from relatedness import *
dog_entities = ["dog", "cat", "horse", "saddle", "rider", "mouse", "cheese",
"churning", "milk", "cow", "human", "race", "gambling"]
dog_connections = [("dog", "cat", 50),
("dog", "horse", 10),
("horse", "saddle", 60),
("horse", "rider", 30),
("rider", "saddle", 40),
("horse", "race", 30),
("rider", "race", 35),
("dog", "race", 20),
("cat", "mouse", 50),
("race", "gambling", 40),
("mouse", "cheese", 50),
("cheese", "milk", 60),
("milk", "cow", 60),
("cheese", "cow", 30),
("rider", "human", 50),
("milk", "churning", 20),
("human", "gambling", 30)]
def get_test_network1():
""" Returns a sample Semantic_Network.
"""
network = Semantic_Network()
network.add_entities(dog_entities)
network.add_connections(dog_connections)
return network
def draw_network(network, location=None):
""" Displays in an interactive window a visualization of the graph underlying the specified Semantic_Network.
"""
graph = network.graph
draw_graph(graph, location)
def draw_graph(graph, location=None):
""" Displays in an interactive window a visualization of the specifed graph.
"""
positions = nx.spring_layout(graph)
labels = get_capacity_dict(graph)
plt.clf()
nx.draw(graph, positions)
nx.draw_networkx_edge_labels(graph, positions, edge_labels=labels)
if location is None:
plt.ion()
plt.show()
else:
plt.savefig(location)