示例#1
0
    def get_attributes(self):
        """ return attributes by tornado Attributes type

            @return:
            attributes: Attributes
        """
        attributes = []
        dim_index = 0
        dataset_attributes = Dataset.get_attributes(self.dataset)

        for attr in dataset_attributes:
            for index in range(attr[1]):
                attribute = Attribute()
                attribute.set_name('{}_{}'.format(attr[0], index))
                attribute.set_type(TornadoDic.NUMERIC_ATTRIBUTE)
                attribute.set_possible_values([])
                if self.split:
                    range_dim = self.configuration['split']['range'][
                        self.cur_data_slit][dim_index]
                else:
                    range_dim = self.configuration['all']['range'][dim_index]
                attribute.set_bounds_values(range_dim[0], range_dim[1])
                if attr[0] != 'cast':
                    attributes.append(attribute)
                dim_index += 1
        return [0, 1], attributes
 def construct_attribute(self):
     for attr in [('warning_level', self.le, [0, 1, 2])]:
         for index in range(attr[1]):
             attribute = Attribute()
             attribute.set_name('{}_{}'.format(attr[0], index))
             attribute.set_type(TornadoDic.NOMINAL_ATTRIBUTE)
             attribute.set_possible_values(attr[2])
             self.attributes.append(attribute)
def construct_attribute():
    nb_property = []
    for attr in [('warning_level', 1, [1, 2, 3])]:
        for index in range(attr[1]):
            att = Attribute()
            att.set_name('{}_{}'.format(attr[0], index))
            att.set_type(TornadoDic.NOMINAL_ATTRIBUTE)
            att.set_possible_values(attr[2])
            nb_property.append(att)
    return nb_property
示例#4
0
    def read(file_path):
        labels = []
        attributes = []
        attributes_min_max = []
        records = []
        data_flag = False
        reader = open(file_path, "r")
        for line in reader:
            
            if line.strip() == '':
                continue
            
            if line.startswith("@attribute") or line.startswith("@ATTRIBUTE"):

                line = line.strip('\n\r\t')
                line = line.split(' ')

                attribute_name = line[1]
                attribute_value_range = line[2]

                attribute = Attribute()
                attribute.set_name(attribute_name)
                if attribute_value_range.lower() in ['numeric', 'real', 'integer']:
                    attribute_type = TornadoDic.NUMERIC_ATTRIBUTE
                    attribute_value_range = []
                    attributes_min_max.append([0, 0])
                else:
                    attribute_type = TornadoDic.NOMINAL_ATTRIBUTE
                    attribute_value_range = attribute_value_range.strip('{}').replace("'", "")
                    attribute_value_range = attribute_value_range.split(',')
                    attributes_min_max.append([None, None])
                attribute.set_type(attribute_type)
                attribute.set_possible_values(attribute_value_range)

                attributes.append(attribute)

            elif line.startswith("@data") or line.startswith("@DATA"):
                data_flag = True
                labels = attributes[len(attributes) - 1].POSSIBLE_VALUES
                attributes.pop(len(attributes) - 1)
                continue

            elif data_flag is True:
                line = re.sub('\s+', '', line)
                elements = line.split(',')
                for i in range(0, len(elements) - 1):
                    if attributes[i].TYPE == TornadoDic.NUMERIC_ATTRIBUTE:
                        elements[i] = float(elements[i])
                        min_value = attributes_min_max[i][0]
                        max_value = attributes_min_max[i][1]
                        if elements[i] < min_value:
                            min_value = elements[i]
                        elif elements[i] > max_value:
                            max_value = elements[i]
                        attributes_min_max[i] = [min_value, max_value]
                records.append(elements)

        for i in range(0, len(attributes)):
            if attributes[i].TYPE == TornadoDic.NUMERIC_ATTRIBUTE:
                attributes[i].set_bounds_values(attributes_min_max[i][0], attributes_min_max[i][1])

        return labels, attributes, records