forked from NatLanGroup/NatLan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnatlan.py
43 lines (34 loc) · 1.76 KB
/
natlan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import sys, gl, conc, wrd, testing, reason
def process_testinput (tf): # input is the Testinput object
for ri in range(len(tf.mentalese)): # take mentalese items (rows in test input file)
counter=0; tfment=[]
tfment.append(tf.mentalese[ri])
starti=gl.WM.ci # start position in WM
while (len(tfment[0])>3 and counter<20): # counter protects against endless loop
gl.WM.read_concept(tfment) # store concepts in WM
counter=counter+1
gl.WM.move_rule(tf,ri,starti) # if this is a rule, move to KB
endi = gl.WM.ci # end position in WM
if (tf.question[ri]==1): # if yes, then on endi we assume a question
tf.systemanswer[ri][:] = gl.WM.answer_question(starti,endi)[:] # answer question and record concept indices
gl.test.write_result(ri) # write reult file
ri=ri+1
gl.args = gl.Arguments() # initialize
gl.WM = conc.Kbase("WM") # WORKING MEMORY
gl.KB = conc.Kbase("KB") # KNOWLEDGE BASE
gl.WL = wrd.Wlist("WL") # WORD LIST
gl.log = gl.Logging()
test1 = conc.Concept()
test1.add_parents([-1, 17])
result = gl.WM.search_inlist(test1)
gl.unittest=testing.Temptest() # initialize temporary tests
thisrule=reason.Rule(2)
if gl.args.argnum == 2:
gl.test = testing.Testinput(sys.argv[1])
gl.test.readtest()
process_testinput (gl.test)
gl.test.testf.close()
gl.test.resultf.close()
# gl.KB.walk_db(11) # walk through parents of a concept, print them
#gl.unittest.utest_read_concept() # run read_concept unit test
gl.log.logf.close()