1
+ import pyreason as pr
2
+
3
+
4
+ def test_anyBurl_rule_1_fp ():
5
+ graph_path = './tests/knowledge_graph_test_subset.graphml'
6
+ pr .reset ()
7
+ pr .reset_rules ()
8
+ pr .reset_settings ()
9
+ # Modify pyreason settings to make verbose and to save the rule trace to a file
10
+ pr .settings .verbose = True
11
+ pr .settings .atom_trace = True
12
+ pr .settings .memory_profile = False
13
+ pr .settings .canonical = True
14
+ pr .settings .inconsistency_check = False
15
+ pr .settings .static_graph_facts = False
16
+ pr .settings .output_to_file = False
17
+ pr .settings .store_interpretation_changes = True
18
+ pr .settings .save_graph_attributes_to_trace = True
19
+ pr .settings .fp_version = True
20
+ # Load all the files into pyreason
21
+ pr .load_graphml (graph_path )
22
+ pr .add_rule (pr .Rule ('isConnectedTo(A, Y) <-1 isConnectedTo(Y, B), Amsterdam_Airport_Schiphol(B), Vnukovo_International_Airport(A)' , 'connected_rule_1' , infer_edges = True ))
23
+
24
+ # Run the program for two timesteps to see the diffusion take place
25
+ interpretation = pr .reason (timesteps = 1 )
26
+ # pr.save_rule_trace(interpretation)
27
+
28
+ # Display the changes in the interpretation for each timestep
29
+ dataframes = pr .filter_and_sort_edges (interpretation , ['isConnectedTo' ])
30
+ for t , df in enumerate (dataframes ):
31
+ print (f'TIMESTEP - { t } ' )
32
+ print (df )
33
+ print ()
34
+ assert len (dataframes ) == 2 , 'Pyreason should run exactly 2 fixpoint operations'
35
+ assert len (dataframes [1 ]) == 1 , 'At t=1 there should be only 1 new isConnectedTo atom'
36
+ assert ('Vnukovo_International_Airport' , 'Riga_International_Airport' ) in dataframes [1 ]['component' ].values .tolist () and dataframes [1 ]['isConnectedTo' ].iloc [0 ] == [1 , 1 ], '(Vnukovo_International_Airport, Riga_International_Airport) should have isConnectedTo bounds [1,1] for t=1 timesteps'
37
+
38
+
39
+ def test_anyBurl_rule_2_fp ():
40
+ graph_path = './tests/knowledge_graph_test_subset.graphml'
41
+ pr .reset ()
42
+ pr .reset_rules ()
43
+ pr .reset_settings ()
44
+ # Modify pyreason settings to make verbose and to save the rule trace to a file
45
+ pr .settings .verbose = True
46
+ pr .settings .atom_trace = True
47
+ pr .settings .memory_profile = False
48
+ pr .settings .canonical = True
49
+ pr .settings .inconsistency_check = False
50
+ pr .settings .static_graph_facts = False
51
+ pr .settings .output_to_file = False
52
+ pr .settings .store_interpretation_changes = True
53
+ pr .settings .save_graph_attributes_to_trace = True
54
+ pr .settings .parallel_computing = False
55
+ # Load all the files into pyreason
56
+ pr .load_graphml (graph_path )
57
+
58
+ pr .add_rule (pr .Rule ('isConnectedTo(Y, A) <-1 isConnectedTo(Y, B), Amsterdam_Airport_Schiphol(B), Vnukovo_International_Airport(A)' , 'connected_rule_2' , infer_edges = True ))
59
+
60
+ # Run the program for two timesteps to see the diffusion take place
61
+ interpretation = pr .reason (timesteps = 1 )
62
+ # pr.save_rule_trace(interpretation)
63
+
64
+ # Display the changes in the interpretation for each timestep
65
+ dataframes = pr .filter_and_sort_edges (interpretation , ['isConnectedTo' ])
66
+ for t , df in enumerate (dataframes ):
67
+ print (f'TIMESTEP - { t } ' )
68
+ print (df )
69
+ print ()
70
+ assert len (dataframes ) == 2 , 'Pyreason should run exactly 2 fixpoint operations'
71
+ assert len (dataframes [1 ]) == 1 , 'At t=1 there should be only 1 new isConnectedTo atom'
72
+ assert ('Riga_International_Airport' , 'Vnukovo_International_Airport' ) in dataframes [1 ]['component' ].values .tolist () and dataframes [1 ]['isConnectedTo' ].iloc [0 ] == [1 , 1 ], '(Riga_International_Airport, Vnukovo_International_Airport) should have isConnectedTo bounds [1,1] for t=1 timesteps'
73
+
74
+
75
+ def test_anyBurl_rule_3_fp ():
76
+ graph_path = './tests/knowledge_graph_test_subset.graphml'
77
+ pr .reset ()
78
+ pr .reset_rules ()
79
+ pr .reset_settings ()
80
+ # Modify pyreason settings to make verbose and to save the rule trace to a file
81
+ pr .settings .verbose = True
82
+ pr .settings .atom_trace = True
83
+ pr .settings .memory_profile = False
84
+ pr .settings .canonical = True
85
+ pr .settings .inconsistency_check = False
86
+ pr .settings .static_graph_facts = False
87
+ pr .settings .output_to_file = False
88
+ pr .settings .store_interpretation_changes = True
89
+ pr .settings .save_graph_attributes_to_trace = True
90
+ pr .settings .parallel_computing = False
91
+ # Load all the files into pyreason
92
+ pr .load_graphml (graph_path )
93
+
94
+ pr .add_rule (pr .Rule ('isConnectedTo(A, Y) <-1 isConnectedTo(B, Y), Amsterdam_Airport_Schiphol(B), Vnukovo_International_Airport(A)' , 'connected_rule_3' , infer_edges = True ))
95
+
96
+ # Run the program for two timesteps to see the diffusion take place
97
+ interpretation = pr .reason (timesteps = 1 )
98
+ # pr.save_rule_trace(interpretation)
99
+
100
+ # Display the changes in the interpretation for each timestep
101
+ dataframes = pr .filter_and_sort_edges (interpretation , ['isConnectedTo' ])
102
+ for t , df in enumerate (dataframes ):
103
+ print (f'TIMESTEP - { t } ' )
104
+ print (df )
105
+ print ()
106
+ assert len (dataframes ) == 2 , 'Pyreason should run exactly 1 fixpoint operations'
107
+ assert len (dataframes [1 ]) == 1 , 'At t=1 there should be only 1 new isConnectedTo atom'
108
+ assert ('Vnukovo_International_Airport' , 'Yali' ) in dataframes [1 ]['component' ].values .tolist () and dataframes [1 ]['isConnectedTo' ].iloc [0 ] == [1 , 1 ], '(Vnukovo_International_Airport, Yali) should have isConnectedTo bounds [1,1] for t=1 timesteps'
109
+
110
+
111
+ def test_anyBurl_rule_4_fp ():
112
+ graph_path = './tests/knowledge_graph_test_subset.graphml'
113
+ pr .reset ()
114
+ pr .reset_rules ()
115
+ pr .reset_settings ()
116
+ # Modify pyreason settings to make verbose and to save the rule trace to a file
117
+ pr .settings .verbose = True
118
+ pr .settings .atom_trace = True
119
+ pr .settings .memory_profile = False
120
+ pr .settings .canonical = True
121
+ pr .settings .inconsistency_check = False
122
+ pr .settings .static_graph_facts = False
123
+ pr .settings .output_to_file = False
124
+ pr .settings .store_interpretation_changes = True
125
+ pr .settings .save_graph_attributes_to_trace = True
126
+ pr .settings .parallel_computing = False
127
+ # Load all the files into pyreason
128
+ pr .load_graphml (graph_path )
129
+
130
+ pr .add_rule (pr .Rule ('isConnectedTo(Y, A) <-1 isConnectedTo(B, Y), Amsterdam_Airport_Schiphol(B), Vnukovo_International_Airport(A)' , 'connected_rule_4' , infer_edges = True ))
131
+
132
+ # Run the program for two timesteps to see the diffusion take place
133
+ interpretation = pr .reason (timesteps = 1 )
134
+ # pr.save_rule_trace(interpretation)
135
+
136
+ # Display the changes in the interpretation for each timestep
137
+ dataframes = pr .filter_and_sort_edges (interpretation , ['isConnectedTo' ])
138
+ for t , df in enumerate (dataframes ):
139
+ print (f'TIMESTEP - { t } ' )
140
+ print (df )
141
+ print ()
142
+ assert len (dataframes ) == 2 , 'Pyreason should run exactly 1 fixpoint operations'
143
+ assert len (dataframes [1 ]) == 1 , 'At t=1 there should be only 1 new isConnectedTo atom'
144
+ assert ('Yali' , 'Vnukovo_International_Airport' ) in dataframes [1 ]['component' ].values .tolist () and dataframes [1 ]['isConnectedTo' ].iloc [0 ] == [1 , 1 ], '(Yali, Vnukovo_International_Airport) should have isConnectedTo bounds [1,1] for t=1 timesteps'
0 commit comments