Skip to content

MultiLabelEntry

labl.data.base_sequence.BaseMultiLabelEntry

BaseMultiLabelEntry(
    iterable: Iterable[LabeledObject] | None = None,
    *,
    info: InfoDictType = {},
)

Bases: BaseLabeledSequence[EntryType], ABC

Class for a list of EntryType objects representing multiple labels over the same text.

Source code in labl/data/base_sequence.py
def __init__(self, iterable: Iterable[LabeledObject] | None = None, *, info: InfoDictType = {}):
    if iterable is None:
        super().__init__()
    else:
        super().__init__(iterable)
    self._label_types = self._get_label_types()
    self._info = info

label_counts property

label_counts: list[int]

Counts the number of labels for each token in the original text.

tokens_with_label_counts property

tokens_with_label_counts: LabeledTokenList

Returns a list of LabeledToken with the number of labels for each token in the original text.

get_agreement

get_agreement(
    level_of_measurement: LevelOfMeasurement | None = None,
) -> AgreementOutput

Compute the inter-annotator agreement for the token labels of all label sets using Krippendorff's alpha.

Source code in labl/data/base_sequence.py
def get_agreement(
    self,
    level_of_measurement: LevelOfMeasurement | None = None,
) -> AgreementOutput:
    """Compute the inter-annotator agreement for the token labels of all label sets using
    [Krippendorff's alpha](https://en.wikipedia.org/wiki/Krippendorff%27s_alpha).
    """
    self._validate_single_label_type()
    labels_array = self._get_labels_array(dtype=self.label_types[0])
    return get_labels_agreement(
        label_type=self.label_types[0],
        labels_array=labels_array,
        level_of_measurement=level_of_measurement,
    )

labl.data.labeled_entry.MultiLabelEntry

MultiLabelEntry(
    iterable: Iterable[LabeledObject] | None = None,
    *,
    info: InfoDictType = {},
)

Bases: BaseMultiLabelEntry[LabeledEntry]

Class for a list of LabeledEntry representing multiple labels over the same text.

Source code in labl/data/base_sequence.py
def __init__(self, iterable: Iterable[LabeledObject] | None = None, *, info: InfoDictType = {}):
    if iterable is None:
        super().__init__()
    else:
        super().__init__(iterable)
    self._label_types = self._get_label_types()
    self._info = info

labl.data.edited_entry.MultiEditEntry

MultiEditEntry(
    iterable: Iterable[LabeledObject] | None = None,
    *,
    info: InfoDictType = {},
)

Bases: BaseMultiLabelEntry[EditedEntry]

Class for a list of EditedEntry representing multiple edits over the same orig text.

Source code in labl/data/base_sequence.py
def __init__(self, iterable: Iterable[LabeledObject] | None = None, *, info: InfoDictType = {}):
    if iterable is None:
        super().__init__()
    else:
        super().__init__(iterable)
    self._label_types = self._get_label_types()
    self._info = info

merge_gap_annotations

merge_gap_annotations(
    merge_fn: Callable[[Sequence[LabelType]], LabelType]
    | None = None,
    keep_final_gap: bool = True,
) -> None

Merge gap annotations in the tokens of orig and edit.

This method is equivalent to calling EditedEntry.from_edits with with_gaps=False. Gap annotations are merged to the next non-gap token to the right, and the gap label is added to the label of the non-gap token. The last gap is kept to account for insertions at the end of the text.

E.g. GAP Hello GAP World GAP ! GAP becomes Hello World ! GAP. I S I I IS I I

Source code in labl/data/edited_entry.py
def merge_gap_annotations(
    self,
    merge_fn: Callable[[Sequence[LabelType]], LabelType] | None = None,
    keep_final_gap: bool = True,
) -> None:
    """Merge gap annotations in the tokens of `orig` and `edit`.

    This method is equivalent to calling `EditedEntry.from_edits` with `with_gaps=False`. Gap annotations are merged
    to the next non-gap token to the right, and the gap label is added to the label of the non-gap token. The last
    gap is kept to account for insertions at the end of the text.

    E.g. `GAP Hello GAP World GAP ! GAP` becomes `Hello World ! GAP`.
         `  I     S   I               I`         `   IS     I     I`
    """
    for entry in self:
        entry.merge_gap_annotations(merge_fn=merge_fn, keep_final_gap=keep_final_gap)