Skip to content

Commit

Permalink
modify
Browse files Browse the repository at this point in the history
  • Loading branch information
xubowen committed Sep 23, 2022
1 parent 4f95b13 commit e347862
Show file tree
Hide file tree
Showing 109 changed files with 46,391 additions and 376 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ __pycache__/
Tests/*.png
*.pkl
!pynars/utils/SparseLUT/*.pyd
temp/

# C extensions
*.so

Expand Down
4 changes: 2 additions & 2 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"name": "Python: Pong",
"type": "python",
"request": "launch",
"module": "RL.Pong.main"
"module": "pynars.RL.Pong.main"
},
{
"name": "Python: test_nal9",
Expand Down Expand Up @@ -197,7 +197,7 @@
"module": "pynars.Console",
"console": "integratedTerminal",
"args": [
"Tests/examples/single_step/nal7/nal7.revrev.nal"
// "Tests/examples/single_step/nal7/nal7.revrev.nal"
// "Tests/examples/single_step/nal5.query.nal"
]
},
Expand Down
8 changes: 8 additions & 0 deletions Tests/examples/multi_steps/nal1.multistep.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<a --> b>. %1.00;0.90%
<b --> c>. %1.00;0.90%
<c --> d>. %1.00;0.90%
<a --> d>?

11000

''outputMustContain('<a --> d>. %1.00;0.73%')
15 changes: 15 additions & 0 deletions Tests/examples/multi_steps/nal3.subtermMapping1.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
' from https://code.google.com/archive/p/open-nars/issues/47
<{t1,{t2,{t3}}} --> [p1,[p2,[p3]]]>. %1.00;0.90%
<c <-> t3>. %1.00;0.90%

<{t1,{t2,{c}}} --> [p1,[p2,[p3]]]>?
500

' |-

' answer provided by OpenNARS 3.0.2 and 3.0.3
''outputMustContain('<{t1,{t2,{c}}} --> [[[p3],p2],p1]>. %1.00;0.59%')

' right answer should be
'''outputMustContain('<{t1,{t2,{c}}} --> [[[p3],p2],p1]>. %1.00;0.81%')
' because it can use conj
10 changes: 10 additions & 0 deletions Tests/examples/multi_steps/nal4.everyday_reasoning.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//tom is a cat
<{tom} --> cat>.
//tom likes the sky
<(*,{tom},{sky}) --> likes>.
//the sky is blue
<{sky} --> [blue]>.
//cats like blue?
<(*,cat,[blue]) --> likes>?
10000
''outputMustContain('<(*,cat,[blue]) --> likes>. %1.00;0.37%')
12 changes: 12 additions & 0 deletions Tests/examples/multi_steps/nal4.recursion.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'*silence=80

<0 --> num>. %1.00;0.90%
<<$1 --> num> ==> <(*,$1) --> num>>. %1.00;0.90%
<(*,(*,(*,(*,(*,0))))) --> num>?

50000

''outputMustContain('')
//''outputMustContain('<(*,(*,(*,(*,(*,0))))) --> num>.')
''//outputMustContain('<(*,(*,(*,(*,(*,0))))) --> num>. %1.00')
''//outputMustContain('<(*,(*,(*,(*,(*,0))))) --> num>. %1.00;0.53%')
10 changes: 10 additions & 0 deletions Tests/examples/multi_steps/nal4.recursion.small.2.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<<$1 --> number> ==> <(/,successor,$1,_) --> number>>.
<0 --> number>.
<(/,successor,(/,successor,0,_),_) --> number>?

20000

''outputMustContain('<(/,successor,0,_) --> number>.')
//''outputMustContain('<(/,successor,(/,successor,0,_),_) --> number>.')
//''outputMustContain('<(/,successor,(/,successor,0,_),_) --> number>. %1.00;0.73%')

9 changes: 9 additions & 0 deletions Tests/examples/multi_steps/nal4.recursion.small.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<0 --> num>. %1.00;0.90%

<<$1 --> num> ==> <(*,$1) --> num>>. %1.00;0.90%

<(*,(*,(*,0))) --> num>?

50000

''outputMustContain('<(*,(*,(*,0))) --> num>. %1.00;0.66%')
28 changes: 28 additions & 0 deletions Tests/examples/multi_steps/nal6.mln1.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
' MLN example by patrick

' Facts:
<(*,{Anna},{Bob}) --> Friends>. %1.00;0.99%
<(*,{Anna},{Edward}) --> Friends>. %1.00;0.99%
<(*,{Anna},{Frank}) --> Friends>. %1.00;0.99%
<(*,{Edward},{Frank}) --> Friends>. %1.00;0.99%
<(*,{Gary},{Helen}) --> Friends>. %1.00;0.99%
(--,<(*,{Gary},{Frank}) --> Friends>). %1.00;0.99%
<{Anna} --> [Drinks]>. %1.00;0.99%
<{Edward} --> [Smokes]>. %1.00;0.99%

' Rule0:
' p=0.8, Drinks(x) => Cancer(x)
<<$1 --> [Drinks]> ==> <$1 --> [Cancer]>>. %0.8;0.9%

' Rule1:
' p=0.8, Smokes(x) => Cancer(x)
<<$1 --> [Smokes]> ==> <$1 --> [Cancer]>>. %0.8;0.9%

' Rule2:
' p=0.6 Friends(x, y) => (Smokes(x) <=> Smokes(y))
<<(*,$1,$2) --> Friends> ==> (||, (&&,<$1 --> [Smokes]>,<$2 --> [Smokes]>), (&&,(--,<$1 --> [Smokes]>),(--,<$2 --> [Smokes]>)))>. %0.6;0.9%

<?who --> [Cancer]>?
1000

''outputMustContain('<{Edward} --> [Cancer]>. %0.80;0.71%')
8 changes: 8 additions & 0 deletions Tests/examples/multi_steps/nal7.implSeqABCsimple.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
' unittset seq
<a --> A>. :|: %1.00;0.90%
8
<b --> B>. :|: %1.00;0.90%
8
<c --> C>. :|: %1.00;0.90%
100
''outputMustContain('<(&/,<a --> A>,+8,<b --> B>,+8) =/> <c --> C>>. :!16: %1.00;0.42%')
7 changes: 7 additions & 0 deletions Tests/examples/multi_steps/nal7.predEquiv.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<a --> A>. :|: %1.00;0.90%
8
<b --> B>. :|: %1.00;0.90%
8
<c --> C>. :|: %1.00;0.90%
100
''outputMustContain('<(&/,<a --> A>,+8,<b --> B>,+8) </> <c --> C>>. :!16: %1.00;0.42%')
7 changes: 7 additions & 0 deletions Tests/examples/multi_steps/nal7.seq3.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<a --> A>. :|: %1.00;0.90%
8
<b --> B>. :|: %1.00;0.90%
8
<c --> C>. :|: %1.00;0.90%
100
''outputMustContain('(&/,<a --> A>,+8,<b --> B>,+8,<c --> C>). :!16: %1.00;0.73%')
6 changes: 6 additions & 0 deletions Tests/examples/multi_steps/nars_memorize_precondition.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<(&/,<a --> A>,+10,(^pick,{SELF},a),+10) =/> <a --> B>>.
100
<a --> A>. :|:
10
<a --> B>!
''outputMustContain('(^pick,{SELF},a). :!110: %1.00;0.90%')
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<(&/,(&|,<a --> #A>,<a2 --> #A>),+10,(^pick,{SELF},a),+10) =/> <a --> B>>.
100
<a --> A>. :|:
<a2 --> A>. :|:
10
<a --> B>!
''outputMustContain('(^pick,{SELF},a). :!110: %1.00;0.90%')
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<(&/,<a --> #A>,+10,<a2 --> #A>,+10,(^pick,{SELF},a),+10) =/> <a --> B>>.
100
<a --> A>. :|:
10
<a2 --> A>. :|:
10
<a --> B>!
''outputMustContain('(^pick,{SELF},a). :!120: %1.00;0.90%')
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<(&/,<a --> A>,+10,<x --> y>,+10,(^pick,{SELF},a),+10) =/> <a --> B>>.
100
<a --> A>. :|:
10
<x --> y>. :|:
10
<a --> B>!
''outputMustContain('(^pick,{SELF},a). :!120: %1.00;0.90%')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<(&/,<#1 --> A>,+10,(^pick,{SELF},#1),+10) =/> <a --> B>>.
100
<a --> A>. :|:
10
<a --> B>!
''outputMustContain('(^pick,{SELF},a). :!110: %1.00;0.90%')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<(&/,<a --> A>,+10,(^pick,{SELF},a),+10) =/> <#1 --> B>>.
100
<a --> A>. :|:
10
<a --> B>!
''outputMustContain('(^pick,{SELF},a). :!110: %1.00;0.90%')
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<(&/,<$1 --> A>,+10,(^pick,{SELF},$1),+10) =/> <$1 --> B>>.
100
<a --> A>. :|:
10
<a --> B>!
''outputMustContain('(^pick,{SELF},a). :!110: %1.00;0.90%')
20 changes: 20 additions & 0 deletions Tests/examples/multi_steps/nars_multistep_1.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'****** Mixed inference
<swan --> bird>.
<swan --> swimmer>.
50
<bird --> swimmer>?
80
<gull --> bird>.
<gull --> swimmer>.
80
<bird --> [feathered]>.
<robin --> [feathered]>.
80
<robin --> bird>?
100
<robin --> swimmer>?
7000
''outputMustContain('<bird --> swimmer>. %1.00;0.45%')
//''outputMustContain('<bird --> swimmer>. %1.00;0.62%')
''outputMustContain('<robin --> bird>. %1.00;0.45%')
''outputMustContain('<robin --> swimmer>. %1.00;0.28%')
13 changes: 13 additions & 0 deletions Tests/examples/multi_steps/nars_multistep_2.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// *** Semi-compositionality
<(&,light,[red]) --> traffic_signal>?
5
<[red] --> traffic_signal>. %0.1%
<light --> traffic_signal>. %0.1%
500
''outputMustContain('<(&,[red],light) --> traffic_signal>. %0.19;0.81%')
1000
<{light_1} --> (&,light,[red])>.
<{light_1} --> traffic_signal>.
200000
''outputMustContain('<(&,[red],light) --> traffic_signal>. %0.30;0.83%')

20 changes: 20 additions & 0 deletions Tests/examples/multi_steps/nars_multistep_3.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// *** Fuzzy concepts
<{John} --> (/,taller_than,{Tom},_)>.
<{John} --> boy>.
5
<{Tom} --> (/,taller_than,_,boy)>?
''outputMustContain('<boy --> (/,taller_than,{Tom},_)>. %1.00;0.45%')
6
<{David} --> boy>.
(--,<{David} --> (/,taller_than,{Tom},_)>).

1000

//''outputMustContain('<boy --> (/,taller_than,{Tom},_)>. %0.00;0.40%')

//''outputMustContain('<{Tom} --> (/,taller_than,_,boy)>. %1.00;0.45%')
1
<{Karl} --> (/,taller_than,{Tom},_)>.
<{Karl} --> boy>.
500000
''outputMustContain('<boy --> (/,taller_than,{Tom},_)>. %0.67;0.71%')
14 changes: 14 additions & 0 deletions Tests/examples/multi_steps/nars_seqABC.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<a --> A>. :|: %1.00;0.90%
8
<b --> B>. :|: %1.00;0.90%
8
<c --> C>. :|: %1.00;0.90%
8
<a --> A>. :|: %1.00;0.90%
100
<b --> B>. :|: %1.00;0.90%
20000
<?1 =/> <c --> C>>?
''outputMustContain('<(&/,<a --> A>,+8,<b --> B>,+8) =/> <c --> C>>. :!16: %1.00;0.42%')
''outputMustContain('<(&/,<b --> B>,+8) =/> <c --> C>>. %0.50;0.62%')
''outputMustContain('<(&/,<a --> A>,+16) =/> <c --> C>>. %0.50;0.62%')
8 changes: 8 additions & 0 deletions Tests/examples/multi_steps/nars_transitivity.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<(*,a,b) --> like>. %1.00;0.90%
<(*,b,c) --> like>. %1.00;0.90%
<(*,a,c) --> like>. %1.00;0.90%
<<(*,b,$1) --> like> ==> <(*,a,$1) --> like>>?
//<(&&,<(*,#1,$2) --> like>,<(*,$3,#1) --> like>) ==> <(*,$3,$2) --> like>>?
210000
''outputMustContain('<<(*,b,$1) --> like> ==> <(*,a,$1) --> like>>. %1.00;0.45%')
''outputMustContain('<(&&,<(*,#1,$2) --> like>,<(*,$3,#1) --> like>) ==> <(*,$3,$2) --> like>>. %1.00;0.26%')
33 changes: 33 additions & 0 deletions Tests/examples/multi_steps/stresstest_bird1.nal
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
' stress test
' from https://code.google.com/archive/p/open-nars/issues/1

<{b1} --> bird>.
<{b1} --> fly>.
<{b2} --> bird>.
<{b2} --> fly>.
<{b3} --> bird>.
<{b3} --> fly>.
<{b4} --> bird>.
<{b4} --> fly>.
<{b5} --> bird>.
<{b5} --> fly>.
<{b6} --> bird>.
<{b6} --> fly>.
<{b7} --> bird>.
<{b7} --> fly>.
<{b8} --> bird>.
<{b8} --> fly>.
<{b9} --> bird>.
<{b9} --> fly>.
<{bA} --> bird>.
<{bA} --> fly>?

' expected answers on a good run
' Answer <{bA} --> fly>. %1.00;0.27% {2176
' Answer <{bA} --> fly>. %1.00;0.40% {6305
' Answer <{bA} --> fly>. %1.00;0.44% {32125
' Answer <{bA} --> fly>. %1.00;0.78% {44080

' give enough time
60000
''outputMustContain('<{bA} --> fly>. %1.00;0.77%')
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal3/nal3.11.nal
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'Is being bird what differ swimmer from swan?
<(~,swimmer, swan) --> bird>?

60
100

'What differs swimmer from swan is not being bird.
''outputMustContain('<(~,swimmer,swan) --> bird>. %0.10;0.73%')
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal3/nal3.12.nal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'Robin is a type of swimming bird.
<robin --> (&,bird,swimmer)>. %0.90%

1
2

'Robin is a type of bird.
''outputMustContain('<robin --> bird>. %0.90;0.73%')
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal3/nal3.8.nal
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'Is a swan a type of bird or swimmer?
<swan --> (|,bird,swimmer)>?

50
100

'A swan is probably a type of bird or swimmer.
''outputMustContain('<swan --> (|,bird,swimmer)>. %0.90;0.73%')
Expand Down
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal3/nal3.9.nal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<(&,swan,swimmer) --> bird>?

'Is swimming swan a type of bird?
50
100

'Swimming swan is a type of bird.
''outputMustContain('<(&,swan,swimmer) --> bird>. %0.90;0.73%')
Expand Down
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal4/nal4.0.nal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'An acid and a base can have a reaction.
<(*,acid,base) --> reaction>.

6
3

'Acid can react with base.
''outputMustContain('<acid --> (/,reaction,_,base)>. %1.00;0.90%')
Expand Down
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal4/nal4.3.nal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'Neutralization is a relation between an acid and a base.
<neutralization --> (*,acid,base)>.

6
3

'Something that can neutralize a base is an acid.
''outputMustContain('<(\,neutralization,_,base) --> acid>. %1.00;0.90%')
Expand Down
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal4/nal4.4.nal
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
'Something that can neutralize a base is an acid.
<(\,neutralization,_,base) --> acid>.

4
5

'Neutralization is a relation between an acid and a base.
''outputMustContain('<neutralization --> (*,acid,base)>. %1.00;0.90%')
Expand Down
2 changes: 1 addition & 1 deletion Tests/examples/single_step/nal5/nal5.11.nal
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'Robin is a type of bird if and only if robin can fly.
<<robin --> bird> <=> <robin --> [flying]>>. %0.9%

19
5

'Robin is a type of animal if and only if robin can fly.
''outputMustContain('<<robin --> [flying]> <=> <robin --> animal>>. %0.90;0.81%')
Expand Down
Loading

0 comments on commit e347862

Please sign in to comment.