def test_graph_add_nodes(self): graph = InferenceGraph() alist1 = Alist( **{ tt.ID: '1', tt.SUBJECT: '$y', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1, '$y': 'Ghana' }) alist2 = Alist( **{ tt.ID: '101', tt.SUBJECT: 'Africa', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1 }) graph.add_alists_from([alist1, alist2]) nodes = graph.nodes() print(nodes) self.assertTrue(len(nodes) == 2)
def create_graph2(self): graph = InferenceGraph() parent = Alist( **{ tt.ID: '1', tt.SUBJECT: 'Africa', tt.PROPERTY: 'P1082', tt.OBJECT: '', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1 }) child = Alist( **{ tt.ID: '1', tt.SUBJECT: 'Ghana', tt.PROPERTY: 'P1082', tt.OBJECT: '', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 2 }) child2 = Alist( **{ tt.ID: '1', tt.SUBJECT: 'a_Ghana', tt.PROPERTY: 'P1082', tt.OBJECT: '', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 5 }) grandchild = Alist( **{ tt.ID: '1', tt.SUBJECT: 'b_Ghana', tt.PROPERTY: 'P1082', tt.OBJECT: '', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 3 }) ggrandchild = Alist( **{ tt.ID: '1', tt.SUBJECT: 'c_Ghana', tt.PROPERTY: 'P1082', tt.OBJECT: '', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 4 }) # ggrandchild.state = states.EXPLORED graph.add_alists_from([parent]) graph.link(parent, child, edge_label='TP') graph.link(parent, child2, edge_label='GS') graph.link(child, grandchild, edge_label='GS') graph.link(grandchild, ggrandchild, edge_label='GS') return graph
def test_graph_add_nodes_and_edges(self): graph = InferenceGraph() alist1 = Alist( **{ tt.ID: '1', tt.SUBJECT: '$y', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1, '$y': 'Ghana' }) alist2 = Alist( **{ tt.ID: '101', tt.SUBJECT: 'Africa', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1 }) alist3 = Alist( **{ tt.ID: '102', tt.SUBJECT: 'Africa', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1 }) graph.add_alists_from([alist1]) # plt.ion() # # plt.plot() # fig = plt.figure() # plt.show() # graph.display() graph.plot_plotly("Graph 1") # plt.pause(0.3) graph.link(alist1, alist2, edge_label='TP') graph.link(alist1, alist3, edge_label='GS') edges = graph.edges() # plt.clf() # graph.display() # plt.pause(2) graph.plot_plotly("Graph 2") self.assertTrue(len(edges) > 0)
def create_graph(self): graph = InferenceGraph() alist1 = Alist( **{ tt.ID: '1', tt.SUBJECT: '$y', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1, '$y': 'Ghana' }) alist2 = Alist( **{ tt.ID: '101', tt.SUBJECT: 'Africa', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1 }) alist3 = Alist( **{ tt.ID: '102', tt.SUBJECT: 'Africa', tt.PROPERTY: 'P1082', tt.OBJECT: '?x', tt.TIME: '2010', tt.OPVAR: '?x', tt.COST: 1 }) graph.add_alists_from([alist1]) graph.link(alist1, alist2, edge_label='TP') graph.link(alist1, alist3, edge_label='GS') return graph