Skip to content

edsnlp.pipelines.core.context

context

ContextAdder

Bases: BaseComponent

Provides a generic context adder component.

PARAMETER DESCRIPTION
nlp

The spaCy object.

TYPE: Language

context

The list of extensions to add to the Doc

TYPE: List[str]

Source code in edsnlp/pipelines/core/context/context.py
 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
class ContextAdder(BaseComponent):
    """
    Provides a generic context adder component.

    Parameters
    ----------
    nlp : Language
        The spaCy object.
    context : List[str]
        The list of extensions to add to the `Doc`
    """

    def __init__(
        self,
        nlp: Language,
        context: List[str],
    ):

        self.nlp = nlp
        self.context = context
        self.set_extensions()

    def set_extensions(self):
        for col in self.context:
            if not Doc.has_extension(col):
                Doc.set_extension(col, default=None)

    def __call__(self, doc: Doc) -> Doc:
        return doc
nlp = nlp instance-attribute
context = context instance-attribute
__init__(nlp, context)
Source code in edsnlp/pipelines/core/context/context.py
21
22
23
24
25
26
27
28
29
def __init__(
    self,
    nlp: Language,
    context: List[str],
):

    self.nlp = nlp
    self.context = context
    self.set_extensions()
set_extensions()
Source code in edsnlp/pipelines/core/context/context.py
31
32
33
34
def set_extensions(self):
    for col in self.context:
        if not Doc.has_extension(col):
            Doc.set_extension(col, default=None)
__call__(doc)
Source code in edsnlp/pipelines/core/context/context.py
36
37
def __call__(self, doc: Doc) -> Doc:
    return doc

factory

DEFAULT_CONFIG = dict(context=['note_id']) module-attribute

create_component(nlp, name, context)

Source code in edsnlp/pipelines/core/context/factory.py
12
13
14
15
16
17
18
19
20
21
22
@Language.factory("eds.context", default_config=DEFAULT_CONFIG)
def create_component(
    nlp: Language,
    name: str,
    context: List[str],
):

    return ContextAdder(
        nlp,
        context=context,
    )
Back to top