Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any burl rules 4 types #56

Merged
merged 4 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions tests/knowledge_graph_test_subset.graphml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version='1.0' encoding='utf-8'?>
<graphml xmlns="http://graphml.graphdrawing.org/xmlns" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns http://graphml.graphdrawing.org/xmlns/1.0/graphml.xsd">
<key id="isConnectedTo" for="edge" attr.name="isConnectedTo" attr.type="long" />
<key id="Amsterdam_Airport_Schiphol" for="node" attr.name="Amsterdam_Airport_Schiphol" attr.type="long" />
<key id="Riga_International_Airport" for="node" attr.name="Riga_International_Airport" attr.type="long" />
<key id="Chișinău_International_Airport" for="node" attr.name="Chișinău_International_Airport" attr.type="long" />
<key id="Düsseldorf_Airport" for="node" attr.name="Düsseldorf_Airport" attr.type="long" />
<key id="Dubrovnik_Airport" for="node" attr.name="Dubrovnik_Airport" attr.type="long" />
<key id="Athens_International_Airport" for="node" attr.name="Athens_International_Airport" attr.type="long" />
<key id="Yali" for="node" attr.name="Yali" attr.type="long" />
<key id="Vnukovo_International_Airport" for="node" attr.name="Vnukovo_International_Airport" attr.type="long" />
<key id="Hévíz-Balaton_Airport" for="node" attr.name="Hévíz-Balaton_Airport" attr.type="long" />
<key id="Pobedilovo_Airport" for="node" attr.name="Pobedilovo_Airport" attr.type="long" />
<graph id="G" edgedefault="directed">
<node id="Amsterdam_Airport_Schiphol">
<data key="Amsterdam_Airport_Schiphol">1</data>
</node>
<node id="Riga_International_Airport">
<data key="Riga_International_Airport">1</data>
</node>
<node id="Chișinău_International_Airport">
<data key="Chișinău_International_Airport">1</data>
</node>
<node id="Yali">
<data key="Yali">1</data>
</node>
<node id="Düsseldorf_Airport">
<data key="Düsseldorf_Airport">1</data>
</node>
<node id="Pobedilovo_Airport">
<data key="Pobedilovo_Airport">1</data>
</node>
<node id="Dubrovnik_Airport">
<data key="Dubrovnik_Airport">1</data>
</node>
<node id="Hévíz-Balaton_Airport">
<data key="Hévíz-Balaton_Airport">1</data>
</node>
<node id="Athens_International_Airport">
<data key="Athens_International_Airport">1</data>
</node>
<node id="Vnukovo_International_Airport">
<data key="Vnukovo_International_Airport">1</data>
</node>
<edge source="Pobedilovo_Airport" target="Vnukovo_International_Airport">
<data key="isConnectedTo">1</data>
</edge>
<edge source="Vnukovo_International_Airport" target="Hévíz-Balaton_Airport">
<data key="isConnectedTo">1</data>
</edge>
<edge source="Düsseldorf_Airport" target="Dubrovnik_Airport">
<data key="isConnectedTo">1</data>
</edge>
<edge source="Dubrovnik_Airport" target="Athens_International_Airport">
<data key="isConnectedTo">1</data>
</edge>
<edge source="Riga_International_Airport" target="Amsterdam_Airport_Schiphol">
<data key="isConnectedTo">1</data>
</edge>
<edge source="Riga_International_Airport" target="Düsseldorf_Airport">
<data key="isConnectedTo">1</data>
</edge>
<edge source="Chișinău_International_Airport" target="Riga_International_Airport">
<data key="isConnectedTo">1</data>
</edge>
<edge source="Amsterdam_Airport_Schiphol" target="Yali">
<data key="isConnectedTo">1</data>
</edge>

</graph>
</graphml>
136 changes: 136 additions & 0 deletions tests/test_anyBurl_infer_edges_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import pyreason as pr


def test_anyBurl_rule_1():
graph_path = './tests/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
# Modify pyreason settings to make verbose and to save the rule trace to a file
pr.settings.verbose = True
pr.settings.atom_trace = True
pr.settings.memory_profile = False
pr.settings.canonical = True
pr.settings.inconsistency_check = False
pr.settings.static_graph_facts = False
pr.settings.output_to_file = False
pr.settings.store_interpretation_changes = True
pr.settings.save_graph_attributes_to_trace = True
# Load all the files into pyreason
pr.load_graphml(graph_path)
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))

# Run the program for two timesteps to see the diffusion take place
interpretation = pr.reason(timesteps=1)
# pr.save_rule_trace(interpretation)

# Display the changes in the interpretation for each timestep
dataframes = pr.filter_and_sort_edges(interpretation, ['isConnectedTo'])
for t, df in enumerate(dataframes):
print(f'TIMESTEP - {t}')
print(df)
print()
assert len(dataframes) == 2, 'Pyreason should run exactly 2 fixpoint operations'
assert len(dataframes[1]) == 1, 'At t=1 there should be only 1 new isConnectedTo atom'
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'


def test_anyBurl_rule_2():
graph_path = './tests/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
# Modify pyreason settings to make verbose and to save the rule trace to a file
pr.settings.verbose = True
pr.settings.atom_trace = True
pr.settings.memory_profile = False
pr.settings.canonical = True
pr.settings.inconsistency_check = False
pr.settings.static_graph_facts = False
pr.settings.output_to_file = False
pr.settings.store_interpretation_changes = True
pr.settings.save_graph_attributes_to_trace = True
# Load all the files into pyreason
pr.load_graphml(graph_path)

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))

# Run the program for two timesteps to see the diffusion take place
interpretation = pr.reason(timesteps=1)
# pr.save_rule_trace(interpretation)

# Display the changes in the interpretation for each timestep
dataframes = pr.filter_and_sort_edges(interpretation, ['isConnectedTo'])
for t, df in enumerate(dataframes):
print(f'TIMESTEP - {t}')
print(df)
print()
assert len(dataframes) == 2, 'Pyreason should run exactly 2 fixpoint operations'
assert len(dataframes[1]) == 1, 'At t=1 there should be only 1 new isConnectedTo atom'
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'


def test_anyBurl_rule_3():
graph_path = './tests/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
# Modify pyreason settings to make verbose and to save the rule trace to a file
pr.settings.verbose = True
pr.settings.atom_trace = True
pr.settings.memory_profile = False
pr.settings.canonical = True
pr.settings.inconsistency_check = False
pr.settings.static_graph_facts = False
pr.settings.output_to_file = False
pr.settings.store_interpretation_changes = True
pr.settings.save_graph_attributes_to_trace = True
# Load all the files into pyreason
pr.load_graphml(graph_path)

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))

# Run the program for two timesteps to see the diffusion take place
interpretation = pr.reason(timesteps=1)
# pr.save_rule_trace(interpretation)

# Display the changes in the interpretation for each timestep
dataframes = pr.filter_and_sort_edges(interpretation, ['isConnectedTo'])
for t, df in enumerate(dataframes):
print(f'TIMESTEP - {t}')
print(df)
print()
assert len(dataframes) == 2, 'Pyreason should run exactly 1 fixpoint operations'
assert len(dataframes[1]) == 1, 'At t=1 there should be only 1 new isConnectedTo atom'
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'


def test_anyBurl_rule_4():
graph_path = './tests/knowledge_graph_test_subset.graphml'
pr.reset()
pr.reset_rules()
# Modify pyreason settings to make verbose and to save the rule trace to a file
pr.settings.verbose = True
pr.settings.atom_trace = True
pr.settings.memory_profile = False
pr.settings.canonical = True
pr.settings.inconsistency_check = False
pr.settings.static_graph_facts = False
pr.settings.output_to_file = False
pr.settings.store_interpretation_changes = True
pr.settings.save_graph_attributes_to_trace = True
# Load all the files into pyreason
pr.load_graphml(graph_path)

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))

# Run the program for two timesteps to see the diffusion take place
interpretation = pr.reason(timesteps=1)
# pr.save_rule_trace(interpretation)

# Display the changes in the interpretation for each timestep
dataframes = pr.filter_and_sort_edges(interpretation, ['isConnectedTo'])
for t, df in enumerate(dataframes):
print(f'TIMESTEP - {t}')
print(df)
print()
assert len(dataframes) == 2, 'Pyreason should run exactly 1 fixpoint operations'
assert len(dataframes[1]) == 1, 'At t=1 there should be only 1 new isConnectedTo atom'
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'