Skip to content

medspacy.context.util

This module will contain helper functions and classes for common clinical processing tasks which will be used in medspaCy's context implementation.

is_modified_by(span, modifier_label)

Check whether a span has a modifier of a specific type.

Parameters:

Name Type Description Default
span Span

The span to examine.

required
modifier_label str

The type of modifier to check for.

required

Returns:

Type Description
bool

Whether there is a modifier of modifier_label that modifies span.

Source code in medspacy/context/util.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def is_modified_by(span: Span, modifier_label: str) -> bool:
    """
    Check whether a span has a modifier of a specific type.

    Args:
        span: The span to examine.
        modifier_label: The type of modifier to check for.

    Returns:
        Whether there is a modifier of `modifier_label` that modifies `span`.
    """
    for modifier in span._.modifiers:
        if modifier.category.upper() == modifier_label.upper():
            return True
    return False