-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
115 lines (81 loc) · 3.12 KB
/
main.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
__author__ = 'jimrutt'
from opencog.atomspace import Atom, AtomSpace, TruthValue, types, get_type_name
from opencog.scheme_wrapper import load_scm, scheme_eval, scheme_eval_h, __init__
from opencog.utilities import initialize_opencog, finalize_opencog
import time
import random
import project_utils as pu
import zmq
import sys
import collections
import os
try:
ipaddress = str(sys.argv[1])
except:
print "ipaddress missing or bad as parameter"
exit()
atomspace = AtomSpace()
__init__(atomspace)
debugflag = False
data = ["/usr/local/share/opencog/scm/core_types.scm",
"/usr/local/share/opencog/scm/utilities.scm"]
for item in data:
load_scm(atomspace, item)
# Add to scheme's %load-path directory to serach for opencog guile modules
scheme_eval(atomspace, "(add-to-load-path \"/usr/local/share/opencog/scm\")")
# Import opencog modules required for using `cog-bind` in scheme_eval
scheme_eval(atomspace, "(use-modules (opencog))")
scheme_eval(atomspace, "(use-modules (opencog query))")
initialize_opencog(atomspace,str(os.getcwd()) + "/AIDeerProto001.conf")
TRUTH_VALUE = TruthValue(1,1)
pu.ontology_setup(atomspace,TRUTH_VALUE)
if (debugflag):
pu.printatoms(atomspace)
context , rcvsocket = pu.setupzmq(ipaddress)
sendsocket = pu.setupzmqsend(context,ipaddress)
pu.setzmqsubprofile("444",rcvsocket) # my channel number
print "starting to receive"
kount = 0
currentEpisode = "Episode_1"
framekount = 0
cogbindkount = 0
while True:
# Wait for next request from client
kount = kount + 1
try:
message = rcvsocket.recv()
except:
print "ooops no recv"
exit()
# print message
MsgFields = pu.parsemessage(message)
if (MsgFields.msgtype == "OBJ"):
pu.processOBJmsg(atomspace,MsgFields,MyLocation, frameNode,TRUTH_VALUE)
elif (MsgFields.msgtype == "STARTFRAME"):
framename = "Frame_" + str(MsgFields.frame)
currentEpisode = currentEpisode
frameNode = pu.createFrame(atomspace,currentEpisode,framename,TRUTH_VALUE)
framekount = framekount + 1
MyLocation = collections.namedtuple("MyLocation",["locx","locy","locz"])
MyLocation.locx = MsgFields.locx
MyLocation.locy = MsgFields.locy
MyLocation.locz = MsgFields.locz
#if (framekount > 20):
# pu.printatoms(atomspace)
# exit()
elif (MsgFields.msgtype == "ENDFRAME"):
objAttn, attention = pu.getAttention(atomspace,MsgFields,framename)
message = "444 UNITY " + str(MsgFields.frame) + " " + objAttn + " " + str(attention)
pu.sendmessagezmq(sendsocket,message)
cogbindkount = cogbindkount + 1
print "Frame: " + str(MsgFields.frame) + " Attention Object: " + str(objAttn) + " Attention Value: " + str(attention)
#if (cogbindkount > 1200):
# exit()
elif (MsgFields.msgtype == "STARTOPENCOG"):
pu.ontology_setup(atomspace,TRUTH_VALUE) # reinitializes atomspace
message = "444 UNITY " + str(MsgFields.frame) + " OPENCOGSTARTED"
pu.sendmessagezmq(sendsocket,message)
print "sent: " + message
else:
print "bad message type"
exit()