예제 #1
0
 def action(self):
     # Setting a filter
     f = Filter()
     # The object 'f' is the 'model' of message you want to receive
     f.set_ontology(self.agent.section
                    )  # The filter only accept agent's section messages
     if self.agent.has_messages():
         message = self.agent.read(f)
         if message != None:  # Filtering the message
             display(self.agent,
                     'I received this list: \n%s' % message.content)
예제 #2
0
 def action(self):
     f = Filter()
     f.set_performative(ACLMessage.REQUEST)
     f.set_ontology('foods')
     message = self.read()
     if f.filter(message):  # If the message satisfies the filter
         reply = message.create_reply()
         reply.set_content('meat\nchicken\ncookies\nice cream\nbread')
         reply.set_performative(ACLMessage.INFORM)
         self.agent.send(reply)
         display(self.agent,
                 'Food list sent to %s.' % message.sender.getLocalName())
예제 #3
0
 def action(self):
     f = Filter()
     f.set_performative(ACLMessage.REQUEST)
     f.set_ontology('office')
     message = self.read()
     if f.filter(message):
         reply = message.create_reply()
         reply.set_content('pen\nclips\nscissors\npaper\npencil')
         reply.set_performative(ACLMessage.INFORM)
         self.agent.send(reply)
         display(
             self.agent, 'Office material list sent to %s.' %
             message.sender.getLocalName())
예제 #4
0
    def action(self):
        # Setting a filter
        f = Filter()
        f.set_performative(ACLMessage.REQUEST)  # Accept only REQUEST messages
        f.set_ontology('fruits')

        # Reveiving a message and filtering it
        message = self.read()
        if f.filter(message):  # If the message satisfies the filter
            reply = message.create_reply()
            reply.set_content(
                'apple\nbanana\ncocoa\ncoconuts\ngrape\norange\nstrawberry')
            reply.set_performative(ACLMessage.INFORM)
            self.agent.send(reply)
            display(self.agent,
                    'Fruit list sent to %s.' % message.sender.getLocalName())
예제 #5
0
    def action(self):
        # Setting the filter
        f = Filter()
        f.set_performative(ACLMessage.REQUEST)
        f.set_ontology('foods')

        # Filtering the received message based on 'f' filter
        if self.agent.has_messages(
        ):  # If the message satisfies the filter 'f'
            message = self.agent.read(f)
            if message != None:
                reply = message.create_reply()  # Creates a reply to the sender
                reply = message.create_reply()
                reply.set_content('meat\nchicken\ncookies\nice cream\nbread')
                reply.set_performative(ACLMessage.INFORM)
                self.send(reply)
                display(self.agent,
                        'Food list sent to %s.' % message.sender.getName())
예제 #6
0
    def action(self):
        # Setting the filter
        f = Filter()
        f.set_performative(ACLMessage.REQUEST)
        f.set_ontology('office')

        # Filtering the received message based on 'f' filter
        if self.agent.has_messages(
        ):  # If the message satisfies the filter 'f'
            message = self.agent.read(f)
            if message != None:
                reply = message.create_reply()  # Creates a reply to the sender
                reply = message.create_reply()
                reply.set_content('pen\nclips\nscissors\npaper\npencil')
                reply.set_performative(ACLMessage.INFORM)
                self.send(reply)
                display(
                    self.agent, 'Office material list sent to %s.' %
                    message.sender.getName())
예제 #7
0
    def action(self):
        # Setting the filter
        f = Filter()
        # The object 'f' is the 'model' of message you want to receive
        f.set_performative(ACLMessage.REQUEST)  # Only accept REQUEST messages
        f.set_ontology(
            'fruits')  # Only accept messagens with 'fruits' in ontology field

        # Filtering the received message based on 'f' filter
        if self.agent.has_messages(
        ):  # If the message satisfies the filter 'f'
            message = self.agent.read(f)
            if message != None:
                reply = message.create_reply()  # Creates a reply to the sender
                reply.set_content(
                    'apple\nbanana\ncocoa\ncoconuts\ngrape\norange\nstrawberry'
                )
                reply.set_performative(ACLMessage.INFORM)
                self.send(reply)  # Sends the reply to the sender
                display(self.agent,
                        'Fruit list sent to %s.' % message.sender.getName())