medkit.text.spacy.edsnlp
medkit.text.spacy.edsnlp#
This package needs extra-dependencies not installed as core dependencies of medkit. To install them, use pip install medkit[edsnlp].
Classes:
|
DocPipeline to obtain annotations created using EDS-NLP |
|
Segment annotator relying on an EDS-NLP pipeline |
Functions:
|
Build a medkit attribute from an EDS-NLP context/qualifying attribute, adding the cues as metadata |
|
Build a medkit date attribute from an EDS-NLP attribute with a date object as value. |
|
Build a medkit attribute from an EDS-NLP "history" attribute, adding the cues as metadata |
|
Build a medkit attribute from an EDS-NLP "score_name" and corresponding "score_value" attribute. |
|
Build a medkit attribute from an EDS-NLP "value" attribute with a custom object as value: |
Data:
Pre-defined attribute factories to handle EDS-NLP attributes |
- class EDSNLPPipeline(nlp, spacy_entities=None, spacy_span_groups=None, spacy_attrs=None, medkit_attribute_factories=None, name=None, uid=None)[source]#
Segment annotator relying on an EDS-NLP pipeline
Initialize the segment annotator
- Parameters
nlp (
Language) – Language object with the loaded pipeline from Spacyspacy_entities (
Optional[List[str]]) – Labels of new spacy entities (doc.ents) to convert into medkit entities. If None (default) all the new spacy entities will be convertedspacy_span_groups (
Optional[List[str]]) – Name of new spacy span groups (doc.spans) to convert into medkit segments. If None (default) new spacy span groups will be convertedspacy_attrs (
Optional[List[str]]) – Name of span extensions to convert into medkit attributes. If None, all non-redundant EDS-NLP attributes will be handled.medkit_attribute_factories (
Optional[Dict[str,Callable[[Span,str],Attribute]]]) – Mapping of factories in charge of converting spacy attributes to medkit attributes. Factories will receive a spacy span and an an attribute label when called. The key in the mapping is the attribute label. Pre-defined default factories are listed inDEFAULT_ATTRIBUTE_FACTORIESname (
Optional[str]) – Name describing the pipeline (defaults to the class name).uid (str) – Identifier of the pipeline
- class EDSNLPDocPipeline(nlp, medkit_labels_anns=None, medkit_attrs=None, spacy_entities=None, spacy_span_groups=None, spacy_attrs=None, medkit_attribute_factories=None, name=None, uid=None)[source]#
DocPipeline to obtain annotations created using EDS-NLP
Initialize the pipeline
- Parameters
nlp (
Language) – Language object with the loaded pipeline from Spacymedkit_labels_anns (
Optional[List[str]]) – Labels of medkit annotations to include in the spacy document. If None (default) all the annotations will be included.medkit_attrs (
Optional[List[str]]) – Labels of medkit attributes to add in the annotations that will be included. If None (default) all the attributes will be added as custom attributes in each annotation included.spacy_entities (
Optional[List[str]]) – Labels of new spacy entities (doc.ents) to convert into medkit entities. If None (default) all the new spacy entities will be converted and added into its origin medkit document.spacy_span_groups (
Optional[List[str]]) – Name of new spacy span groups (doc.spans) to convert into medkit segments. If None (default) new spacy span groups will be converted and added into its origin medkit document.spacy_attrs (
Optional[List[str]]) – Name of span extensions to convert into medkit attributes. If None, all non-redundant EDS-NLP attributes will be handled.medkit_attribute_factories (
Optional[Dict[str,Callable[[Span,str],Attribute]]]) – Mapping of factories in charge of converting spacy attributes to medkit attributes. Factories will receive a spacy span and an an attribute label when called. The key in the mapping is the attribute label. Pre-defined default factories are listed inDEFAULT_ATTRIBUTE_FACTORIESname (
Optional[str]) – Name describing the pipeline (defaults to the class name).uid (str) – Identifier of the pipeline
- build_date_attribute(spacy_span, spacy_label)[source]#
Build a medkit date attribute from an EDS-NLP attribute with a date object as value.
- Parameters
spacy_span (
Span) – Spacy span having an ESD-NLP date attributespacy_label (
str) – Label of the date attribute on spacy_spacy. Ex: “date”, “consultation_date”
- Return type
- Returns
Attribute –
DateAttribute,RelativeDateAttributeorDurationAttributeinstance, depending on the EDS-NLP attribute
- build_value_attribute(spacy_span, spacy_label)[source]#
Build a medkit attribute from an EDS-NLP “value” attribute with a custom object as value:
if the value is an EDS-NLP Adipcap object, a
ADICAPNormAttributeinstance is returned;if the value is an EDS-NLP TNN object, a
TNMAttributeinstance is returned;if the value is an EDS-NLP SimpleMeasurement object, a
Attributeinstance is returned.
Otherwise an error is raised.
- Parameters
spacy_span (
Span) – Spacy span having an attribute custom object as valuespacy_label (
str) – Label of the attribute on spacy_spacy. Ex: “value”
- Return type
- Returns
Attribute – Medkit attribute corresponding to the spacy attribute value
- build_score_attribute(spacy_span, spacy_label)[source]#
Build a medkit attribute from an EDS-NLP “score_name” and corresponding “score_value” attribute.
- Parameters
spacy_span (
Span) – Spacy span having “score_name” and “score_value” attributesspacy_label (
str) – Must be “score_name”
- Return type
- Returns
Attribute – Medkit attribute with “score_name” value as label and “score_value” value as value
- build_context_attribute(spacy_span, spacy_label)[source]#
Build a medkit attribute from an EDS-NLP context/qualifying attribute, adding the cues as metadata
- Parameters
spacy_span (
Span) – Spacy span having a context/qualifying attributespacy_label (
str) – Label of the attribute on spacy_spacy. Ex: “negation”, “hypothesis”, etc
- Return type
- Returns
Attribute – Medkit attribute corresponding to the spacy attribute
- build_history_attribute(spacy_span, spacy_label)[source]#
Build a medkit attribute from an EDS-NLP “history” attribute, adding the cues as metadata
- Parameters
spacy_span (
Span) – Spacy span having a “history” attributespacy_label (
str) – Must be “history”
- Return type
- Returns
Attribute – Medkit attribute corresponding to the spacy attribute
- DEFAULT_ATTRIBUTE_FACTORIES = {'consultation_date': <function build_date_attribute>, 'date': <function build_date_attribute>, 'family': <function build_context_attribute>, 'history': <function build_history_attribute>, 'hypothesis': <function build_context_attribute>, 'negation': <function build_context_attribute>, 'reported_speech': <function build_context_attribute>, 'score_name': <function build_score_attribute>, 'value': <function build_value_attribute>}#
Pre-defined attribute factories to handle EDS-NLP attributes