medkit.text.spacy.displacy_utils

medkit.text.spacy.displacy_utils#

Functions:

entities_to_displacy(entities, raw_text[, ...])

Build data dict that can be passed to displacy.render() (with manual=True and style="ent") to visualize entities.

medkit_doc_to_displacy(medkit_doc[, ...])

Build data dict that can be passed to displacy.render() (with manual=True and style="ent") to visualize entities of a document.

medkit_doc_to_displacy(medkit_doc, entity_labels=None, entity_formatter=None, max_gap_length=3)[source]#

Build data dict that can be passed to displacy.render() (with manual=True and style=”ent”) to visualize entities of a document.

Parameters:
  • medkit_doc (TextDocument) – Document to visualize.

  • entity_labels (list of str, optional) – Labels of entities to display. If None, all entities are displayed.

  • entity_formatter (Callable, 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_length (int, 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().

Return type:

dict[str, Any]

Returns:

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

entities_to_displacy(entities, raw_text, entity_formatter=None, max_gap_length=3)[source]#

Build data dict that can be passed to displacy.render() (with manual=True and style=”ent”) to visualize entities.

Parameters:
  • entities (list of Entity) – Entities to visualize in text context.

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

  • entity_formatter (Callable, 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_length (int, 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().

Return type:

dict[str, Any]

Returns:

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