Packages

  • package root
    Definition Classes
    root
  • package com
    Definition Classes
    root
  • package johnsnowlabs
    Definition Classes
    com
  • package nlp
    Definition Classes
    johnsnowlabs
  • package annotators
    Definition Classes
    nlp
  • package merge
    Definition Classes
    annotators
  • class REChunkMerger extends AnnotatorModel[REChunkMerger] with HasSimpleAnnotate[REChunkMerger]

    REChunkMerger annotator merges relation chunks to create a new chunk.

    REChunkMerger annotator merges relation chunks to create a new chunk.

    Example

    val documentAssembler = new DocumentAssembler()
       .setInputCol("text")
       .setOutputCol("document")
    
    val tokenizer = new Tokenizer()
       .setInputCols(Array("document"))
       .setOutputCol("tokens")
    
    val sentencer = new SentenceDetector()
       .setInputCols(Array("document"))
       .setOutputCol("sentences")
    
    val embedder = WordEmbeddingsModel
       .pretrained("embeddings_clinical", "en", "clinical/models")
       .setInputCols(Array("document", "tokens"))
       .setOutputCol("embeddings")
    
    val posTagger = PerceptronModel
       .pretrained("pos_clinical", "en", "clinical/models")
       .setInputCols(Array("sentences", "tokens"))
       .setOutputCol("posTags")
    
    val nerTagger = MedicalNerModel
       .pretrained("ner_clinical", "en", "clinical/models")
       .setInputCols(Array("sentences", "tokens", "embeddings"))
       .setOutputCol("nerTags")
    
    val nerConverter = new NerConverterInternal()
       .setInputCols(Array("sentences", "tokens", "nerTags"))
       .setOutputCol("nerChunks")
    
    val depencyParser = DependencyParserModel
       .pretrained("dependency_conllu", "en")
       .setInputCols(Array("document", "posTags", "tokens"))
       .setOutputCol("dependencies")
    
    val re = RelationExtractionModel
       .pretrained("re_clinical", "en", "clinical/models")
       .setInputCols(Array("embeddings", "posTags", "nerChunks", "dependencies"))
       .setOutputCol("relations_t")
    
    val REChunkMerger = new REChunkMerger()
       .setInputCols("relations_t")
       .setOutputCol("relation_chunk")
       .setSeparator(" & ")
    
    val flattener = new Flattener()
       .setInputCols("relation_chunk")
       .setExplodeSelectedFields(Map("relation_chunk" -> Array(
                                     "result as result",
                                     "begin as begin",
                                     "end as end",
                                     "metadata.relation_type as relationType",
                                     "metadata.sentence as sentence"
      )))
    
    val pipeline = new Pipeline()
       .setStages(Array(
           documentAssembler,
           sentencer,
           tokenizer,
           embedder,
           posTagger,
           nerTagger,
           nerConverter,
           depencyParser,
           re,
           REChunkMerger,
           flattener
       ))
    
    import spark.implicits._
    
    val data = Seq("A 28-year-old female with a history of gestational diabetes mellitus diagnosed eight years prior to " +
     "presentation and subsequent type two diabetes mellitus ( T2DM ). one prior episode of HTG-induced pancreatitis " +
     "three years prior to presentation , associated with an acute hepatitis , and obesity with a body mass index ")
       .toDS()
       .toDF("text")
    
    val result = pipeline.fit(data).transform(data)

    Show Results

    +---------------------------------------------------------------------+-----+---+------------+--------+
    |result                                                               |begin|end|relationType|sentence|
    +---------------------------------------------------------------------+-----+---+------------+--------+
    |gestational diabetes mellitus & subsequent type two diabetes mellitus|39   |153|TeRP        |0       |
    |gestational diabetes mellitus & T2DM                                 |39   |160|TeRP        |0       |
    |subsequent type two diabetes mellitus & T2DM                         |117  |160|TeRP        |0       |
    +---------------------------------------------------------------------+-----+---+------------+--------+
    Definition Classes
    merge
  • MetadataKey

implicit class MetadataKey extends AnyRef

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. MetadataKey
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new MetadataKey(annotation: Annotation)

Value Members

  1. def optionalMetadataKey(field: String): String
  2. def requiredMetadataKey(field: String): String