Пример #1
0
    def __init__(self):
        super().__init__(output=True)
        self.vision = Vision(self)
        self.memory = Memory(self)
        self.audition = Audition(self)
        self.typing = Typing(Hands(self))

        def interpreter(words):
            if words[0] == 'read':
                sem = Item(isa='action', type='read', object=words[1])
                pointer = self.vision.find(isa='pointer')
                if pointer is not None:
                    self.vision.encode(pointer)
                    sem.set('x', pointer.x).set('y', pointer.y)
                return sem
            elif words[0] == 'done':
                return Item(isa='done')
            else:
                return Item(isa='action', type=words[0], object=words[1])

        self.language = Language(self)
        self.language.add_interpreter(interpreter)

        def executor(action, context):
            if action.type == 'read':
                query = Query(x=action.x, y=action.y)
                context.set(action.object, self.vision.find_and_encode(query))
            elif action.type == 'type':
                self.typing.type(context.get(action.object))

        self.instruction = Instruction(
            self, self.memory, self.audition, self.language)
        self.instruction.add_executor(executor)
Пример #2
0
class ACEUndifferentiatedAgent(Agent):
    def __init__(self):
        """Initializes the agent"""
        super().__init__(output=True)
        self.memory = Memory(self)
        self.vision = Vision(self)
        self.audition = Audition(self)
        self.typing = Typing(Hands(self))

        self.language = Language(self)
        self.language.add_interpreter(self.interpret)

        self.instruction = Instruction(self, self.memory, self.audition,
                                       self.language)
        self.instruction.add_executor(self.execute)

    def _ace_to_owl(self, text):
        """Converts ACE instruction text to OWL XML using the web API"""
        url = 'http://attempto.ifi.uzh.ch/ws/ape/apews.perl'
        params = {
            'text': text,
            'guess': 'on',
            # 'solo': 'owlxml',
            'cdrs': 'on',
            'cowlxml': 'on',
        }
        data = parse.urlencode(params).encode()
        req = request.Request(url, parse.urlencode(params).encode())
        res = request.urlopen(req)
        xml_string = res.read().decode('utf-8')
        print(xml_string)
        xml = ElementTree.fromstring(xml_string)
        print(xml)
        # print(ElementTree.tostring(xml, encoding='utf8', method='xml'))

    def interpret(self, words):
        self._ace_to_owl(' '.join(words))
        if words[0] == 'read':
            sem = Item(isa='action', type='read', object=words[1])
            pointer = self.vision.find(isa='pointer')
            if pointer is not None:
                self.vision.encode(pointer)
                sem.set('x', pointer.x).set('y', pointer.y)
            return sem
        elif words[0] == 'done':
            return Item(isa='done')
        else:
            return Item(isa='action', type=words[0], object=words[1])

    def execute(self, action, context):
        if action.type == 'read':
            query = Query(x=action.x, y=action.y)
            context.set(action.object, self.vision.find_and_encode(query))
        elif action.type == 'type':
            self.typing.type(context.get(action.object))

    def run(self, time=300):
        goal = self.instruction.listen_and_learn()
        self.instruction.execute(goal)
Пример #3
0
class PVTAgent(Agent):
    def __init__(self):
        """Initializes the agent"""
        super().__init__(output=True)
        self.vision = Vision(self)
        self.audition = Audition(self)
        self.typing = Typing(Hands(self))

    def run(self, time=300):
        while self.time() < time:
            visual = self.vision.wait_for(seen=False)
            self.vision.start_encode(visual)
            self.typing.type('j')
            self.vision.get_encoded()
Пример #4
0
    def __init__(self):
        """Initializes the agent"""
        super().__init__(output=True)
        self.memory = Memory(self)
        self.vision = Vision(self)
        self.audition = Audition(self)
        self.typing = Typing(Hands(self))

        self.language = Language(self)
        self.language.add_interpreter(self.interpret)

        self.instruction = Instruction(self, self.memory, self.audition,
                                       self.language)
        self.instruction.add_executor(self.execute)
Пример #5
0
    def __init__(self):
        """Initializes the agent"""
        super().__init__(output=True)
        self.memory = Memory(self)
        self.vision = Vision(self)
        self.audition = Audition(self)
        self.hands = Hands(self)
        self.mouse = Mouse(self.hands, self.vision)
        self.typing = Typing(self.hands)

        self.language = Language(self)
        self.language.add_interpreter(self.interpret)
Пример #6
0
class SearchAgent(Agent):

    def __init__(self):
        super().__init__(output=True)
        self.vision = Vision(self)
        self.audition = Audition(self)
        self.typing = Typing(Hands(self))

    def run(self, time=300):
        while self.time() < time:
            visual = self.vision.wait_for(seen=False)
            while (visual is not None
                    and not visual.isa == 'vertical-line'):
                obj = self.vision.encode(visual)
                print('**** skip')
                visual = self.vision.find(seen=False)
            if visual:
                print('**** found')
                self.typing.type('j')
                self.vision.encode(visual)
            else:
                print('**** not found')
                self.typing.type('k')
Пример #7
0
    def run_trial(self):
        agent = Agent(output=False)
        memory = Memory(agent, Memory.OPTIMIZED_DECAY)
        memory.decay_rate = .5
        memory.activation_noise = .5
        memory.retrieval_threshold = -1.8
        memory.latency_factor = .450
        vision = Vision(agent)
        typing = Typing(Hands(agent))
        self.trial_start = 0
        self.block_index = 0

        def fn():
            for i in range(PairedAssociatesTest.N_BLOCKS):
                self.block_index = i
                pairs = PairedAssociatesTest.PAIRS.copy()
                random.shuffle(pairs)
                for pair in pairs:
                    self.trial_start = agent.time()
                    vision.clear().add(Visual(50, 50, 20, 20, 'word'), pair[0])
                    agent.wait(5.0)
                    vision.clear().add(
                        Visual(50, 50, 20, 20, 'digit'), pair[1])
                    agent.wait(5.0)
        agent.run_thread(fn)

        def type_fn(c):
            self.rt.add(self.block_index, agent.time() - self.trial_start)
        typing.add_type_fn(type_fn)
        for i in range(PairedAssociatesTest.N_BLOCKS):
            for _ in range(len(PairedAssociatesTest.PAIRS)):
                word = vision.encode(vision.wait_for(isa='word'))
                chunk = memory.recall(word=word)
                if chunk:
                    typing.type(chunk.get('digit'))
                    self.correct.add(i, 1)
                else:
                    self.correct.add(i, 0)
                digit = vision.encode(vision.wait_for(isa='digit'))
                memory.store(word=word, digit=digit)
        agent.wait_for_all()
Пример #8
0
 def __init__(self):
     """Initializes the agent"""
     super().__init__(output=True)
     self.vision = Vision(self)
     self.audition = Audition(self)
     self.typing = Typing(Hands(self))
Пример #9
0
 def test_typing(self, output=False):
     agent = Agent(output=output)
     typing = Typing(Hands(agent))
     typing.type("Hello there. What's up?")
     agent.wait_for_all()
     self.assertAlmostEqual(6.597, agent.time(), 1)
Пример #10
0
 def test_timing(self, output=False):
     agent = Agent(output=output)
     typing = Typing(Hands(agent))
     self.assertAlmostEqual(6.597,
                            typing.typing_time("Hello there. What's up?"),
                            1)
Пример #11
0
 def __init__(self):
     super().__init__(output=True)
     self.vision = Vision(self)
     self.audition = Audition(self)
     self.typing = Typing(Hands(self))