예제 #1
0
    def test_predicate_consolidation(self):
        """
        Test whether the predictor can correctly consolidate multiword
        predicates.
        """
        tokenizer = SpacyTokenizer(pos_tags=True)

        sent_tokens = tokenizer.tokenize(
            "In December, John decided to join the party.")

        # Emulate predications - for both "decided" and "join"
        predictions = [
            [
                "B-ARG2", "I-ARG2", "O", "B-ARG0", "B-V", "B-ARG1", "I-ARG1",
                "I-ARG1", "I-ARG1", "O"
            ],
            [
                "O", "O", "O", "B-ARG0", "B-BV", "I-BV", "B-V", "B-ARG1",
                "I-ARG1", "O"
            ],
        ]
        # Consolidate
        pred_dict = consolidate_predictions(predictions, sent_tokens)

        # Check that only "decided to join" is left
        assert len(pred_dict) == 1
        tags = list(pred_dict.values())[0]
        assert get_predicate_text(sent_tokens, tags) == "decided to join"
예제 #2
0
    def test_more_than_two_overlapping_predicates(self):
        """
        Test whether the predictor can correctly consolidate multiword
        predicates.
        """
        tokenizer = SpacyTokenizer(pos_tags=True)

        sent_tokens = tokenizer.tokenize(
            "John refused to consider joining the club.")

        # Emulate predications - for "refused" and "consider" and "joining"
        predictions = [
            [
                "B-ARG0", "B-V", "B-ARG1", "I-ARG1", "I-ARG1", "I-ARG1",
                "I-ARG1", "O"
            ],
            [
                "B-ARG0", "B-BV", "I-BV", "B-V", "B-ARG1", "I-ARG1", "I-ARG1",
                "O"
            ],
            ["B-ARG0", "B-BV", "I-BV", "I-BV", "B-V", "B-ARG1", "I-ARG1", "O"],
        ]

        # Consolidate
        pred_dict = consolidate_predictions(predictions, sent_tokens)

        # Check that only "refused to consider to join" is left
        assert len(pred_dict) == 1
        tags = list(pred_dict.values())[0]
        assert get_predicate_text(sent_tokens,
                                  tags) == "refused to consider joining"