Skip to content

Commit

Permalink
fix issue with incorrect rules added to strong_rules; keep subset for…
Browse files Browse the repository at this point in the history
… each theorem to speed up structural inference
  • Loading branch information
maxeeem committed Mar 29, 2024
1 parent a8b267a commit 8e68b95
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
9 changes: 5 additions & 4 deletions pynars/NARS/InferenceEngine/KanrenEngine/KanrenEngine.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ def __init__(self):
higher_order.append(rule)

# save subset for backward inference
self.rules_backward = [convert(r) for r in nal1_rules + nal2_rules
self.rules_backward = [convert(r, True) for r in nal1_rules + nal2_rules
+ higher_order
# + conditional_syllogistic
]

self.rules_conditional_syllogistic = [convert(r) for r in conditional_syllogistic]
self.rules_conditional_syllogistic = [convert(r, True) for r in conditional_syllogistic]

for rule in nal3_rules:
# replace --> with ==> and <-> with <=> in NAL3 (except difference)
Expand Down Expand Up @@ -251,8 +251,9 @@ def inference_structural(self, t: Sentence, theorems = None):
theorems = self.theorems

l1 = logic(t.term, structural=True)
for (l2, sub_terms) in theorems:
for rule in rules_strong:
for (l2, sub_terms, matching_rules) in theorems:
for i in matching_rules:
rule = rules_strong[i]
res = self.apply(rule, l2, l1)
if res is not None:
# ensure no theorem terms in conclusion
Expand Down
8 changes: 7 additions & 1 deletion pynars/NARS/InferenceEngine/KanrenEngine/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ def convert_theorems(theorem):
# print(l)
# print(term(l))
# print("\n\n")
matching_rules = []
for i, rule in enumerate(rules_strong):
(p1, p2, c) = rule[0]
if run(1, c, eq(p1, l)):
matching_rules.append(i)

sub_terms = frozenset(filter(lambda x: x != place_holder, t.sub_terms))
return (l, sub_terms)
return (l, sub_terms, tuple(matching_rules))


#################
Expand Down

0 comments on commit 8e68b95

Please sign in to comment.