zensols.clinicamr package¶
Submodules¶
zensols.clinicamr.adm module¶
Classes used to parse the clinical corpus into an annotated AMR corpus.
- class zensols.clinicamr.adm.AdmissionAmrFactoryStash(corpus, amr_annotator, keep_notes, keep_summary_sections)[source]¶
Bases:
ReadOnlyStashA stash that CRUDs instances of
AdmissionAmrFeatureDocument.- __init__(corpus, amr_annotator, keep_notes, keep_summary_sections)¶
-
amr_annotator:
AnnotationFeatureDocumentParser¶ Parses, populates and caches AMR graphs in feature documents.
- exists(name)[source]¶
Return
Trueif data with keynameexists.Implementation note: This
Stash.exists()method is very inefficient and should be overriden.- Return type:
-
keep_notes:
Union[List[str],Set[str]]¶ The note (by category) to keep in each clinical note. The rest are filtered.
-
keep_summary_sections:
Union[List[str],Set[str]]¶ The sections to keep in each clinical note. The rest are filtered.
zensols.clinicamr.app module¶
Clincial Domain Abstract Meaning Representation Graphs
- class zensols.clinicamr.app.Application(config_factory, doc_parser, adm_amr_stash, dumper)[source]¶
Bases:
objectClincial Domain Abstract Meaning Representation Graphs.
- __init__(config_factory, doc_parser, adm_amr_stash, dumper)¶
- adm_amr_stash: Stash¶
A stash that CRUDs instances of
AdmissionAmrFeatureDocument.
- config_factory: ConfigFactory¶
For creating app config resources.
- doc_parser: FeatureDocumentParser¶
The document parser used for the
parse()action.
- dumper: Dumper¶
Plots and writes AMR content in human readable formats.
zensols.clinicamr.cli module¶
Command line entry point to the application.
- class zensols.clinicamr.cli.ApplicationFactory(*args, **kwargs)[source]¶
Bases:
ApplicationFactory
zensols.clinicamr.decorator module¶
Adds concept unique identifiers to the graph.
- class zensols.clinicamr.decorator.ClinicTokenAnnotationFeatureDocumentDecorator(name, feature_id, indexed=False, add_none=False, use_sent_index=True, method='attribute', feature_format='[{cui_}]: {pref_name_} ({tui_descs_})')[source]¶
Bases:
TokenAnnotationFeatureDocumentDecoratorOverride token feature annotation by adding CUI data.
- __init__(name, feature_id, indexed=False, add_none=False, use_sent_index=True, method='attribute', feature_format='[{cui_}]: {pref_name_} ({tui_descs_})')¶
zensols.clinicamr.domain module¶
Object graph classes for EHR notes.
- class zensols.clinicamr.domain.AdmissionAmrFeatureDocument(sents, text=None, spacy_doc=None, amr=None, coreference_relations=None, hadm_id=None, _ds_ix=None, _ant_ixs=None, parse_fails=None)[source]¶
Bases:
AmrFeatureDocumentAn AMR feature document whose
sentsconsist of all parsed sentences of all notes of an admission.- __init__(sents, text=None, spacy_doc=None, amr=None, coreference_relations=None, hadm_id=None, _ds_ix=None, _ant_ixs=None, parse_fails=None)¶
- clone(cls=None, **kwargs)[source]¶
- Parameters:
kwargs – if copy_spacy is
True, the spacy document is copied to the clone in addition parameters passed to new clone initializer- Return type:
-
parse_fails:
Tuple[ParseFailure,...] = None¶ Sentences who have parsed features, but the AMR parse failed.
- write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Write the document and optionally sentence features.
- Parameters:
n_sents – the number of sentences to write
n_tokens – the number of tokens to print across all sentences
include_original – whether to include the original text
include_normalized – whether to include the normalized text
- exception zensols.clinicamr.domain.ClinicAmrError[source]¶
Bases:
APIErrorRaised for this package’s API errors.
- __module__ = 'zensols.clinicamr.domain'¶
- class zensols.clinicamr.domain.NoteDocument(sents, note_ix)[source]¶
Bases:
_IndexedDocumentAn index container class that creates AMR clinical note documents.
- write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Write the contents of this instance to
writerusing indentiondepth.- Parameters:
depth (
int) – the starting indentation depthwriter (
TextIOBase) – the writer to dump the content of this writable
- class zensols.clinicamr.domain.ParseFailure(row_id, sec_id, sec_name, para_idx, sent)[source]¶
Bases:
WritableA container class for sentences who have parsed features, but the AMR parse failed.
- __init__(row_id, sec_id, sec_name, para_idx, sent)¶
-
sent:
AmrFeatureSentence¶ The AMR sentence.
- See:
is_failure
- write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Write the contents of this instance to
writerusing indentiondepth.- Parameters:
depth (
int) – the starting indentation depthwriter (
TextIOBase) – the writer to dump the content of this writable
- class zensols.clinicamr.domain.SectionDocument(sents, sec_ix)[source]¶
Bases:
_IndexedDocumentAn index container class that creates AMR paragraph documents.
- create_paragraphs()[source]¶
Return the paragraph documents of this section.
- Return type:
Iterable[AmrFeatureDocument]
- write(depth=0, writer=<_io.TextIOWrapper name='<stdout>' mode='w' encoding='utf-8'>)[source]¶
Write the contents of this instance to
writerusing indentiondepth.- Parameters:
depth (
int) – the starting indentation depthwriter (
TextIOBase) – the writer to dump the content of this writable
zensols.clinicamr.parafac module¶
Parse clinical medical note paragraph AMR graphs and cache using a
Stash.
- class zensols.clinicamr.parafac.ClinicAmrParagraphFactory(delegate, amr_annotator, stash, document_decorators=(), sentence_decorators=(), id_format='MIMIC3_{note_id}_{sec_id}_{para_id}.{sent_id}', add_is_header=True, remove_empty_sentences=True)[source]¶
Bases:
ParagraphFactoryParse paragraph AMR graphs by using the the
delegateparagraph factory. Then each document is given an AMR graph using aAmrDocumentat the document level and aAmrSentenceat the sentence level, which are cached using aStash.A list of
AmrFeatureDocumentare returned.- __init__(delegate, amr_annotator, stash, document_decorators=(), sentence_decorators=(), id_format='MIMIC3_{note_id}_{sec_id}_{para_id}.{sent_id}', add_is_header=True, remove_empty_sentences=True)¶
-
add_is_header:
bool= True¶ Whether or not to add the
is_headerAMR metadata indicating if the sentence is part of one of the section headers.
-
amr_annotator:
AnnotationFeatureDocumentParser¶ Parses, populates and caches AMR graphs in feature documents.
-
delegate:
ParagraphFactory¶ The paragraph factory that chunks the paragraphs.
-
document_decorators:
Sequence[FeatureDocumentDecorator] = ()¶ A list of decorators that can add, remove or modify features on a document.
-
id_format:
str= 'MIMIC3_{note_id}_{sec_id}_{para_id}.{sent_id}'¶ Whether to add the
idAMR metadata field if it does not already exist.
-
remove_empty_sentences:
bool= True¶ Whether to remove empty sentences from paragraphs. If
Trueempty paragraphs are skipped.
-
sentence_decorators:
Sequence[FeatureSentenceDecorator] = ()¶ A list of decorators that can add, remove or modify features on a document.
zensols.clinicamr.proto module¶
Prototyping module.
zensols.clinicamr.spring module¶
Use the paper implementation of the SPRING parser.
- class zensols.clinicamr.spring.SpringAmrParser(model='noop', add_missing_metadata=True, client=None, doc_parser=None)[source]¶
Bases:
AmrParserAdapt the
zensols.amrspringclient to azensols.amr.model.AmrParser. This is to allow us to use the clinical notes trained THYME parser.Citation:
Bevilacqua et al. (2021) One SPRING to Rule Them Both: Symmetric AMR Semantic Parsing and Generation without a Complex Pipeline. In Proceedings of the AAAI Conference on Artificial Intelligence, volume 35, pages 12564–12573, Virtual, May.
- __init__(model='noop', add_missing_metadata=True, client=None, doc_parser=None)¶
-
client:
AmrParseClient= None¶
-
doc_parser:
FeatureDocumentParser= None¶