sparknlp.functions.explode_annotations_col

sparknlp.functions.explode_annotations_col(dataframe: pyspark.sql.dataframe.DataFrame, column, output_column)[source]

Explodes an Annotation column, putting each result onto a separate row.

Parameters
dataframeDataFrame

The Spark DataFrame containing output Annotations

columnstr

Name of the column

output_columnstr

Name of the output column

Returns
pyspark.sql.DataFrame

Transformed DataFrame

Examples

>>> from sparknlp.pretrained import PretrainedPipeline
>>> from sparknlp.functions import *
>>> explain_document_pipeline = PretrainedPipeline("explain_document_dl")
>>> data = spark.createDataFrame([["U.N. official Ekeus heads for Baghdad."]]).toDF("text")
>>> result = explain_document_pipeline.transform(data)
>>> result.select("pos.result").show(truncate=False)
+----------------------------------+
|result                            |
+----------------------------------+
|[NNP, ., JJ, NNP, VBZ, IN, NNP, .]|
+----------------------------------+
>>> explode_annotations_col(result, "pos", "pos").select("pos.result").show()
+------+
|result|
+------+
|   NNP|
|     .|
|    JJ|
|   NNP|
|   VBZ|
|    IN|
|   NNP|
|     .|
+------+