Skip to content

Commit

Permalink
Merge pull request #94 from bowen-xu/KanrenReasoner
Browse files Browse the repository at this point in the history
Kanren reasoner
  • Loading branch information
bowen-xu authored May 15, 2024
2 parents 3bd6316 + ee133fe commit 6ee8035
Show file tree
Hide file tree
Showing 36 changed files with 1,836 additions and 247 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-app-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.7.x
- name: Set up Python 3.9.x
uses: actions/setup-python@v5
with:
python-version: "3.7"
python-version: "3.9"

- name: Install dependencies
run: |
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-app-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.7.x
- name: Set up Python 3.9.x
uses: actions/setup-python@v5
with:
python-version: "3.7"
python-version: "3.9"

- name: Install dependencies
run: |
Expand Down
6 changes: 6 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: KanrenEngine",
"type": "debugpy",
"request": "launch",
"module": "pynars.NARS.InferenceEngine.KanrenEngine"
},
{
"name": "Python: pynars.GUI",
"type": "python",
Expand Down
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
"test_*.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
"python.testing.unittestEnabled": true,
"python.REPL.enableREPLSmartSend": false
}
19 changes: 9 additions & 10 deletions Tests/test_NAL/test_BUG_NAL4.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,23 @@ def test_bug_0(self):
<(/, ?0, animal, _) --> (/, ?0, bird, _)>.
'''

rules, task, belief, concept, task_link, term_link, result1, result2 = rule_map_two_premises(
tasks_derived = process_two_premises(
'<bird --> animal>. %1.00;0.90%',
'(/, tree, bird, _).',
'bird.', is_belief_term=True)
tasks_derived = [rule(task, belief.term, task_link, term_link) for rule in rules]
20
)
self.assertTrue(
output_contains(tasks_derived, '<(/, tree, animal, _) --> (/, tree, bird, _)>. %1.00;0.81%')
)

rules, task, belief, concept, task_link, term_link, result1, result2 = rule_map_two_premises(
tasks_derived = process_two_premises(
'<bird --> animal>. %1.00;0.90%',
'(/, ?0, bird, _).',
'bird.', is_belief_term=True)
if rules is not None:
tasks_derived = [rule(task, belief.term, task_link, term_link) for rule in rules]
self.assertFalse(
output_contains(tasks_derived, '<(/, ?0, animal, _) --> (/, ?0, bird, _)>. %1.00;0.81%')
)
20
)
self.assertFalse(
output_contains(tasks_derived, '<(/, ?0, animal, _) --> (/, ?0, bird, _)>. %1.00;0.81%')
)

pass

Expand Down
8 changes: 4 additions & 4 deletions Tests/test_NAL/test_NAL1.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_revision(self):
tasks_derived = process_two_premises(
'<bird --> swimmer>. %1.00;0.90%',
'<bird --> swimmer>. %0.10;0.60%',
2
10
)
self.assertTrue(
output_contains(tasks_derived, '<bird --> swimmer>. %0.87;0.91%')
Expand Down Expand Up @@ -96,7 +96,7 @@ def test_abduction(self):
tasks_derived = process_two_premises(
'<sport --> competition>. %1.00;0.90%',
'<chess --> competition>. %0.90;0.90%',
5
10
)
self.assertTrue(
output_contains(tasks_derived, '<sport --> chess>. %1.00;0.42%')
Expand Down Expand Up @@ -129,7 +129,7 @@ def test_induction(self):
tasks_derived = process_two_premises(
'<swan --> swimmer>. %0.90;0.90%',
'<swan --> bird>. %1.00;0.90%',
5
20
)
self.assertTrue(
output_contains(tasks_derived, '<bird --> swimmer>. %0.90;0.45%')
Expand Down Expand Up @@ -159,7 +159,7 @@ def test_exemplification(self):
tasks_derived = process_two_premises(
'<robin --> bird>. %1.00;0.90%',
'<bird --> animal>. %1.00;0.90%',
5
20
)
self.assertTrue(
output_contains(tasks_derived, '<animal --> robin>. %1.00;0.45%')
Expand Down
32 changes: 16 additions & 16 deletions Tests/test_NAL/test_NAL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_revision(self):
tasks_derived = process_two_premises(
'<robin <-> swan>. %1.00;0.90%',
'<robin <-> swan>. %0.10;0.60%',
2
10
)
self.assertTrue(
output_contains(tasks_derived, '<robin <-> swan>. %0.87;0.91%')
Expand Down Expand Up @@ -112,7 +112,7 @@ def test_comparison(self):
tasks_derived = process_two_premises(
'<sport --> competition>. %1.00;0.90%',
'<chess --> competition>. %0.90;0.90% ',
5
20
)
self.assertTrue(
output_contains(tasks_derived, '<chess <-> sport>. %0.90;0.45%')
Expand All @@ -139,7 +139,7 @@ def test_analogy_0(self):
tasks_derived = process_two_premises(
'<swan --> swimmer>. %1.00;0.90%',
'<gull <-> swan>. %1.00;0.90%',
5
20
)
self.assertTrue(
output_contains(tasks_derived, '<gull --> swimmer>. %1.00;0.81%')
Expand All @@ -165,7 +165,7 @@ def test_analogy_1(self):
tasks_derived = process_two_premises(
'<gull --> swimmer>. %1.00;0.90%',
'<gull <-> swan>. %1.00;0.90%',
5
10
)
self.assertTrue(
output_contains(tasks_derived, '<swan --> swimmer>. %1.00;0.81%')
Expand All @@ -191,7 +191,7 @@ def test_resemblance(self):
tasks_derived = process_two_premises(
'<robin <-> swan>. %1.00;0.90%',
'<gull <-> swan>. %1.00;0.90%',
5
20
)
self.assertTrue(
output_contains(tasks_derived, '<gull <-> robin>. %1.00;0.81%')
Expand All @@ -218,7 +218,7 @@ def test_conversions_between_inheritance_and_similarity(self):
tasks_derived = process_two_premises(
'<swan --> bird>. %1.00;0.90%',
'<bird --> swan>. %0.10;0.90%',
10
20
)
self.assertTrue(
output_contains(tasks_derived, '<bird <-> swan>. %0.10;0.81%')
Expand Down Expand Up @@ -248,10 +248,10 @@ def test_structure_transformation_0(self):
10
)
self.assertTrue(
output_contains(tasks_derived, '<[bright] <-> [smart]>. %0.90;0.90%')
output_contains(tasks_derived, '<[bright] <-> [smart]>. %0.90;0.81%')
)
self.assertTrue(
output_contains(tasks_derived, '<[smart] --> [bright]>. %0.90;0.66%')
output_contains(tasks_derived, '<[smart] --> [bright]>. %0.90;0.73%')
)
pass

Expand All @@ -274,7 +274,7 @@ def test_structure_transformation_1(self):
tasks_derived = process_two_premises(
'<Birdie <-> Tweety>. %0.90;0.90%',
'<{Birdie} <-> {Tweety}>?',
10
200
)
self.assertTrue(
output_contains(tasks_derived, '<{Birdie} <-> {Tweety}>. %0.90;0.73%')
Expand All @@ -300,10 +300,10 @@ def test_conversions_between_inheritance_and_similarity_0(self):
tasks_derived = process_two_premises(
'<swan --> bird>. %1.00;0.90%',
'<bird <-> swan>. %0.10;0.90%',
10
20
)
self.assertTrue(
output_contains(tasks_derived, '<bird --> swan>. %0.10;0.73%')
output_contains(tasks_derived, '<bird --> swan>. %1.00;0.47%')
)
pass

Expand Down Expand Up @@ -355,7 +355,7 @@ def test_conversions_between_inheritance_and_similarity_2(self):
tasks_derived = process_two_premises(
'<bird <-> swan>. %0.90;0.90%',
'<swan --> bird>?',
10
40
)
self.assertTrue(
output_contains(tasks_derived, '<swan --> bird>. %0.90;0.81%')
Expand Down Expand Up @@ -444,7 +444,7 @@ def test_set_definition_0(self):
tasks_derived = process_two_premises(
'<{Tweety} --> {Birdie}>. %1.00;0.90%',
None,
3
200
)
self.assertTrue(
output_contains(tasks_derived, '<{Birdie} <-> {Tweety}>. %1.00;0.90%')
Expand All @@ -467,7 +467,7 @@ def test_set_definition_1(self):
tasks_derived = process_two_premises(
'<[smart] --> [bright]>. %1.00;0.90%',
None,
1
200
)
self.assertTrue(
output_contains(tasks_derived, '<[bright] <-> [smart]>. %1.00;0.90%')
Expand All @@ -493,7 +493,7 @@ def test_set_definition_2(self):
tasks_derived = process_two_premises(
'<{Birdie} <-> {Tweety}>. %1.00;0.90%',
None,
1
200
)
self.assertTrue(
output_contains(tasks_derived, '<Birdie <-> Tweety>. %1.00;0.90%')
Expand Down Expand Up @@ -522,7 +522,7 @@ def test_set_definition_3(self):
tasks_derived = process_two_premises(
'<[bright] <-> [smart]>. %1.00;0.90%',
None,
1
200
)
self.assertTrue(
output_contains(tasks_derived, '<bright <-> smart>. %1.00;0.90%')
Expand Down
6 changes: 3 additions & 3 deletions Tests/test_NAL/test_NAL3.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ def test_compound_decomposition_intensional_intersection(self):
tasks_derived = process_two_premises(
'<robin --> (|,bird,swimmer)>. %1.00;0.90%',
'<robin --> swimmer>. %0.00;0.90%',
32
20
)
self.assertTrue(
output_contains(tasks_derived, '<robin --> bird>. %1.00;0.81%')
Expand All @@ -162,7 +162,7 @@ def test_compound_decomposition_intensional_intersection(self):
tasks_derived = process_two_premises(
'<robin --> swimmer>. %0.00;0.90%',
'<robin --> (|,bird,swimmer)>. %1.00;0.90%',
32
20
)
self.assertTrue(
output_contains(tasks_derived, '<robin --> bird>. %1.00;0.81%')
Expand Down Expand Up @@ -203,7 +203,7 @@ def test_compound_decomposition_extensional_difference(self):
)
self.assertTrue(
output_contains(tasks_derived, '<robin --> mammal>. %0.00;0.81%')
)
)

pass

Expand Down
Loading

0 comments on commit 6ee8035

Please sign in to comment.