Skip to content

medspacy.postprocess.postprocessing_pattern

PostprocessingPattern

PostprocessingPatterns are callable functions and equality values wrapped together that will create triggers in the later Postprocessor as part of PostprocessingRules.

Source code in medspacy/postprocess/postprocessing_pattern.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class PostprocessingPattern:
    """
    PostprocessingPatterns are callable functions and equality values wrapped together that will create triggers
    in the later Postprocessor as part of PostprocessingRules.
    """

    def __init__(self, condition: Callable, success_value: Any = True, **kwargs):
        """
        A PostprocessingPattern defines a single condition to check against an entity.

        Args:
            condition: A function to call on an entity. If the result of the function call equals success_value, then
                the pattern passes.
            success_value: The value which should be returned by condition(ent) in order for the pattern to pass. Must
                have == defined for condition(ent) == success_value.
            kwargs: Optional keyword arguments to call with condition(ent, **kwargs).
        """
        self.condition = condition
        self.success_value = success_value
        self.kwargs = kwargs

    def __call__(self, ent: Span) -> bool:
        """
        Call the PostprocessingPattern on the span specified.

        Args:
            ent: the span to process.

        Returns:
            Whether calling `condition` on the entity specified is `success_value`.
        """
        if self.kwargs:
            result = self.condition(ent, **self.kwargs)
        else:
            result = self.condition(ent)
        return result == self.success_value

__call__(ent)

Call the PostprocessingPattern on the span specified.

Parameters:

Name Type Description Default
ent Span

the span to process.

required

Returns:

Type Description
bool

Whether calling condition on the entity specified is success_value.

Source code in medspacy/postprocess/postprocessing_pattern.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
def __call__(self, ent: Span) -> bool:
    """
    Call the PostprocessingPattern on the span specified.

    Args:
        ent: the span to process.

    Returns:
        Whether calling `condition` on the entity specified is `success_value`.
    """
    if self.kwargs:
        result = self.condition(ent, **self.kwargs)
    else:
        result = self.condition(ent)
    return result == self.success_value

__init__(condition, success_value=True, **kwargs)

A PostprocessingPattern defines a single condition to check against an entity.

Parameters:

Name Type Description Default
condition Callable

A function to call on an entity. If the result of the function call equals success_value, then the pattern passes.

required
success_value Any

The value which should be returned by condition(ent) in order for the pattern to pass. Must have == defined for condition(ent) == success_value.

True
kwargs

Optional keyword arguments to call with condition(ent, **kwargs).

{}
Source code in medspacy/postprocess/postprocessing_pattern.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def __init__(self, condition: Callable, success_value: Any = True, **kwargs):
    """
    A PostprocessingPattern defines a single condition to check against an entity.

    Args:
        condition: A function to call on an entity. If the result of the function call equals success_value, then
            the pattern passes.
        success_value: The value which should be returned by condition(ent) in order for the pattern to pass. Must
            have == defined for condition(ent) == success_value.
        kwargs: Optional keyword arguments to call with condition(ent, **kwargs).
    """
    self.condition = condition
    self.success_value = success_value
    self.kwargs = kwargs