Exemplo n.º 1
0
    def analyze(self, chinese_str):
        data = {'quantity': 1, 'x': 0, 'y': 0, 'item_name': "桌子"}

        x = randint(-7, 7)
        y = randint(-5, 5)
        data.update({'x': x, 'y': y})
        matched = False

        for expressions in self.re_collection:
            match_result = re.search(expressions, chinese_str)
            if not match_result is None:
                for k in match_result.groupdict().keys():
                    res_dict = match_result.groupdict()
                    val = res_dict[k]
                    data.update({k: val})
                    matched = True
                break
        item_command = data['item_name']
        item_command = self.item_converter[item_command]
        data.update({'item_name': item_command})

        if matched:
            iter_time = data['quantity']
            iter_time = CHINESE_STRING_TO_INT(iter_time)
            for i in range(0, iter_time):
                res_string = 'Instantiation ' + str(data['x']) + ' ' + str(
                    data['y']) + ' ' + item_command
                print(res_string)
        else:
            print('exception')
Exemplo n.º 2
0
    def analyze(self, chinese_str):
        data = {'quantity': 1, 'x': 0, 'y': 0, 'item_name': "桌子"}

        x = randint(-7, 7)
        y = randint(-5, 5)
        data.update({'x': x, 'y': y})
        matched = False

        for expressions in self.re_collection:
            match_result = re.search(expressions, chinese_str)
            if not match_result is None:
                for k in match_result.groupdict().keys():
                    res_dict = match_result.groupdict()
                    val = res_dict[k]
                    data.update({k: val})
                    matched = True
                # break
        item_command = data['item_name']
        item_command = self.item_converter[item_command]
        data.update({'item_name': item_command})
        # print(data)

        if 'location' in data.keys():
            try:
                val = data['location']
                x, y = self.location_converter[val]
                data.update({'x': x, 'y': y})

            except NameError:
                pass
        if 'sit' in data.keys():
            data.update({'item_name': 'chair'})
        if 'desk' in data.keys():
            data.update({'item_name': 'desk'})
        if 'chair' in data.keys():
            data.update({'item_name': 'chair'})

        if matched:
            iter_time = data['quantity']
            iter_time = CHINESE_STRING_TO_INT(iter_time)
            # item_command=data[it\]
            for i in range(0, iter_time):
                res_string = 'Instantiation ' + str(data['x']) + ' ' + str(
                    data['y']) + ' ' + data['item_name']
                print(res_string)
        else:
            print('exception')
Exemplo n.º 3
0
    def analyze(self,chinese_str):
        data={
            'item_name':'桌子',
            'item_id':0,
            'quantity':1,
        }

        matched=False

        for expressions in self.re_collection:
            match_result=re.search(expressions,chinese_str)
            if not match_result is None:
                for k in match_result.groupdict().keys():
                    res_dict = match_result.groupdict()
                    val = res_dict[k]
                    data.update({k: val})
                    matched=True
                # break
        item_command=data['item_name']
        item_command=self.item_converter[item_command]
        data.update({'item_name':item_command})

        if 'sit' in data.keys():
            data.update({'item_name':'chair'})
        if 'desk' in data.keys():
            data.update({'item_name':'desk'})
        if 'chair' in data.keys():
            data.update({'item_name':'chair'})

        if matched:
            iter_time=data['quantity']
            iter_time=CHINESE_STRING_TO_INT(iter_time)
            for i in range(0,iter_time):
                res_string='Delete '+ str(data['item_name'])+' '+str(data['item_id'])
                print(res_string)
        else:
            print('exception')
        return
Exemplo n.º 4
0
    def analyze(self, chinese_str):
        data = {
            'quantity': 1,
            'x': 0,
            'y': 0,
            'item_name': "桌子",
            'red': 255,
            'blue': 245,
            'green': 255,
            'alpha': 80
        }

        x = randint(-7, 7)
        y = randint(-5, 5)
        data.update({'x': x, 'y': y})
        matched = False

        for expressions in self.re_collection:
            match_result = re.search(expressions, chinese_str)
            if not match_result is None:
                for k in match_result.groupdict().keys():
                    res_dict = match_result.groupdict()
                    val = res_dict[k]
                    data.update({k: val})
                    matched = True
                # break
        item_command = data['item_name']
        item_command = self.item_converter[item_command]
        data.update({'item_name': item_command})
        print(data)

        # if 'location' in data.keys():
        #     try:
        #         val=data['location']
        #         x,y =self.location_converter[val]
        #         data.update({'x': x, 'y': y})
        #
        #     except NameError:
        #         pass
        if 'sit' in data.keys():
            data.update({'item_name': 'chair'})
        if 'desk' in data.keys():
            data.update({'item_name': 'desk'})
        if 'chair' in data.keys():
            data.update({'item_name': 'chair'})
        if 'color' in data.keys():
            try:
                val = data['color']
                red, green, blue = self.color_rgb[val]
                data.update({'red': red, 'green': green, 'blue': blue})
                # data.update({'x': x, 'y': y})
            except NameError:
                pass

        if matched:
            iter_time = data['quantity']
            iter_time = CHINESE_STRING_TO_INT(iter_time)
            # item_command=data[it\]
            for i in range(0, iter_time):
                res_string = 'ChangeColor ' + str(
                    data['item_name']) + ' ' + str(data['red']) + ' ' + str(
                        data['green']) + ' ' + str(data['blue']) + ' ' + str(
                            data['alpha'])
                print(res_string)
        else:
            print('exception')