Exemplo n.º 1
0
    def test_task_functions(self, input_patch, output_patch):
        with mock.patch(
            "bwg.tasks.naive_ore.NaiveOpenRelationExtractionTask.workflow_resources", new_callable=mock.PropertyMock()
        ) as workflow_mock:
            task_config = {
                "NER_TAGSET": ["I-P", "I-N"],
                "DEFAULT_NE_TAG": "O",
                "VERB_NODE_POS_TAGS": ["VV"],
                "OMITTED_TOKENS_FOR_ALIGNMENT": [],
                "CORPUS_ENCODING": "",
                "ORE_OUTPUT_PATH": ""
            }

            output_patch.return_value = MockOutput()
            input_patch.return_value = (
                MockInput(NAIVE_OPEN_RELATION_EXTRACTION_TASK["input"][0]),
                MockInput(NAIVE_OPEN_RELATION_EXTRACTION_TASK["input"][1]),
                MockInput(NAIVE_OPEN_RELATION_EXTRACTION_TASK["input"][2])
            )
            workflow_mock.__get__ = mock.Mock(return_value={})

            task = bwg.tasks.naive_ore.NaiveOpenRelationExtractionTask(task_config=task_config)

            # Testing
            self._test_task(task)
            self._test_extract_relations_from_sentence(task)
            self._test_get_sentence()
            self._test_align_tagged_sentence(task)
            self._test_normalize_node_addresses()
            self._test_extract_verb_nodes(task)
            self._test_expand_node(task)
            self._test_word_is_ne_tagged(task)
            self._test_join_expanded_node()
            self._test_get_subj_and_obj()
            self._test_extract_relations(task)
Exemplo n.º 2
0
    def test_task_functions(self, input_patch, output_patch):
        task_config = {
            "NEO4J_USER": "",
            "NEO4J_PASSWORD": "",
            "NEO4J_HOST": "",
            "DATABASE_CATEGORIES": {},
            "CORPUS_ENCODING": ""
        }

        output_patch.return_value = MockOutput()
        input_patch.return_value = MockInput(
            RELATIONS_DATABASE_WRITING_TASK["input"])

        task = bwg.tasks.relations_database_writing.RelationsDatabaseWritingTask(
            task_config=task_config)

        # Testing
        self._test_process_article(task)
        self._test_read_properties_file(task)
        self._test_extract_properties(task)
        self._test_add_entity_data_to_properties_dict(task)
        self._test_convert_entity_sense(task)
        self._test_rename_field()
        self._test_read_pipeline_run_info(task)
        self._test_is_relevant(task)
        self._test_is_relevant_node(task)
        self._test_categorize_node(task)
Exemplo n.º 3
0
    def test_task_functions(self, input_patch, output_patch):
        with mock.patch(
                "bwg.tasks.pos_tagging.PoSTaggingTask.workflow_resources",
                new_callable=mock.PropertyMock()) as workflow_mock:
            task_config = {
                "STANFORD_POSTAGGER_PATH": "",
                "STANFORD_MODELS_PATH": "",
                "STANFORD_POS_MODEL_PATH": "",
                "CORPUS_ENCODING": "",
                "POS_OUTPUT_PATH": ""
            }

            output_patch.return_value = MockOutput()
            input_patch.return_value = MockInput(POS_TAGGING_TASK["input"])
            workflow_mock.__get__ = mock.Mock(
                return_value={
                    "tokenizer": MockTokenizer(),
                    "pos_tagger": MockTagger(self.naive_pos_tag)
                })

            task = bwg.tasks.pos_tagging.PoSTaggingTask(
                task_config=task_config)

            # Testing
            self._test_task(task)
            self._test_pos_tag(task)
 def test_task(self, open_patch, output_patch):
     open_patch.return_value = MockInput(READING_TASK["input"])
     output_patch.return_value = MockOutput()
     self.task.run()
     output_mock = output_patch()
     assert [
         json.loads(content, encoding="utf-8")
         for content in output_mock.contents
     ] == READING_TASK["output"]
Exemplo n.º 5
0
    def test_task_functions(self, input_patch, output_patch):
        with mock.patch(
                "bwg.tasks.relation_merging.RelationMergingTask.workflow_resources",
                new_callable=mock.PropertyMock()) as workflow_mock:
            task_config = {
                "CORPUS_ENCODING": "",
                "RELATION_MERGING_OUTPUT_PATH": ""
            }

            output_patch.return_value = MockOutput()
            input_patch.return_value = (MockInput(
                RELATION_MERGING_TASK["input"][0]),
                                        MockInput(
                                            RELATION_MERGING_TASK["input"][0]))
            workflow_mock.__get__ = mock.Mock(return_value={})

            task = bwg.tasks.relation_merging.RelationMergingTask(
                task_config=task_config)

            # Testing
            self._test_get_relations_from_sentence_json()
            self._test_is_relevant_article(task)
            self._test_is_relevant_sentence(task)
Exemplo n.º 6
0
    def test_task_functions(self, input_patch, output_patch):
        task_config = {
            "CORPUS_ENCODING": "",
            "PIPELINE_RUN_INFO_OUTPUT_PATH": ""
        }

        output_patch.return_value = MockOutput()
        input_patch.return_value = MockInput(
            PIPELINE_RUN_INFO_GENERATION_TASK["input"])

        task = bwg.tasks.relation_merging.RelationMergingTask(
            task_config=task_config)

        # Testing
        self._test_generate_run_information(task)
        self._test_generate_run_hash()
        self._test_generate_timestamp()
    def test_task_functions(self, input_patch, output_patch):
        with mock.patch(
                "bwg.tasks.dependency_parsing.DependencyParseTask.workflow_resources",
                new_callable=mock.PropertyMock()) as workflow_mock:
            task_config = {
                "STANFORD_DEPENDENCY_MODEL_PATH": "",
                "STANFORD_CORENLP_MODELS_PATH": "",
                "CORPUS_ENCODING": "",
                "DEPENDENCY_OUTPUT_PATH": ""
            }

            output_patch.return_value = MockOutput()
            input_patch.return_value = MockInput(DEPENDENCY_TASK["input"])
            workflow_mock.__get__ = mock.Mock(
                return_value={"dependency_parser": MockParser()})

            task = bwg.tasks.dependency_parsing.DependencyParseTask(
                task_config=task_config)

            # Testing
            self._test_task(task)
            self._test_dependency_parse(task)
    def test_task_functions(self, input_patch, output_patch):
        with mock.patch(
                "bwg.tasks.participation_extraction.ParticipationExtractionTask.workflow_resources",
                new_callable=mock.PropertyMock()) as workflow_mock:
            task_config = {
                "DEFAULT_NE_TAG": "O",
                "PARTICIPATION_PHRASES": self.participation_phrases,
                "PE_OUTPUT_PATH": "",
                "CORPUS_ENCODING": ""
            }

            output_patch.return_value = MockOutput()
            input_patch.return_value = MockInput(
                PARTICIPATION_EXTRACTION_TASK["input"])
            workflow_mock.__get__ = mock.Mock(return_value={})

            task = bwg.tasks.participation_extraction.ParticipationExtractionTask(
                task_config=task_config)

            # Testing
            self._test_task(task)
            self._test_build_participation_relations()
            self._test_get_sentence()