Packages

c

com.johnsnowlabs.nlp.annotators.merge

ChunkMergeApproach

class ChunkMergeApproach extends AnnotatorApproach[ChunkMergeModel] with CheckLicense

Merges two chunk columns coming from two annotators(NER, ContextualParser or any other annotator producing chunks). The merger of the two chunk columns is made by selecting one chunk from one of the columns according to certain criteria. The decision on which chunk to select is made according to the chunk indices in the source document. (chunks with longer lengths and highest information will be kept from each source) Labels can be changed by setReplaceDictResource.

Example

Define a pipeline with 2 different NER models with a ChunkMergeApproach at the end

val data = Seq(("A 63-year-old man presents to the hospital ...")).toDF("text")
val pipeline = new Pipeline().setStages(Array(
  new DocumentAssembler().setInputCol("text").setOutputCol("document"),
  new SentenceDetector().setInputCols("document").setOutputCol("sentence"),
  new Tokenizer().setInputCols("sentence").setOutputCol("token"),
  WordEmbeddingsModel.pretrained("embeddings_clinical", "en", "clinical/models").setOutputCol("embs"),
  MedicalNerModel.pretrained("ner_jsl", "en", "clinical/models")
    .setInputCols("sentence", "token", "embs").setOutputCol("jsl_ner"),
  new NerConverter().setInputCols("sentence", "token", "jsl_ner").setOutputCol("jsl_ner_chunk"),
  MedicalNerModel.pretrained("ner_bionlp", "en", "clinical/models")
    .setInputCols("sentence", "token", "embs").setOutputCol("bionlp_ner"),
  new NerConverter().setInputCols("sentence", "token", "bionlp_ner")
    .setOutputCol("bionlp_ner_chunk"),
  new ChunkMergeApproach().setInputCols("jsl_ner_chunk", "bionlp_ner_chunk").setOutputCol("merged_chunk")
))

Show results

val result = pipeline.fit(data).transform(data).cache()
result.selectExpr("explode(merged_chunk) as a")
  .selectExpr("a.begin","a.end","a.result as chunk","a.metadata.entity as entity")
  .show(5, false)
+-----+---+-----------+---------+
|begin|end|chunk      |entity   |
+-----+---+-----------+---------+
|5    |15 |63-year-old|Age      |
|17   |19 |man        |Gender   |
|64   |72 |recurrent  |Modifier |
|98   |107|cellulitis |Diagnosis|
|110  |119|pneumonias |Diagnosis|
+-----+---+-----------+---------+
Linear Supertypes
CheckLicense, AnnotatorApproach[ChunkMergeModel], CanBeLazy, DefaultParamsWritable, MLWritable, HasOutputAnnotatorType, HasOutputAnnotationCol, HasInputAnnotationCols, Estimator[ChunkMergeModel], PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. ChunkMergeApproach
  2. CheckLicense
  3. AnnotatorApproach
  4. CanBeLazy
  5. DefaultParamsWritable
  6. MLWritable
  7. HasOutputAnnotatorType
  8. HasOutputAnnotationCol
  9. HasInputAnnotationCols
  10. Estimator
  11. PipelineStage
  12. Logging
  13. Params
  14. Serializable
  15. Serializable
  16. Identifiable
  17. AnyRef
  18. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new ChunkMergeApproach()
  2. new ChunkMergeApproach(uid: String)

    uid

    a unique identifier for the instantiated AnnotatorModel

Type Members

  1. type AnnotatorType = String
    Definition Classes
    HasOutputAnnotatorType

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def $[T](param: Param[T]): T
    Attributes
    protected
    Definition Classes
    Params
  4. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  5. def _fit(dataset: Dataset[_], recursiveStages: Option[PipelineModel]): ChunkMergeModel
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def beforeTraining(spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  8. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  9. def checkValidEnvironment(spark: Option[SparkContext]): Unit
    Definition Classes
    CheckLicense
  10. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  11. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkContext], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  12. val chunkPrecedence: Param[String]

    Select what is the priorization when two chunks have the same start and end indices.Possibles values [entity|identifier|field]

  13. final def clear(param: Param[_]): ChunkMergeApproach.this.type
    Definition Classes
    Params
  14. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  15. final def copy(extra: ParamMap): Estimator[ChunkMergeModel]
    Definition Classes
    AnnotatorApproach → Estimator → PipelineStage → Params
  16. def copyValues[T <: Params](to: T, extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  17. final def defaultCopy[T <: Params](extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  18. val description: String
    Definition Classes
    ChunkMergeApproach → AnnotatorApproach
  19. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  20. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  21. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  22. def explainParams(): String
    Definition Classes
    Params
  23. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  24. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  25. val falsePositivesResource: ExternalResourceParam

    Path to csv with false positive text, entity pairs to remove

  26. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  27. final def fit(dataset: Dataset[_]): ChunkMergeModel
    Definition Classes
    AnnotatorApproach → Estimator
  28. def fit(dataset: Dataset[_], paramMaps: Array[ParamMap]): Seq[ChunkMergeModel]
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  29. def fit(dataset: Dataset[_], paramMap: ParamMap): ChunkMergeModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" )
  30. def fit(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): ChunkMergeModel
    Definition Classes
    Estimator
    Annotations
    @Since( "2.0.0" ) @varargs()
  31. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  32. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  33. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  34. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  35. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  36. def getMergeOverlapping: Boolean
  37. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  38. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  39. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  40. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  41. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  42. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  43. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  44. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  45. val inputAnnotatorTypes: Array[AnnotatorType]

    Output annotator types: CHUNK, CHUNK

    Output annotator types: CHUNK, CHUNK

    Definition Classes
    ChunkMergeApproach → HasInputAnnotationCols
  46. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  47. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  48. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  49. def isLp(): Boolean
    Definition Classes
    CheckLicense
  50. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  51. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  52. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  53. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  54. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  55. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  56. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  57. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  58. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  59. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  60. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  61. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  62. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  63. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  64. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  65. val mergeOverlapping: BooleanParam

    whether to merge overlapping matched chunks.

    whether to merge overlapping matched chunks. Defaults to true

  66. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  67. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  68. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  69. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  70. def onTrained(model: ChunkMergeModel, spark: SparkSession): Unit
    Definition Classes
    AnnotatorApproach
  71. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  72. val outputAnnotatorType: AnnotatorType

    Input annotator types: CHUNK

    Input annotator types: CHUNK

    Definition Classes
    ChunkMergeApproach → HasOutputAnnotatorType
  73. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  74. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  75. val replaceDictResource: ExternalResourceParam

    dictionary with regular expression patterns that match some protected entity TODO: is this regex?

  76. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  77. final def set(paramPair: ParamPair[_]): ChunkMergeApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  78. final def set(param: String, value: Any): ChunkMergeApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  79. final def set[T](param: Param[T], value: T): ChunkMergeApproach.this.type
    Definition Classes
    Params
  80. def setChunkPrecedence(m: String): ChunkMergeApproach.this.type

    Select what is the priorization when one chunk has the same start and end chunk.Possibles values [entity|identifier|field]

  81. final def setDefault(paramPairs: ParamPair[_]*): ChunkMergeApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  82. final def setDefault[T](param: Param[T], value: T): ChunkMergeApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  83. def setFalsePositivesResource(path: String, readAs: Format = ReadAs.TEXT, options: Map[String, String] = Map("delimiter" -> ",")): ChunkMergeApproach.this.type

    Path to csv with false positive text, entity pairs to remove

  84. def setFalsePositivesResource(path: ExternalResource): ChunkMergeApproach.this.type

    Path to csv with false positive text, entity pairs to remove

  85. final def setInputCols(value: String*): ChunkMergeApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  86. final def setInputCols(value: Array[String]): ChunkMergeApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  87. def setLazyAnnotator(value: Boolean): ChunkMergeApproach.this.type
    Definition Classes
    CanBeLazy
  88. def setMergeOverlapping(v: Boolean): ChunkMergeApproach.this.type
  89. final def setOutputCol(value: String): ChunkMergeApproach.this.type
    Definition Classes
    HasOutputAnnotationCol
  90. def setReplaceDictResource(path: String, readAs: Format = ReadAs.TEXT, options: Map[String, String] = Map("delimiter" -> ",")): ChunkMergeApproach.this.type

    dictionary with regular expression patterns that match some protected entity

  91. def setReplaceDictResource(path: ExternalResource): ChunkMergeApproach.this.type

    dictionary with regular expression patterns that match some protected entity

  92. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  93. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  94. def train(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): ChunkMergeModel

    Trains a model from the provided dataset.

    Trains a model from the provided dataset. Input columns should be set to output columns from e.g. a NerDLModel and a RegexMatcher.

    Definition Classes
    ChunkMergeApproach → AnnotatorApproach
  95. def transformReplaceDict(replaceDict: Array[(String, String)]): Map[String, String]
  96. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  97. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  98. val uid: String
    Definition Classes
    ChunkMergeApproach → Identifiable
  99. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  100. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  101. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  102. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  103. def write: MLWriter
    Definition Classes
    DefaultParamsWritable → MLWritable

Inherited from CheckLicense

Inherited from AnnotatorApproach[ChunkMergeModel]

Inherited from CanBeLazy

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from HasOutputAnnotatorType

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from Estimator[ChunkMergeModel]

Inherited from PipelineStage

Inherited from Logging

Inherited from Params

Inherited from Serializable

Inherited from Serializable

Inherited from Identifiable

Inherited from AnyRef

Inherited from Any

Parameters

Annotator types

Required input and expected output annotator types

Members

Parameter setters