Skip to content

Commit f8b92c2

Browse files
committed
Test partial edge grounding
1 parent d9aadfb commit f8b92c2

3 files changed

Lines changed: 18 additions & 0 deletions

File tree

pyreason/scripts/interpretation/interpretation.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,12 @@ def _ground_rule(rule, interpretations_node, interpretations_edge, predicate_map
864864
if allow_ground_rules and (clause_var_1, clause_var_2) in edges_set:
865865
grounding = numba.typed.List([(clause_var_1, clause_var_2)])
866866
else:
867+
# Pre-populate groundings for any variable that matches an existing node (partial grounding)
868+
if allow_ground_rules:
869+
if clause_var_1 in nodes_set and clause_var_1 not in groundings:
870+
groundings[clause_var_1] = numba.typed.List([clause_var_1])
871+
if clause_var_2 in nodes_set and clause_var_2 not in groundings:
872+
groundings[clause_var_2] = numba.typed.List([clause_var_2])
867873
grounding = get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groundings_edges, neighbors, reverse_neighbors, predicate_map_edge, clause_label, edges)
868874

869875
# Narrow subset based on predicate (save the edges that are qualified to use for finding future groundings faster)

pyreason/scripts/interpretation/interpretation_fp.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,12 @@ def _ground_rule(rule, interpretations_node, interpretations_edge, predicate_map
986986
if allow_ground_rules and (clause_var_1, clause_var_2) in edges_set:
987987
grounding = numba.typed.List([(clause_var_1, clause_var_2)])
988988
else:
989+
# Pre-populate groundings for any variable that matches an existing node (partial grounding)
990+
if allow_ground_rules:
991+
if clause_var_1 in nodes_set and clause_var_1 not in groundings:
992+
groundings[clause_var_1] = numba.typed.List([clause_var_1])
993+
if clause_var_2 in nodes_set and clause_var_2 not in groundings:
994+
groundings[clause_var_2] = numba.typed.List([clause_var_2])
989995
grounding = get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groundings_edges, neighbors, reverse_neighbors, predicate_map_edge, clause_label, edges)
990996

991997
# Narrow subset based on predicate (save the edges that are qualified to use for finding future groundings faster)

pyreason/scripts/interpretation/interpretation_parallel.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,12 @@ def _ground_rule(rule, interpretations_node, interpretations_edge, predicate_map
864864
if allow_ground_rules and (clause_var_1, clause_var_2) in edges_set:
865865
grounding = numba.typed.List([(clause_var_1, clause_var_2)])
866866
else:
867+
# Pre-populate groundings for any variable that matches an existing node (partial grounding)
868+
if allow_ground_rules:
869+
if clause_var_1 in nodes_set and clause_var_1 not in groundings:
870+
groundings[clause_var_1] = numba.typed.List([clause_var_1])
871+
if clause_var_2 in nodes_set and clause_var_2 not in groundings:
872+
groundings[clause_var_2] = numba.typed.List([clause_var_2])
867873
grounding = get_rule_edge_clause_grounding(clause_var_1, clause_var_2, groundings, groundings_edges, neighbors, reverse_neighbors, predicate_map_edge, clause_label, edges)
868874

869875
# Narrow subset based on predicate (save the edges that are qualified to use for finding future groundings faster)

0 commit comments

Comments
 (0)