Пример #1
0
    def dataReceived(self, data):
        # Remove extra escape characters
        data = data.replace('\\','')
        print 'Received input: ', data

        knowledge_demo = data.startswith(SECRET_CODE)
        if knowledge_demo:
            data = data[len(SECRET_CODE):]

        with open(LOG_FILE, 'a') as f:
            f.write('%s | %s | "%s"\n' % (time.asctime(), str(self.transport.getPeer()), data))

        with self.lock:
            parse = PipelineClient(verbose=True).parse(data)

        response = {}
        frames, new_commands, kb_response = process_parse_tree(parse, data, self.kb if knowledge_demo else None, quiet=True)
        response['parse'] = parse
        if frames is not None:
            # We do a join and split to make sure all whitespace becomes single spaces
            modified_trees = [" ".join(str(modified_parse_tree[1]).split())
                              for modified_parse_tree in frames
                              if (len(modified_parse_tree) > 1 and
                                  isinstance(modified_parse_tree[1], tree.Tree))]
            response['trees'] = list(set(modified_trees))
            response['frames'] = [frame_dict for frame_dict in [frame[0] for frame in frames
                                                    if isinstance(frame[0], dict)]]
        else:
            response['trees'] = []
            response['frames'] = []
        response['response'] = make_response(new_commands, kb_response)
        response['structures'] = '\n\n'.join(str(c) for c in new_commands)
        self.transport.write(json.dumps(response))
Пример #2
0
    def dataReceived(self, data):
        lines = data.split('\n')
        print 'Received input: ', lines

        for s in lines:
            if s.startswith('CHAT_MESSAGE_PREFIX'):
                s = remove_prefix(s, 'CHAT_MESSAGE_PREFIX<Commander> ')
                # TODO: multi-process lock
                parse = PipelineClient().parse(s)
                frames, new_commands, kb_response = process_parse_tree(
                    parse, data, self.kb, quiet=True)
                self.sendMessage(
                    'CHAT_MESSAGE_PREFIX',
                    '<Junior> ' + make_response(new_commands, kb_response))
                self.ge.jr.plan_path(self.ge.cmdr.cell)
            elif s.startswith('MOVE_PLAYER_CELL'):
                s = remove_prefix(s, 'MOVE_PLAYER_CELL')
                new_x, old_x, new_y, old_y = s.split(',')
                self.ge.update_cmdr((int(new_x), int(new_y)))
                print str(self.ge)
            elif s.startswith('CREATE_FPSENVIRONMENT'):
                s = remove_prefix(s, 'CREATE_FPSENVIRONMENT')
                # This will be provided before environment related messages
                self.ge = GameEnvironment(s)
                lc = LoopingCall(self.ge.jr.follow_waypoints, self.sendMessage)
                lc.start(0.05)
Пример #3
0
def process_input(text, kb, verbose=True):
    """Send given text to the semantics component"""
    msg = PipelineClient().parse(text)
    if msg:
        print msg
        frames, new_commands, kb_response = process_parse_tree(msg, text, kb, quiet=True)
        if verbose:
            print "Frames: %s" % '\n'.join(str(f) for f in frames);
            print "Knowledge base: %s" % str(kb)
        
        print 'Response: %s' % make_response(new_commands, kb_response)
        print '\n'.join(str(c) for c in new_commands)
        return True
    else:
        print 'Connection to server closed.'
        return False
Пример #4
0
def process_input(text, kb, verbose=True):
    """Send given text to the semantics component"""
    msg = PipelineClient().parse(text)
    if msg:
        print msg
        frames, new_commands, kb_response = process_parse_tree(msg,
                                                               text,
                                                               kb,
                                                               quiet=True)
        if verbose:
            print "Frames: %s" % '\n'.join(str(f) for f in frames)
            print "Knowledge base: %s" % str(kb)

        print 'Response: %s' % make_response(new_commands, kb_response)
        print '\n'.join(str(c) for c in new_commands)
        return True
    else:
        print 'Connection to server closed.'
        return False
Пример #5
0
    def dataReceived(self, data):
        # Remove extra escape characters
        data = data.replace('\\', '')
        print 'Received input: ', data

        knowledge_demo = data.startswith(SECRET_CODE)
        if knowledge_demo:
            data = data[len(SECRET_CODE):]

        with open(LOG_FILE, 'a') as f:
            f.write('%s | %s | "%s"\n' %
                    (time.asctime(), str(self.transport.getPeer()), data))

        with self.lock:
            parse = PipelineClient(verbose=True).parse(data)

        response = {}
        frames, new_commands, kb_response = process_parse_tree(
            parse, data, self.kb if knowledge_demo else None, quiet=True)
        response['parse'] = parse
        if frames is not None:
            # We do a join and split to make sure all whitespace becomes single spaces
            modified_trees = [
                " ".join(str(modified_parse_tree[1]).split())
                for modified_parse_tree in frames
                if (len(modified_parse_tree) > 1
                    and isinstance(modified_parse_tree[1], tree.Tree))
            ]
            response['trees'] = list(set(modified_trees))
            response['frames'] = [
                frame_dict for frame_dict in
                [frame[0] for frame in frames if isinstance(frame[0], dict)]
            ]
        else:
            response['trees'] = []
            response['frames'] = []
        response['response'] = make_response(new_commands, kb_response)
        response['structures'] = '\n\n'.join(str(c) for c in new_commands)
        self.transport.write(json.dumps(response))
Пример #6
0
    def dataReceived(self, data):
        lines = data.split('\n')
        print 'Received input: ', lines

        for s in lines:
            if s.startswith('CHAT_MESSAGE_PREFIX'):
                s = remove_prefix(s, 'CHAT_MESSAGE_PREFIX<Commander> ')
                # TODO: multi-process lock
                parse = PipelineClient().parse(s)
                frames, new_commands, kb_response = process_parse_tree(parse, data, self.kb, quiet=True)
                self.sendMessage('CHAT_MESSAGE_PREFIX', '<Junior> ' + make_response(new_commands, kb_response))
                self.ge.jr.plan_path(self.ge.cmdr.cell)
            elif s.startswith('MOVE_PLAYER_CELL'):
                s = remove_prefix(s, 'MOVE_PLAYER_CELL')
                new_x, old_x, new_y, old_y = s.split(',')
                self.ge.update_cmdr((int(new_x), int(new_y)))
                print str(self.ge)
            elif s.startswith('CREATE_FPSENVIRONMENT'):
                s = remove_prefix(s, 'CREATE_FPSENVIRONMENT')
                # This will be provided before environment related messages
                self.ge = GameEnvironment(s)
                lc = LoopingCall(self.ge.jr.follow_waypoints, self.sendMessage)
                lc.start(0.05)