medkit.text.spacy.displacy_utils

medkit.text.spacy.displacy_utils#

Functions#

medkit_doc_to_displacy(→ dict[str, Any])

Build data dictionary for displaCy to visualize a document.

entities_to_displacy(→ dict[str, Any])

Build data dictionary for displaCy to visualize entities.

Module Contents#

medkit.text.spacy.displacy_utils.medkit_doc_to_displacy(medkit_doc: medkit.core.text.TextDocument, entity_labels: list[str] | None = None, entity_formatter: Callable[[medkit.core.text.Entity], str] | None = None, max_gap_length: int = 3) dict[str, Any]#

Build data dictionary for displaCy to visualize a document.

Parameters:
medkit_docTextDocument

Document to visualize.

entity_labelslist of str, optional

Labels of entities to display. If None, all entities are displayed.

entity_formatterCallable, optional

Optional function returning the text to display as label for a given entity. If None, the entity label will be used. Can be used for instance to display normalization information available in entity attributes.

max_gap_lengthint, default=3

When cleaning up gaps in spans, spans around gaps smaller than max_gap_length will be merged. Cf clean_up_gaps_in_normalized_spans().

Returns:
dict of str to Any

Data to be passed to displacy.render() as docs argument (with manual=True and style=”ent”)

medkit.text.spacy.displacy_utils.entities_to_displacy(entities: list[medkit.core.text.Entity], raw_text: str, entity_formatter: Callable[[medkit.core.text.Entity], str] | None = None, max_gap_length: int = 3) dict[str, Any]#

Build data dictionary for displaCy to visualize entities.

Parameters:
entitieslist of Entity

Entities to visualize in text context.

raw_textstr

Initial document text from which entities where extracted and to which they spans refer (typically the text attribute of a TextDocument).

entity_formatterCallable, optional

Optional function returning the text to display as label for a given entity. If None, the entity label will be used. Can be used for instance to display normalization information available in entity attributes.

max_gap_lengthint, default=3

When cleaning up gaps in spans, spans around gaps smaller than max_gap_length will be merged. Cf clean_up_gaps_in_normalized_spans().

Returns:
dict of str to Any

Data to be passed to displacy.render() as docs argument (with manual=True and style=”ent”)