Packages

c

com.johnsnowlabs.nlp.annotators.merge

ChunkMergeApproach

class ChunkMergeApproach extends AnnotatorApproach[ChunkMergeModel] with HasMultipleInputAnnotationCols 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, HasMultipleInputAnnotationCols, 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. HasMultipleInputAnnotationCols
  4. AnnotatorApproach
  5. CanBeLazy
  6. DefaultParamsWritable
  7. MLWritable
  8. HasOutputAnnotatorType
  9. HasOutputAnnotationCol
  10. HasInputAnnotationCols
  11. Estimator
  12. PipelineStage
  13. Logging
  14. Params
  15. Serializable
  16. Serializable
  17. Identifiable
  18. AnyRef
  19. 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. val blackList: StringArrayParam
  9. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  10. def checkValidEnvironment(spark: Option[SparkSession]): Unit
    Definition Classes
    CheckLicense
  11. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  12. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkSession], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  13. def checkValidScopesAndEnvironment(scopes: Seq[String], spark: Option[SparkSession], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  14. val chunkPrecedence: Param[String]

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

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

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

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

    Output annotator types: CHUNK, CHUNK

    Output annotator types: CHUNK, CHUNK

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

    whether to merge overlapping matched chunks.

    whether to merge overlapping matched chunks. Defaults to true

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

    Input annotator types: CHUNK

    Input annotator types: CHUNK

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

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

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

    If defined, list of entities to ignore.

    If defined, list of entities to ignore. The rest will be processed.

  83. 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]

  84. final def setDefault(paramPairs: ParamPair[_]*): ChunkMergeApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  85. final def setDefault[T](param: Param[T], value: T): ChunkMergeApproach.this.type
    Attributes
    protected
    Definition Classes
    Params
  86. 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

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

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

  88. def setInputCols(value: Array[String]): ChunkMergeApproach.this.type
    Definition Classes
    HasMultipleInputAnnotationCols → HasInputAnnotationCols
  89. final def setInputCols(value: String*): ChunkMergeApproach.this.type
    Definition Classes
    HasInputAnnotationCols
  90. def setLazyAnnotator(value: Boolean): ChunkMergeApproach.this.type
    Definition Classes
    CanBeLazy
  91. def setMergeOverlapping(v: Boolean): ChunkMergeApproach.this.type
  92. final def setOutputCol(value: String): ChunkMergeApproach.this.type
    Definition Classes
    HasOutputAnnotationCol
  93. 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

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

    dictionary with regular expression patterns that match some protected entity

  95. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  96. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  97. 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
  98. def transformReplaceDict(replaceDict: Array[(String, String)]): Map[String, String]
  99. final def transformSchema(schema: StructType): StructType
    Definition Classes
    AnnotatorApproach → PipelineStage
  100. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  101. val uid: String
    Definition Classes
    ChunkMergeApproach → Identifiable
  102. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    AnnotatorApproach
  103. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  104. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  105. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  106. def write: MLWriter
    Definition Classes
    DefaultParamsWritable → MLWritable

Inherited from CheckLicense

Inherited from HasMultipleInputAnnotationCols

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