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. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  6. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  10. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  11. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  14. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  15. def optionalMetadataKey(field: String): String
  16. def requiredMetadataKey(field: String): String
  17. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  18. def toString(): String
    Definition Classes
    AnyRef → Any
  19. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  20. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  21. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()

Inherited from AnyRef

Inherited from Any

Members