def _create_test_configuration(self):
     task_configs = TaskConfigurationFileParser.create_configurations_from_file(
         Path(self.resource_directory, "configuration.yaml"))
     categories = TaskCategoryFileParser.create_categories_from_file(
         Path(self.resource_directory, "configuration.yaml"),
         EntityLabels())
     entity_linking = EntityLinkingFileParser.create_from_file(
         Path(self.resource_directory, "linking.csv"))
     embedding = EmbeddingFileParser.create_from_file(
         Path(self.resource_directory, "embedding"))
     return TestConfiguration(embedding, entity_linking, EntityLabels(),
                              categories, task_configs)
Пример #2
0
 def test_type_missing(self):
     config = {
         "name": "",
         "test_set": str(self.empty_file.relative_to(self.test_dir))
     }
     task_file_parser = TaskFileParser(self.empty_file, EntityLabels())
     with pytest.raises(KeyError):
         task_file_parser.create_task_from_configuration(config)
Пример #3
0
 def test_test_set_missing(self):
     config = {
         "name": "task-name",
         "type": "analogy",
     }
     task_file_parser = TaskFileParser(self.empty_file, EntityLabels())
     with pytest.raises(KeyError):
         task_file_parser.create_task_from_configuration(config)
Пример #4
0
 def test_test_set_does_not_exist(self):
     config = {
         "name": "task-name",
         "type": "analogy",
         "test_set": f"./{uuid.uuid4()}"
     }
     task_file_parser = TaskFileParser(self.empty_file, EntityLabels())
     with pytest.raises(KeyError):
         task_file_parser.create_task_from_configuration(config)
Пример #5
0
    def create_from_file(configuration_file: Path):
        if not configuration_file or not configuration_file.exists():
            return EntityLabels()

        with configuration_file.open("r") as csv_stream:
            csv_reader = csv.reader(csv_stream, delimiter=',')
            entity_labels = EntityLabels()

            next(csv_reader, None)  # skip header
            for row in csv_reader:
                if not row:
                    continue

                knowledgebase_id = row[
                    EntityLabelFileParser.COLUMN_INDEX_KNOWLEDGEBASE_ID]
                entity_label = row[
                    EntityLabelFileParser.COLUMN_INDEX_EMBEDDING_LABEL]
                entity_labels.add(knowledgebase_id, entity_label)

            return entity_labels
    def test_run_disabled_returns_empty_result(self):
        # noinspection PyTypeChecker
        test_configuration = TestConfiguration(
            {}, {}, EntityLabels(), {},
            [TaskConfiguration(TaskType.EUCLIDEAN_OUTLIER_DETECTION, False)])
        task = EuclideanOutlierDetectionTask("Disabled Task", Path())

        result = task.run(test_configuration)

        assert result.is_finalized()
        assert not result.has_results()
    def test_run_disabled_returns_empty_result(self):
        # noinspection PyTypeChecker
        test_configuration = TestConfiguration(
            {}, {}, EntityLabels(), {},
            [TaskConfiguration(TaskType.EUCLIDEAN_NEIGHBORHOOD, False)])
        task = EuclideanNeighborhoodTask("Disabled Task", Path())

        result = task.run(test_configuration)

        assert result.is_finalized()
        assert not result.has_results()
    def test_create_categories_from_file(self):
        file = self._random_test_file()
        with open(file, "w+") as file_output:
            print(f"""
            configuration:
                categories:
                    - category:
                        name: category_name_1
                        enabled: true
                        entities: {self.empty_file.absolute()}
                        tasks:
                            - task:
                                name: task_name_1
                                type: analogy
                                test_set: {self.empty_file.absolute()}
                            - task:
                                name: task_name_2
                                type: cosine_similarity
                                test_set: {self.empty_file.absolute()}
                        categories:
                            - category:
                                name: sub_category_name_1
                                enabled: false
                                entities: {self.empty_file.absolute()}
                                tasks:
                                categories:""",
                  file=file_output)

        entity_labels = EntityLabels()
        categories = TaskCategoryFileParser.create_categories_from_file(
            file, entity_labels)
        assert len(categories) == 1

        category = categories[0]
        assert category.name == "category_name_1"
        assert category.enabled
        assert len(category.tasks) == 2
        assert len(categories) == 1

        task = category.tasks[0]
        assert task.name == "analogy: task_name_1"
        assert task.__class__ == AnalogyTask
        assert task.test_set == self.empty_file

        task = category.tasks[1]
        assert task.name == "cosine_similarity: task_name_2"
        assert task.__class__ == CosineSimilarityTask
        assert task.test_set == self.empty_file

        subcategory = category.categories[0]
        assert subcategory.name == "sub_category_name_1"
        assert not subcategory.enabled
        assert len(subcategory.tasks) == 0
        assert len(subcategory.categories) == 0
Пример #9
0
 def test_relative_paths(self):
     config = {
         "name": "task-name",
         "type": "analogy",
         "test_set": str(self.empty_file.relative_to(self.test_dir))
     }
     task_file_parser = TaskFileParser(self.empty_file, EntityLabels())
     task = task_file_parser.create_task_from_configuration(config)
     assert task.name == "analogy: task-name"
     assert task.__class__ == AnalogyTask
     assert task.test_set == self.empty_file
    def test_run_disabled_returns_empty_result(self):
        # noinspection PyTypeChecker
        test_configuration = TestConfiguration(
            {}, {}, EntityLabels(), {},
            [TaskConfiguration(TaskType.ANALOGY, False)])
        task = AnalogyTask("Disabled Task", Path())

        result = task.run(test_configuration)

        assert result.is_finalized()
        assert not result.has_results()
    def test_create_from_file_empty_categories(self):
        file = self._random_test_file()
        with open(file, "w+") as file_output:
            print(f"""
            configuration:
                categories:""",
                  file=file_output)

        entity_labels = EntityLabels()
        categories = TaskCategoryFileParser.create_categories_from_file(
            file, entity_labels)
        assert len(categories) == 0
    def test_enabled_is_missing(self):
        file = self._random_test_file()
        with open(file, "w+") as file_output:
            print(f"""
                    configuration:
                        categories:
                            - category:
                                name: category_name_1
                                tasks:
                                categories:""",
                  file=file_output)

        with pytest.raises(KeyError):
            entity_labels = EntityLabels()
            categories = TaskCategoryFileParser.create_categories_from_file(
                file, entity_labels)