Пример #1
0
    def test_perl_eval_script_can_run_on_printed_conll_files(self):
        bio_tags = ["B-ARG-1", "I-ARG-1", "O", "B-V", "B-ARGM-ADJ", "O"]
        sentence = ["Mark", "and", "Matt", "were", "running", "fast", "."]

        gold_file_path = os.path.join(self.TEST_DIR, "gold_conll_eval.txt")
        prediction_file_path = os.path.join(self.TEST_DIR,
                                            "prediction_conll_eval.txt")
        with open(gold_file_path,
                  "a+") as gold_file, open(prediction_file_path,
                                           "a+") as prediction_file:
            # Use the same bio tags as prediction vs gold to make it obvious by looking
            # at the perl script output if something is wrong. Write them twice to
            # ensure that the perl script deals with multiple sentences.
            write_bio_formatted_tags_to_file(gold_file, prediction_file, 4,
                                             sentence, bio_tags, bio_tags)
            write_bio_formatted_tags_to_file(gold_file, prediction_file, 4,
                                             sentence, bio_tags, bio_tags)

        perl_script_command = [
            "perl",
            str(self.TOOLS_ROOT / "srl-eval.pl"), prediction_file_path,
            gold_file_path
        ]
        exit_code = subprocess.check_call(perl_script_command)
        assert exit_code == 0
Пример #2
0
def write_to_conll_eval_file(
    prediction_file: TextIO,
    gold_file: TextIO,
    verb_index: Optional[int],
    sentence: List[str],
    prediction: List[str],
    gold_labels: List[str],
):
    """
    .. deprecated:: 0.8.4
       The `write_to_conll_eval_file` function was deprecated in favor of the
       identical `write_bio_formatted_tags_to_file` in version 0.8.4.

    Prints predicate argument predictions and gold labels for a single verbal
    predicate in a sentence to two provided file references.

    The CoNLL SRL format is described in
    [the shared task data README](https://www.lsi.upc.edu/~srlconll/conll05st-release/README).

    This function expects IOB2-formatted tags, where the B- tag is used in the beginning
    of every chunk (i.e. all chunks start with the B- tag).

    # Parameters

    prediction_file : TextIO, required.
        A file reference to print predictions to.
    gold_file : TextIO, required.
        A file reference to print gold labels to.
    verb_index : Optional[int], required.
        The index of the verbal predicate in the sentence which
        the gold labels are the arguments for, or None if the sentence
        contains no verbal predicate.
    sentence : List[str], required.
        The word tokens.
    prediction : List[str], required.
        The predicted BIO labels.
    gold_labels : List[str], required.
        The gold BIO labels.
    """
    warnings.warn(
        "The 'write_to_conll_eval_file' function has been deprecated in favor of "
        "the identical 'write_bio_formatted_tags_to_file' function.",
        DeprecationWarning,
    )
    write_bio_formatted_tags_to_file(
        prediction_file, gold_file, verb_index, sentence, prediction, gold_labels
    )