Packages

package merger

Ordering
  1. Alphabetic
Visibility
  1. Public
  2. All

Type Members

  1. class AssertionMerger extends AnnotatorModel[AssertionMerger] with HasSimpleAnnotate[AssertionMerger] with WhiteAndBlackListParams with AssertionPrioritizationParams

    Merges variety assertion columns coming from Assertion annotators like com.johnsnowlabs.nlp.annotators.assertion.dl.AssertionDLModel.

    Merges variety assertion columns coming from Assertion annotators like com.johnsnowlabs.nlp.annotators.assertion.dl.AssertionDLModel.

    See also

    com.johnsnowlabs.nlp.annotators.assertion.dl.AssertionDLModel AssertionMerger can filter, prioritize and merge assertion annotations by using proper parameters.

    AssertionPrioritizationParams

    WhiteAndBlackListParams

    Example

    val document_assembler = new DocumentAssembler()
     .setInputCol("text").setOutputCol("document")
    val sentence_detector = SentenceDetectorDLModel.pretrained("sentence_detector_dl_healthcare", "en", "clinical/models")
     .setInputCols(Array("document")).setOutputCol("sentence")
    val tokenizer = new Tokenizer()
     .setInputCols(Array("sentence")).setOutputCol("token")
    val word_embeddings = WordEmbeddingsModel.pretrained("embeddings_clinical", "en", "clinical/models")
     .setInputCols(Array("sentence", "token")).setOutputCol("embeddings")
    val ner_model = MedicalNerModel.pretrained("ner_opioid", "en", "clinical/models")
     .setInputCols(Array("sentence", "token", "embeddings")).setOutputCol("ner")
    val ner_converter = new NerConverterInternal()
     .setInputCols(Array("sentence", "token", "ner")).setOutputCol("ner_chunk")
     .setWhiteList(Array("opioid_drug", "other_drug"))
    val assertion = AssertionDLModel.pretrained("assertion_opioid_drug_status_wip", "en", "clinical/models")
     .setInputCols(Array("sentence", "ner_chunk", "embeddings")).setOutputCol("assertion")
    val assertion2 = AssertionDLModel.pretrained("assertion_opioid_wip", "en", "clinical/models")
     .setInputCols(Array("sentence", "ner_chunk", "embeddings")).setOutputCol("assertion2")
    
    val assertion_merger = new AssertionMerger()
     .setInputCols("assertion", "assertion2")
     .setOutputCol("assertion_merger")
     .setMergeOverlapping(true)
     .setSelectionStrategy("Sequential")
     .setAssertionSourcePrecedence("assertion2,assertion")
     .setBlackList(Array("HYPothetical"))
     .setCaseSensitive(false)
     .setAssertionsConfidence(Map("history" -> 0.80f))
     .setOrderingFeatures(Array("length", "source", "confidence"))
    
    val pipeline = new Pipeline().setStages(Array(document_assembler,
     sentence_detector,
     tokenizer,
     word_embeddings,
     ner_model,
     ner_converter,
     assertion,
     assertion2,
     assertion_merger))
    
    val data = Seq("""The patient presented to the hospital for a neurological evaluation, with a documented prescription for Percocet to manage chronic back pain. Assessment revealed ongoing discomfort localized to the lumbar region, with associated numbness and tingling in the lower extremities.""",
     """The patient, with a known history of hypertension managed with atenolol 50mg and verapamil 40mg, presented after a fall resulting in an ankle injury. Examination revealed swelling and tenderness, indicative of a twisted ankle. Considering the patient's medical history and pain management needs, a prescription for tramadol was provided to alleviate discomfort while ensuring minimal impact on blood pressure control.""",
     """The patient presented to the rehabilitation facility with a documented history of opioid abuse, primarily stemming from misuse of prescription percocet pills intended for their partner's use. Initial assessment revealed withdrawal symptoms consistent with opioid dependency, including agitation, diaphoresis, and myalgias.""",
     """The patient presented to the emergency department following an overdose on cocaine. On examination, the patient displayed signs of sympathetic nervous system stimulation, including tachycardia, hypertension, dilated pupils, and agitation.""",
     """The patient, with a documented history of chronic pain syndrome, was admitted following an accidental overdose of prescribed OxyContin. Upon assessment, the patient displayed symptoms indicative of opioid toxicity, including respiratory depression, altered mental status, and pinpoint pupils. Immediate resuscitative measures were undertaken, including airway management, administration of naloxone, and close monitoring of vital signs.""")
    .toDF("text")

    Show results

     val resultDF = pipeline.fit(data).transform(data)
     resultDF.selectExpr("explode(assertion_merger) as merger").show(false)
    +---------------------------------------------------------------------------------------------------------------------+
    |merger                                                                                                               |
    +---------------------------------------------------------------------------------------------------------------------+
    |{assertion, 104, 111, present, {sentence -> 0, chunk -> 0, assertion_source -> assertion2, confidence -> 0.9802}, []}|
    |{assertion, 63, 70, history, {sentence -> 0, chunk -> 0, assertion_source -> assertion2, confidence -> 0.8833}, []}  |
    |{assertion, 143, 150, present, {sentence -> 0, chunk -> 1, assertion_source -> assertion2, confidence -> 0.905}, []} |
    |{assertion, 256, 261, present, {sentence -> 1, chunk -> 2, assertion_source -> assertion2, confidence -> 0.5283}, []}|
    |{assertion, 75, 81, present, {sentence -> 0, chunk -> 0, assertion_source -> assertion2, confidence -> 0.6853}, []}  |
    |{assertion, 125, 133, present, {sentence -> 0, chunk -> 0, assertion_source -> assertion2, confidence -> 0.5923}, []}|
    |{assertion, 198, 203, present, {sentence -> 1, chunk -> 1, assertion_source -> assertion2, confidence -> 0.8479}, []}|
    +---------------------------------------------------------------------------------------------------------------------+
  2. trait AssertionPrioritizationParams extends Params

Value Members

  1. object AssertionMerger extends ParamsAndFeaturesReadable[AssertionMerger] with Serializable

    This is the companion object of AssertionMerger.

    This is the companion object of AssertionMerger. Please refer to that class for the documentation.

  2. object AssertionOrderingFeatures

    Assertion ordering features to use prioritization in AssertionMerger

Ungrouped