Commit 013d3b92 by serfrape

Allow receival of predicates without args (values)

parent 00928232
...@@ -10,6 +10,7 @@ from spade.agent import Agent ...@@ -10,6 +10,7 @@ from spade.agent import Agent
from spade.template import Template from spade.template import Template
from spade.message import Message from spade.message import Message
import json import json
from ast import literal_eval
PERCEPT_TAG = frozenset( PERCEPT_TAG = frozenset(
[pyson.Literal("source", (pyson.Literal("percept"), ))]) [pyson.Literal("source", (pyson.Literal("percept"), ))])
...@@ -98,7 +99,7 @@ class BDIAgent(Agent): ...@@ -98,7 +99,7 @@ class BDIAgent(Agent):
def get_belief(self, key, pyson_format=False): def get_belief(self, key, pyson_format=False):
"""Get an agent's existing belief. The first belief matching """Get an agent's existing belief. The first belief matching
<key> is returned. Keep <pyson_format> False to strip pyson <key> is returned. Keep <pyson_format> False to strip pyson
formatting.""" formatting."""
key = str(key) key = str(key)
for beliefs in self.bdi_agent.beliefs: for beliefs in self.bdi_agent.beliefs:
...@@ -122,7 +123,7 @@ class BDIAgent(Agent): ...@@ -122,7 +123,7 @@ class BDIAgent(Agent):
return None return None
def get_beliefs(self, pyson_format=False): def get_beliefs(self, pyson_format=False):
"""Get agent's beliefs.Keep <pyson_format> False to strip pyson """Get agent's beliefs.Keep <pyson_format> False to strip pyson
formatting.""" formatting."""
belief_list = [] belief_list = []
for beliefs in self.bdi_agent.beliefs: for beliefs in self.bdi_agent.beliefs:
...@@ -137,7 +138,7 @@ class BDIAgent(Agent): ...@@ -137,7 +138,7 @@ class BDIAgent(Agent):
return belief_list return belief_list
def print_beliefs(self, pyson_format=False): def print_beliefs(self, pyson_format=False):
"""Print agent's beliefs.Keep <pyson_format> False to strip pyson """Print agent's beliefs.Keep <pyson_format> False to strip pyson
formatting.""" formatting."""
print("PRINTING BELIEFS") print("PRINTING BELIEFS")
for beliefs in self.bdi_agent.beliefs.values(): for beliefs in self.bdi_agent.beliefs.values():
...@@ -180,8 +181,13 @@ class BDIAgent(Agent): ...@@ -180,8 +181,13 @@ class BDIAgent(Agent):
raise pyson.PysonError( raise pyson.PysonError(
"unknown illocutionary force: %s" % ilf_type) "unknown illocutionary force: %s" % ilf_type)
intention = pyson.runtime.Intention() intention = pyson.runtime.Intention()
message = pyson.Literal( args = literal_eval(received["args"])
received["functor"], tuple([received["args"]]))
if args != tuple():
message = pyson.Literal(
received["functor"], args)
else:
message = pyson.Literal(received["functor"])
message = pyson.freeze(message, intention.scope, {}) message = pyson.freeze(message, intention.scope, {})
tagged_message = message.with_annotation( tagged_message = message.with_annotation(
pyson.Literal("source", (pyson.Literal(str(msg.sender)), ))) pyson.Literal("source", (pyson.Literal(str(msg.sender)), )))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment