class ContextualEntityFilterer extends AnnotatorModel[ContextualEntityFilterer] with HasSimpleAnnotate[ContextualEntityFilterer] with HandleExceptionParams with HasSafeAnnotate[ContextualEntityFilterer] with CheckLicense

ContextualEntityFilterer can filter chunks coming from CHUNK annotations based on entity(identifier,field) info in metadata. Filters can be done via white list entities, black list entities, black list word and white list words. The filter can be applied to the scope of the sentence or the document.

Example

Define pipeline stages to extract entities

val documentAssembler = new DocumentAssembler()
  .setInputCol("text")
  .setOutputCol("document")

val sentenceDetector = new SentenceDetector()
  .setInputCols(Array("document"))
  .setOutputCol("sentences")

val tokenizer = new Tokenizer()
  .setInputCols(Array("sentences"))
  .setOutputCol("tokens")

val embedder = WordEmbeddingsModel
  .pretrained("embeddings_clinical", "en", "clinical/models")
  .setInputCols(Array("sentences", "tokens"))
  .setOutputCol("embeddings")

val nerTagger = MedicalNerModel
  .pretrained("ner_deid_generic_augmented", "en", "clinical/models")
  .setInputCols(Array("sentences", "tokens", "embeddings"))
  .setOutputCol("nerTags")

val nerConverter = new NerConverterInternal()
  .setInputCols(Array("sentences", "tokens", "nerTags"))
  .setOutputCol("nerChunks")

Define ContextualEntityFilterer and set the rules

val jsonRules=
     """
         |[{
         | "entity" : "LOCATION",
         | "scopeWindow" : [2,2],
         | "whiteListEntities" : ["AGE","DATE"],
         | "blackListEntities" : ["ID","NAME"],
         | "scopeWindowLevel"  : "token",
         | "blackListWords" : ["beautiful"]
         | },
         | {
         |  "entity" : "DATE",
         |  "scopeWindow" : [2,2],
         |  "whiteListEntities" : ["AGE","DATE"],
         |  "blackListEntities" : ["ID","NAME"],
         |  "scopeWindowLevel"  : "chunk",
         |  "confidenceThreshold" : 0,50
         | }
         | ]
         |
         |""".stripMargin

 val contextualEntityFilter = new ContextualEntityFilterer()
   .setInputCols(Array("sentences", "tokens", "nerChunks"))
   .setOutputCol("filtered_chunks")
   .setRulesAsStr(jsonRules)
   .setRuleScope("document")



val pipeline = new Pipeline().setStages(Array(
     documentAssembler,
     sentenceDetector,
     tokenizer,
     embedder,
     nerTagger,
     nerConverter,
     contextualEntityFilter
   ))

 val testText = "California, known for its beautiful beaches,and he is 36 years. " +
     "The Grand Canyon in Arizona, where the age is 37, is a stunning natural landmark. " +
     "It was founded on September 9, 1850, and Arizona on February 14, 1912."
 val testDataSet = Seq(testText).toDS.toDF("text")

 val result = pipeline.fit(testDataSet).transform(testDataSet)

Show results

result.selectExpr("explode(filtered_chunks) as filtered").show(100,truncate = false)

    -----------------+-----+-----+------+
    |result           |begin|end  |entity|
    +-----------------+-----+-----+------+
    |36               |54   |55   |AGE   |
    |37               |110  |111  |AGE   |
    |September 9, 1850|164  |180  |DATE  |
    |February 14, 1912|198  |214  |DATE  |
    +-----------------+-----+-----+------+
Linear Supertypes
CheckLicense, HasSafeAnnotate[ContextualEntityFilterer], HandleExceptionParams, HasSimpleAnnotate[ContextualEntityFilterer], AnnotatorModel[ContextualEntityFilterer], CanBeLazy, RawAnnotator[ContextualEntityFilterer], HasOutputAnnotationCol, HasInputAnnotationCols, HasOutputAnnotatorType, ParamsAndFeaturesWritable, HasFeatures, DefaultParamsWritable, MLWritable, Model[ContextualEntityFilterer], Transformer, PipelineStage, Logging, Params, Serializable, Serializable, Identifiable, AnyRef, Any
Ordering
  1. Grouped
  2. Alphabetic
  3. By Inheritance
Inherited
  1. ContextualEntityFilterer
  2. CheckLicense
  3. HasSafeAnnotate
  4. HandleExceptionParams
  5. HasSimpleAnnotate
  6. AnnotatorModel
  7. CanBeLazy
  8. RawAnnotator
  9. HasOutputAnnotationCol
  10. HasInputAnnotationCols
  11. HasOutputAnnotatorType
  12. ParamsAndFeaturesWritable
  13. HasFeatures
  14. DefaultParamsWritable
  15. MLWritable
  16. Model
  17. Transformer
  18. PipelineStage
  19. Logging
  20. Params
  21. Serializable
  22. Serializable
  23. Identifiable
  24. AnyRef
  25. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

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

    uid

    a unique identifier for the instantiated AnnotatorModel

Type Members

  1. type AnnotationContent = Seq[Row]
    Attributes
    protected
    Definition Classes
    AnnotatorModel
  2. 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. def $$[T](feature: StructFeature[T]): T
    Attributes
    protected
    Definition Classes
    HasFeatures
  5. def $$[K, V](feature: MapFeature[K, V]): Map[K, V]
    Attributes
    protected
    Definition Classes
    HasFeatures
  6. def $$[T](feature: SetFeature[T]): Set[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  7. def $$[T](feature: ArrayFeature[T]): Array[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  8. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  9. def _transform(dataset: Dataset[_], recursivePipeline: Option[PipelineModel]): DataFrame
    Attributes
    protected
    Definition Classes
    AnnotatorModel
  10. def afterAnnotate(dataset: DataFrame): DataFrame
    Attributes
    protected
    Definition Classes
    AnnotatorModel
  11. final def annotate(annotations: Seq[Annotation]): Seq[Annotation]
    Definition Classes
    ContextualEntityFilterer → HasSimpleAnnotate
  12. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  13. def beforeAnnotate(dataset: Dataset[_]): Dataset[_]
    Attributes
    protected
    Definition Classes
    AnnotatorModel
  14. val caseSensitive: BooleanParam

    Whether to use case sensitive when matching values.

    Whether to use case sensitive when matching values. Default is false

  15. final def checkSchema(schema: StructType, inputAnnotatorType: String): Boolean
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  16. def checkValidEnvironment(spark: Option[SparkSession], scopes: Seq[String]): Unit
    Definition Classes
    CheckLicense
  17. def checkValidScope(scope: String): Unit
    Definition Classes
    CheckLicense
  18. def checkValidScopeAndEnvironment(scope: String, spark: Option[SparkSession], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  19. def checkValidScopesAndEnvironment(scopes: Seq[String], spark: Option[SparkSession], checkLp: Boolean): Unit
    Definition Classes
    CheckLicense
  20. final def clear(param: Param[_]): ContextualEntityFilterer.this.type
    Definition Classes
    Params
  21. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  22. def copy(extra: ParamMap): ContextualEntityFilterer
    Definition Classes
    RawAnnotator → Model → Transformer → PipelineStage → Params
  23. def copyValues[T <: Params](to: T, extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  24. final def defaultCopy[T <: Params](extra: ParamMap): T
    Attributes
    protected
    Definition Classes
    Params
  25. def dfAnnotate: UserDefinedFunction
    Definition Classes
    HasSimpleAnnotate
  26. val doExceptionHandling: BooleanParam

    If true, exceptions are handled.

    If true, exceptions are handled. If exception causing data is passed to the model, a error annotation is emitted which has the exception message. Processing continues with the next one. This comes with a performance penalty.

    Definition Classes
    HandleExceptionParams
  27. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  28. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  29. def explainParam(param: Param[_]): String
    Definition Classes
    Params
  30. def explainParams(): String
    Definition Classes
    Params
  31. def extraValidate(structType: StructType): Boolean
    Attributes
    protected
    Definition Classes
    RawAnnotator
  32. def extraValidateMsg: String
    Attributes
    protected
    Definition Classes
    RawAnnotator
  33. final def extractParamMap(): ParamMap
    Definition Classes
    Params
  34. final def extractParamMap(extra: ParamMap): ParamMap
    Definition Classes
    Params
  35. val features: ArrayBuffer[Feature[_, _, _]]
    Definition Classes
    HasFeatures
  36. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  37. def get[T](feature: StructFeature[T]): Option[T]
    Attributes
    protected
    Definition Classes
    HasFeatures
  38. def get[K, V](feature: MapFeature[K, V]): Option[Map[K, V]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  39. def get[T](feature: SetFeature[T]): Option[Set[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  40. def get[T](feature: ArrayFeature[T]): Option[Array[T]]
    Attributes
    protected
    Definition Classes
    HasFeatures
  41. final def get[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  42. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  43. final def getDefault[T](param: Param[T]): Option[T]
    Definition Classes
    Params
  44. def getInputCols: Array[String]
    Definition Classes
    HasInputAnnotationCols
  45. def getLazyAnnotator: Boolean
    Definition Classes
    CanBeLazy
  46. final def getOrDefault[T](param: Param[T]): T
    Definition Classes
    Params
  47. final def getOutputCol: String
    Definition Classes
    HasOutputAnnotationCol
  48. def getParam(paramName: String): Param[Any]
    Definition Classes
    Params
  49. def getRules: Array[ContextualFilteringRules]

    Get ContextualFilteringRules param

  50. final def hasDefault[T](param: Param[T]): Boolean
    Definition Classes
    Params
  51. def hasParam(paramName: String): Boolean
    Definition Classes
    Params
  52. def hasParent: Boolean
    Definition Classes
    Model
  53. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  54. val inExceptionMode: Boolean
    Attributes
    protected
    Definition Classes
    HasSafeAnnotate
  55. def initializeLogIfNecessary(isInterpreter: Boolean, silent: Boolean): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  56. def initializeLogIfNecessary(isInterpreter: Boolean): Unit
    Attributes
    protected
    Definition Classes
    Logging
  57. val inputAnnotatorTypes: Array[String]

    DOCUMENT, CHUNK, TOKEN

    DOCUMENT, CHUNK, TOKEN

    Definition Classes
    ContextualEntityFilterer → HasInputAnnotationCols
  58. final val inputCols: StringArrayParam
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  59. final def isDefined(param: Param[_]): Boolean
    Definition Classes
    Params
  60. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  61. final def isSet(param: Param[_]): Boolean
    Definition Classes
    Params
  62. def isTraceEnabled(): Boolean
    Attributes
    protected
    Definition Classes
    Logging
  63. val lazyAnnotator: BooleanParam
    Definition Classes
    CanBeLazy
  64. def log: Logger
    Attributes
    protected
    Definition Classes
    Logging
  65. def logDebug(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  66. def logDebug(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  67. def logError(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  68. def logError(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  69. def logInfo(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  70. def logInfo(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  71. def logName: String
    Attributes
    protected
    Definition Classes
    Logging
  72. def logTrace(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  73. def logTrace(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  74. def logWarning(msg: ⇒ String, throwable: Throwable): Unit
    Attributes
    protected
    Definition Classes
    Logging
  75. def logWarning(msg: ⇒ String): Unit
    Attributes
    protected
    Definition Classes
    Logging
  76. def msgHelper(schema: StructType): String
    Attributes
    protected
    Definition Classes
    HasInputAnnotationCols
  77. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  78. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  79. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  80. def onWrite(path: String, spark: SparkSession): Unit
    Attributes
    protected
    Definition Classes
    ParamsAndFeaturesWritable
  81. val optionalInputAnnotatorTypes: Array[String]
    Definition Classes
    HasInputAnnotationCols
  82. val outputAnnotatorType: AnnotatorType

    CHUNK

    CHUNK

    Definition Classes
    ContextualEntityFilterer → HasOutputAnnotatorType
  83. final val outputCol: Param[String]
    Attributes
    protected
    Definition Classes
    HasOutputAnnotationCol
  84. lazy val params: Array[Param[_]]
    Definition Classes
    Params
  85. var parent: Estimator[ContextualEntityFilterer]
    Definition Classes
    Model
  86. val ruleScope: Param[String]
  87. val rules: StructFeature[Array[ContextualFilteringRules]]

    The rules parameter is used to filter the annotations by entity.

    The rules parameter is used to filter the annotations by entity. The rules is an array of ContextualFilteringRules.

  88. def safeAnnotate(annotations: Seq[Annotation]): Seq[Annotation]

    A protected method designed to safely annotate a sequence of Annotation objects by handling exceptions.

    A protected method designed to safely annotate a sequence of Annotation objects by handling exceptions.

    annotations

    A sequence of Annotation.

    returns

    A sequence of Annotation objects after processing, potentially containing error annotations.

    Attributes
    protected
    Definition Classes
    HasSafeAnnotate
  89. def save(path: String): Unit
    Definition Classes
    MLWritable
    Annotations
    @Since( "1.6.0" ) @throws( ... )
  90. def set[T](feature: StructFeature[T], value: T): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  91. def set[K, V](feature: MapFeature[K, V], value: Map[K, V]): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  92. def set[T](feature: SetFeature[T], value: Set[T]): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  93. def set[T](feature: ArrayFeature[T], value: Array[T]): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  94. final def set(paramPair: ParamPair[_]): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    Params
  95. final def set(param: String, value: Any): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    Params
  96. final def set[T](param: Param[T], value: T): ContextualEntityFilterer.this.type
    Definition Classes
    Params
  97. def setCaseSensitive(value: Boolean): ContextualEntityFilterer.this.type

    Whether to use case sensitive when matching values.

    Whether to use case sensitive when matching values. Default is false

  98. def setDefault[T](feature: StructFeature[T], value: () ⇒ T): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  99. def setDefault[K, V](feature: MapFeature[K, V], value: () ⇒ Map[K, V]): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  100. def setDefault[T](feature: SetFeature[T], value: () ⇒ Set[T]): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  101. def setDefault[T](feature: ArrayFeature[T], value: () ⇒ Array[T]): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    HasFeatures
  102. final def setDefault(paramPairs: ParamPair[_]*): ContextualEntityFilterer.this.type
    Attributes
    protected
    Definition Classes
    Params
  103. final def setDefault[T](param: Param[T], value: T): ContextualEntityFilterer.this.type
    Attributes
    protected[org.apache.spark.ml]
    Definition Classes
    Params
  104. def setDoExceptionHandling(value: Boolean): ContextualEntityFilterer.this.type

    If true, exceptions are handled.

    If true, exceptions are handled. If exception causing data is passed to the model, a error annotation is emitted which has the exception message. Processing continues with the next one. This comes with a performance penalty.

    Definition Classes
    HandleExceptionParams
  105. final def setInputCols(value: String*): ContextualEntityFilterer.this.type
    Definition Classes
    HasInputAnnotationCols
  106. def setInputCols(value: Array[String]): ContextualEntityFilterer.this.type
    Definition Classes
    HasInputAnnotationCols
  107. def setLazyAnnotator(value: Boolean): ContextualEntityFilterer.this.type
    Definition Classes
    CanBeLazy
  108. final def setOutputCol(value: String): ContextualEntityFilterer.this.type
    Definition Classes
    HasOutputAnnotationCol
  109. def setParent(parent: Estimator[ContextualEntityFilterer]): ContextualEntityFilterer
    Definition Classes
    Model
  110. def setRuleScope(value: String): ContextualEntityFilterer.this.type
  111. def setRules(value: Array[ContextualFilteringRules]): ContextualEntityFilterer.this.type

    Set the rules parameter.

    Set the rules parameter. The rules is an array of ContextualFilteringRules. Default: Array.empty

  112. def setRulesAsStr(value: String): ContextualEntityFilterer.this.type
  113. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  114. def toString(): String
    Definition Classes
    Identifiable → AnyRef → Any
  115. final def transform(dataset: Dataset[_]): DataFrame
    Definition Classes
    AnnotatorModel → Transformer
  116. def transform(dataset: Dataset[_], paramMap: ParamMap): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" )
  117. def transform(dataset: Dataset[_], firstParamPair: ParamPair[_], otherParamPairs: ParamPair[_]*): DataFrame
    Definition Classes
    Transformer
    Annotations
    @Since( "2.0.0" ) @varargs()
  118. final def transformSchema(schema: StructType): StructType
    Definition Classes
    RawAnnotator → PipelineStage
  119. def transformSchema(schema: StructType, logging: Boolean): StructType
    Attributes
    protected
    Definition Classes
    PipelineStage
    Annotations
    @DeveloperApi()
  120. val uid: String
    Definition Classes
    ContextualEntityFilterer → Identifiable
  121. def validate(schema: StructType): Boolean
    Attributes
    protected
    Definition Classes
    RawAnnotator
  122. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  123. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  124. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... ) @native()
  125. def wrapColumnMetadata(col: Column): Column
    Attributes
    protected
    Definition Classes
    RawAnnotator
  126. def write: MLWriter
    Definition Classes
    ParamsAndFeaturesWritable → DefaultParamsWritable → MLWritable

Inherited from CheckLicense

Inherited from HandleExceptionParams

Inherited from HasSimpleAnnotate[ContextualEntityFilterer]

Inherited from AnnotatorModel[ContextualEntityFilterer]

Inherited from CanBeLazy

Inherited from RawAnnotator[ContextualEntityFilterer]

Inherited from HasOutputAnnotationCol

Inherited from HasInputAnnotationCols

Inherited from HasOutputAnnotatorType

Inherited from ParamsAndFeaturesWritable

Inherited from HasFeatures

Inherited from DefaultParamsWritable

Inherited from MLWritable

Inherited from Model[ContextualEntityFilterer]

Inherited from Transformer

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

Parameter getters