sparknlp_jsl.annotator.assertion.assertion_merger#

Contains Class for AssertionMerger

Module Contents#

Classes#

AssertionMerger

Merges variety assertion columns coming from Assertion annotators like sparknlp_jsl.annotator.assertion.AssertionDLModel.

class AssertionMerger(classname='com.johnsnowlabs.nlp.annotators.assertion.merger.AssertionMerger', java_model=None)#

Bases: sparknlp_jsl.common.AnnotatorModelInternal, sparknlp_jsl.annotator.white_black_list_params.WhiteBlackListParams

Merges variety assertion columns coming from Assertion annotators like sparknlp_jsl.annotator.assertion.AssertionDLModel. AssertionMerger can filter, prioritize and merge assertion annotations by using proper parameters. See Also: sparknlp_jsl.annotator.WhiteBlackListParams for filtering options.

Input Annotation types

Output Annotation type

ASSERTION s

ASSERTION

Parameters:
  • mergeOverlapping (bool) – Whether to merge overlapping matched assertion annotations. Default: True

  • applyFilterBeforeMerge (bool) – Whether to apply filtering before merging process. If True, filtering will be applied before merging; if False, filtering will be applied after merging process. Default: False.

  • blackList (list[str]) – If defined, list of entities to ignore. The rest will be processed.

  • whiteList (list[str]) – If defined, list of entities to process. The rest will be ignored. Do not include IOB prefix on labels.

  • caseSensitive (bool) – Determines whether the definitions of the white listed and black listed entities are case sensitive. Default: True.

  • assertionsConfidence (dict[str, float]) – Pairs (assertion,confidenceThreshold) to filter assertions which have confidence lower than the confidence threshold.

  • orderingFeatures (list[str]) – Specifies the ordering features to use for overlapping entities. Possible values include: ‘begin’, ‘end’, ‘length’, ‘source’, ‘confidence’. Default: [‘begin’, ‘length’, ‘source’]

  • selectionStrategy (str) – Determines the strategy for selecting annotations. Annotations can be selected either sequentially based on their order (Sequential) or using a more diverse strategy (DiverseLonger). Currently, only Sequential and DiverseLonger options are available. Default: Sequential.

  • defaultConfidence (float) – When the confidence value is included in the orderingFeatures and a given annotation does not have any confidence, this parameter determines the value to be used. The default value is 0.

  • assertionSourcePrecedence (str) – Specifies the assertion sources to use for prioritizing overlapping annotations when the ‘source’ ordering feature is utilized. This parameter contains a comma-separated list of assertion sources that drive the prioritization. Annotations will be prioritized based on the order of the given string.

  • sortByBegin (bool) – Whether to sort the annotations by begin at the end of the merge and filter process. Default: False.

  • majorityVoting (bool) – Whether to use majority voting to resolve conflicts. Default: False.

applyFilterBeforeMerge#
assertionSourcePrecedence#
blackList#
caseSensitive#
defaultConfidence#
getter_attrs = []#
inputAnnotatorTypes#
inputCols#
lazyAnnotator#
majorityVoting#
mergeOverlapping#
name = 'AssertionMerger'#
optionalInputAnnotatorTypes = []#
orderingFeatures#
outputAnnotatorType = 'assertion'#
outputCol#
selectionStrategy#
skipLPInputColsValidation = True#
sortByBegin#
uid = ''#
whiteList#
clear(param: pyspark.ml.param.Param) None#

Clears a param from the param map if it has been explicitly set.

copy(extra: pyspark.ml._typing.ParamMap | None = None) JP#

Creates a copy of this instance with the same uid and some extra params. This implementation first calls Params.copy and then make a copy of the companion Java pipeline component with extra params. So both the Python wrapper and the Java pipeline component get copied.

Parameters:

extra (dict, optional) – Extra parameters to copy to the new instance

Returns:

Copy of this instance

Return type:

JavaParams

explainParam(param: str | Param) str#

Explains a single param and returns its name, doc, and optional default value and user-supplied value in a string.

explainParams() str#

Returns the documentation of all params with their optionally default values and user-supplied values.

extractParamMap(extra: pyspark.ml._typing.ParamMap | None = None) pyspark.ml._typing.ParamMap#

Extracts the embedded default param values and user-supplied values, and then merges them with extra values from input into a flat param map, where the latter value is used if there exist conflicts, i.e., with ordering: default param values < user-supplied values < extra.

Parameters:

extra (dict, optional) – extra param values

Returns:

merged param map

Return type:

dict

getInputCols()#

Gets current column names of input annotations.

getLazyAnnotator()#

Gets whether Annotator should be evaluated lazily in a RecursivePipeline.

getOrDefault(param: str) Any#
getOrDefault(param: Param[T]) T

Gets the value of a param in the user-supplied param map or its default value. Raises an error if neither is set.

getOutputCol()#

Gets output column name of annotations.

getParam(paramName: str) Param#

Gets a param by its name.

getParamValue(paramName)#

Gets the value of a parameter.

Parameters:

paramName (str) – Name of the parameter

hasDefault(param: str | Param[Any]) bool#

Checks whether a param has a default value.

hasParam(paramName: str) bool#

Tests whether this instance contains a param with a given (string) name.

inputColsValidation(value)#
isDefined(param: str | Param[Any]) bool#

Checks whether a param is explicitly set by user or has a default value.

isSet(param: str | Param[Any]) bool#

Checks whether a param is explicitly set by user.

classmethod load(path: str) RL#

Reads an ML instance from the input path, a shortcut of read().load(path).

classmethod read()#

Returns an MLReader instance for this class.

save(path: str) None#

Save this ML instance to the given path, a shortcut of ‘write().save(path)’.

set(param: Param, value: Any) None#

Sets a parameter in the embedded param map.

setApplyFilterBeforeMerge(value)#

Sets whether to apply filtering before merging process. If True, filtering will be applied before merging; if False, filtering will be applied after merging process. Default: False.

Parameters:

value (bool) – Whether to apply filtering before merging process.

setAssertionSourcePrecedence(value)#

Sets Specifies the assertion sources to use for prioritizing overlapping annotations when the ‘source’ ordering feature is utilized. This parameter contains a comma-separated list of assertion sources that drive the prioritization. Annotations will be prioritized based on the order of the given string.

Parameters:

value (str) – Specifies the assertion sources to use for prioritizing overlapping annotations when the ‘source’ ordering feature is utilized.

setAssertionsConfidence(value: dict)#

Sets Pairs (assertion,confidenceThreshold) to filter assertions which have confidence lower than the confidence threshold.

Parameters:

value (dict[str, float]) – Pairs (assertion,confidenceThreshold) to filter assertions which have confidence lower than the confidence threshold.

setBlackList(value)#

Sets If defined, list of entities to ignore. The rest will be processed. Do not include IOB prefix on labels

Parameters:

value (List[str]) – If defined, list of entities to ignore. The rest will be processed. Do not include IOB prefix on labels

setCaseSensitive(value)#

Determines whether the definitions of the white listed and black listed entities are case sensitive or not.

Parameters:

value (bool) – Whether white listed and black listed entities are case sensitive or not. Default: True.

setDefaultConfidence(value)#

Sets When the confidence value is included in the orderingFeatures and a given annotation does not have any confidence, this parameter determines the value to be used.

Parameters:

value (float) – When the confidence value is included in the orderingFeatures and a given annotation does not have any confidence, this parameter determines the value to be used. The default value is 0.

setDenyList(value)#

Sets If defined, list of entities to ignore. The rest will be processed. Do not include IOB prefix on labels

Parameters:

value (List[str]) – If defined, list of entities to ignore. The rest will be processed. Do not include IOB prefix on labels

setForceInputTypeValidation(etfm)#
setInputCols(*value)#

Sets column names of input annotations. :param *value: Input columns for the annotator :type *value: str

setLazyAnnotator(value)#

Sets whether Annotator should be evaluated lazily in a RecursivePipeline.

Parameters:

value (bool) – Whether Annotator should be evaluated lazily in a RecursivePipeline

setMajorityVoting(value)#
Sets whether to use majority voting to resolve conflicts. Default: False.

It is used to resolve conflicts when there are more than 2 annotations in the same overlapping group. When confidence is used for ordering features, confidence values sum is used for majority voting.

Parameters:

value (bool) – Whether to use majority voting to resolve conflicts. Default: False.

setMergeOverlapping(value)#

Sets whether to merge overlapping matched assertion annotations.

Parameters:

value (bool) – Whether to merge overlapping matched assertion annotations. Default: True.

setOrderingFeatures(value: list)#

Sets array of strings specifying the ordering features to use for overlapping entities. Possible values include: ‘begin’, ‘end’, ‘length’, ‘source’, ‘confidence’. Default: [‘begin’, ‘length’, ‘source’]

Parameters:

value (list[str]) – Array of strings specifying the ordering features to use for overlapping entities.

setOutputCol(value)#

Sets output column name of annotations.

Parameters:

value (str) – Name of output column

setParamValue(paramName)#

Sets the value of a parameter.

Parameters:

paramName (str) – Name of the parameter

setParams()#
setSelectionStrategy(value)#

Determines the strategy for selecting annotations. Annotations can be selected either sequentially based on their order (Sequential) or using a more diverse strategy (DiverseLonger). Currently, only Sequential and DiverseLonger options are available. Default: Sequential.

Parameters:

value (str) – Determines the strategy for selecting annotations.

setSortByBegin(value)#

Sets whether to sort the annotations by begin at the end of the merge and filter process. Default: False.

Parameters:

value (bool) – Whether to sort the annotations by begin at the end of the merge and filter process. Default: False.

setWhiteList(value)#

Sets If defined, list of entities to process. The rest will be ignored. Do not include IOB prefix on labels

Parameters:

value (List[str]) – If defined, list of entities to process. The rest will be ignored. Do not include IOB prefix on labels

transform(dataset: pyspark.sql.dataframe.DataFrame, params: pyspark.ml._typing.ParamMap | None = None) pyspark.sql.dataframe.DataFrame#

Transforms the input dataset with optional parameters.

New in version 1.3.0.

Parameters:
  • dataset (pyspark.sql.DataFrame) – input dataset

  • params (dict, optional) – an optional param map that overrides embedded params.

Returns:

transformed dataset

Return type:

pyspark.sql.DataFrame

write() JavaMLWriter#

Returns an MLWriter instance for this ML instance.