def get_label_set(self) -> LabelSet: data0, data1, data2 = self.label_data label0 = Label(name=data0[0], width=data0[1], font_size=data0[2]) label1 = Label(name=data1[0], width=data1[1], font_size=data1[2]) label2 = Label(name=data2[0], width=data2[1], font_size=data2[2]) return LabelSet([label0, label1, label2])
def test_label_set_serialization(): label_entries = [ { Label.KEY_NAME: "aaa", Label.KEY_WIDTH: 10, Label.KEY_FONT_SIZE: 10 }, { Label.KEY_NAME: "bbb", Label.KEY_WIDTH: 20 }, { Label.KEY_NAME: "ccc", Label.KEY_FONT_SIZE: 30 }, { Label.KEY_NAME: "ddd" }, ] submission_entries = [] for entry in label_entries: d = {"name": entry[Label.KEY_NAME]} if Label.KEY_WIDTH in entry: d["width"] = entry[Label.KEY_WIDTH] if Label.KEY_FONT_SIZE in entry: d["font_size"] = entry[Label.KEY_FONT_SIZE] submission_entries.append(d) label_set = LabelSet([Label(**entry) for entry in submission_entries]) serialized_label_set = label_set.serialize() assert serialized_label_set == label_entries
def test_label_serialization(self): name0, width0, font_size0 = "foo", 100, 14 label0_base = Label(name=name0, width=width0, font_size=font_size0) label0 = Label.deserialize(label0_base.serialize()) assert label0.name == name0 assert label0.width == width0 assert label0.font_size == font_size0 assert label0.name == label0_base.name assert label0.width == label0_base.width assert label0.font_size == label0_base.font_size invalid_labels = {"", True, "xxx", 0, -1} assert label0.name not in invalid_labels assert label0.width not in invalid_labels assert label0.font_size not in invalid_labels
def test_label_attributes(self): name0, width0, font_size0 = "foo", 100, 14 label0 = Label(name=name0, width=width0, font_size=font_size0) assert label0.name == name0 assert label0.width == width0 assert label0.font_size == font_size0 invalid_labels = {"", True, "xxx", 0, -1} assert label0.name not in invalid_labels assert label0.width not in invalid_labels assert label0.font_size not in invalid_labels
def test_label_set_serialization(self): name0, width0, font_size0 = "foo", 100, 14 name1, width1, font_size1 = "bar", 200, 16 name2, width2, font_size2 = "baz", 300, 18 label0 = Label(name=name0, width=width0, font_size=font_size0) label1 = Label(name=name1, width=width1, font_size=font_size1) label2 = Label(name=name2, width=width2, font_size=font_size2) label_set0 = LabelSet([label0, label1, label2]) assert label0 == label_set0[0] assert label1 == label_set0[1] assert label2 == label_set0[2] label_set0_copy = LabelSet.deserialize(label_set0.serialize()) assert label0 == label_set0_copy[0] assert label1 == label_set0_copy[1] assert label2 == label_set0_copy[2] assert label0 != label_set0_copy[1] assert label1 != label_set0_copy[2] assert label2 != label_set0_copy[0]
def _add_transform_to_data_view( cls, transform: Transform, updated_transforms: TransformList, updated_labels: LabelSequence, data_view: DataView, ) -> Tuple[TransformList, LabelSequence]: log.info(f"Adding transform to {data_view.id}") updated_transforms = TransformList(updated_transforms) updated_labels = LabelSequence(updated_labels) updated_transforms.append(transform) if isinstance(transform, EnrichmentTransform): updated_labels.extendleft( [Label(name) for name in transform.output_labels]) return updated_transforms, updated_labels
def get_label(self, name: str, data_view: DataView) -> Label: try: return self._label_by_name_by_data_view.get(data_view).get(name) except KeyError: return Label(name=name)
def get_dataset_labels(self, dataset: Dataset) -> LabelSequence: path = self.data_dir / dataset.filename dataset_reader = self._get_dataset_reader(path) return LabelSequence( [Label(name=name) for name in dataset_reader(path).keys()])