Skip to content

Commit

Permalink
[AIRFLOW-6110] [AIP-21] Rename natural_language service (#6968)
Browse files Browse the repository at this point in the history
  • Loading branch information
michalslowikowski00 authored and turbaszek committed Dec 31, 2019
1 parent 7176a83 commit 95087af
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 45 deletions.
8 changes: 4 additions & 4 deletions UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,10 +490,10 @@ The following table shows changes in import paths.
|airflow.contrib.operators.gcp_dlp_operator.CloudDLPUpdateStoredInfoTypeOperator |airflow.gcp.operators.dlp.CloudDLPUpdateStoredInfoTypeOperator |
|airflow.contrib.operators.gcp_function_operator.GcfFunctionDeleteOperator |airflow.gcp.operators.functions.GcfFunctionDeleteOperator |
|airflow.contrib.operators.gcp_function_operator.GcfFunctionDeployOperator |airflow.gcp.operators.functions.GcfFunctionDeployOperator |
|airflow.contrib.operators.gcp_natural_language_operator.CloudLanguageAnalyzeEntitiesOperator |airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeEntitiesOperator |
|airflow.contrib.operators.gcp_natural_language_operator.CloudLanguageAnalyzeEntitySentimentOperator |airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeEntitySentimentOperator |
|airflow.contrib.operators.gcp_natural_language_operator.CloudLanguageAnalyzeSentimentOperator |airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeSentimentOperator |
|airflow.contrib.operators.gcp_natural_language_operator.CloudLanguageClassifyTextOperator |airflow.providers.google.cloud.operators.natural_language.CloudLanguageClassifyTextOperator |
|airflow.contrib.operators.gcp_natural_language_operator.CloudNaturalLanguageAnalyzeEntitiesOperator |airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeEntitiesOperator |
|airflow.contrib.operators.gcp_natural_language_operator.CloudNaturalLanguageAnalyzeEntitySentimentOperator |airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeEntitySentimentOperator|
|airflow.contrib.operators.gcp_natural_language_operator.CloudNaturalLanguageAnalyzeSentimentOperator |airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeSentimentOperator |
|airflow.contrib.operators.gcp_natural_language_operator.CloudNaturalLanguageClassifyTextOperator |airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageClassifyTextOperator |
|airflow.contrib.operators.gcp_spanner_operator.CloudSpannerInstanceDatabaseDeleteOperator |airflow.gcp.operators.spanner.CloudSpannerInstanceDatabaseDeleteOperator |
|airflow.contrib.operators.gcp_spanner_operator.CloudSpannerInstanceDatabaseDeployOperator |airflow.gcp.operators.spanner.CloudSpannerInstanceDatabaseDeployOperator |
|airflow.contrib.operators.gcp_spanner_operator.CloudSpannerInstanceDatabaseQueryOperator |airflow.gcp.operators.spanner.CloudSpannerInstanceDatabaseQueryOperator |
Expand Down
76 changes: 71 additions & 5 deletions airflow/contrib/operators/gcp_natural_language_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,79 @@

import warnings

# pylint: disable=unused-import
from airflow.providers.google.cloud.operators.natural_language import ( # noqa
CloudLanguageAnalyzeEntitiesOperator, CloudLanguageAnalyzeEntitySentimentOperator,
CloudLanguageAnalyzeSentimentOperator, CloudLanguageClassifyTextOperator,
from airflow.providers.google.cloud.operators.natural_language import (
CloudNaturalLanguageAnalyzeEntitiesOperator, CloudNaturalLanguageAnalyzeEntitySentimentOperator,
CloudNaturalLanguageAnalyzeSentimentOperator, CloudNaturalLanguageClassifyTextOperator,
)

warnings.warn(
"This module is deprecated. Please use `airflow.providers.google.cloud.operators.natural_language`",
"""This module is deprecated.
Please use `airflow.providers.google.cloud.operators.natural_language`
""",
DeprecationWarning, stacklevel=2
)


class CloudLanguageAnalyzeEntitiesOperator(CloudNaturalLanguageAnalyzeEntitiesOperator):
"""
This class is deprecated.
Please use `airflow.gcp.operators.natural_language.CloudNaturalLanguageAnalyzeEntitiesOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"""This class is deprecated.
Please use `airflow.gcp.operators.natural_language.CloudNaturalLanguageAnalyzeEntitiesOperator`.
""",
DeprecationWarning, stacklevel=2
)
super().__init__(*args, **kwargs)


class CloudLanguageAnalyzeEntitySentimentOperator(CloudNaturalLanguageAnalyzeEntitySentimentOperator):
"""
This class is deprecated.
Please use `airflow.gcp.operators.natural_language.CloudNaturalLanguageAnalyzeEntitySentimentOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"""This class is deprecated.
Please use
`airflow.gcp.operators.natural_language.CloudNaturalLanguageAnalyzeEntitySentimentOperator`.
""",
DeprecationWarning, stacklevel=2
)
super().__init__(*args, **kwargs)


class CloudLanguageAnalyzeSentimentOperator(CloudNaturalLanguageAnalyzeSentimentOperator):
"""
This class is deprecated.
Please use `airflow.gcp.operators.natural_language.CloudNaturalLanguageAnalyzeSentimentOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"""This class is deprecated.
Please use `airflow.gcp.operators.natural_language.CloudNaturalLanguageAnalyzeSentimentOperator`.
""",
DeprecationWarning, stacklevel=2
)
super().__init__(*args, **kwargs)


class CloudLanguageClassifyTextOperator(CloudNaturalLanguageClassifyTextOperator):
"""
This class is deprecated.
Please use `airflow.gcp.operators.natural_language.CloudNaturalLanguageClassifyTextOperator`.
"""

def __init__(self, *args, **kwargs):
warnings.warn(
"""This class is deprecated.
Please use `airflow.gcp.operators.natural_language.CloudNaturalLanguageClassifyTextOperator`.
""",
DeprecationWarning, stacklevel=2
)
super().__init__(*args, **kwargs)
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
from airflow import models
from airflow.operators.bash_operator import BashOperator
from airflow.providers.google.cloud.operators.natural_language import (
CloudLanguageAnalyzeEntitiesOperator, CloudLanguageAnalyzeEntitySentimentOperator,
CloudLanguageAnalyzeSentimentOperator, CloudLanguageClassifyTextOperator,
CloudNaturalLanguageAnalyzeEntitiesOperator, CloudNaturalLanguageAnalyzeEntitySentimentOperator,
CloudNaturalLanguageAnalyzeSentimentOperator, CloudNaturalLanguageClassifyTextOperator,
)

# [START howto_operator_gcp_natural_language_document_text]
Expand Down Expand Up @@ -57,7 +57,8 @@
) as dag:

# [START howto_operator_gcp_natural_language_analyze_entities]
analyze_entities = CloudLanguageAnalyzeEntitiesOperator(document=document, task_id="analyze_entities")
analyze_entities = \
CloudNaturalLanguageAnalyzeEntitiesOperator(document=document, task_id="analyze_entities")
# [END howto_operator_gcp_natural_language_analyze_entities]

# [START howto_operator_gcp_natural_language_analyze_entities_result]
Expand All @@ -68,7 +69,7 @@
# [END howto_operator_gcp_natural_language_analyze_entities_result]

# [START howto_operator_gcp_natural_language_analyze_entity_sentiment]
analyze_entity_sentiment = CloudLanguageAnalyzeEntitySentimentOperator(
analyze_entity_sentiment = CloudNaturalLanguageAnalyzeEntitySentimentOperator(
document=document, task_id="analyze_entity_sentiment"
)
# [END howto_operator_gcp_natural_language_analyze_entity_sentiment]
Expand All @@ -81,7 +82,8 @@
# [END howto_operator_gcp_natural_language_analyze_entity_sentiment_result]

# [START howto_operator_gcp_natural_language_analyze_sentiment]
analyze_sentiment = CloudLanguageAnalyzeSentimentOperator(document=document, task_id="analyze_sentiment")
analyze_sentiment = \
CloudNaturalLanguageAnalyzeSentimentOperator(document=document, task_id="analyze_sentiment")
# [END howto_operator_gcp_natural_language_analyze_sentiment]

# [START howto_operator_gcp_natural_language_analyze_sentiment_result]
Expand All @@ -92,7 +94,7 @@
# [END howto_operator_gcp_natural_language_analyze_sentiment_result]

# [START howto_operator_gcp_natural_language_analyze_classify_text]
analyze_classify_text = CloudLanguageClassifyTextOperator(
analyze_classify_text = CloudNaturalLanguageClassifyTextOperator(
document=document, task_id="analyze_classify_text"
)
# [END howto_operator_gcp_natural_language_analyze_classify_text]
Expand Down
17 changes: 9 additions & 8 deletions airflow/providers/google/cloud/operators/natural_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@
MetaData = Sequence[Tuple[str, str]]


class CloudLanguageAnalyzeEntitiesOperator(BaseOperator):
class CloudNaturalLanguageAnalyzeEntitiesOperator(BaseOperator):
"""
Finds named entities in the text along with entity types,
salience, mentions for each entity, and other properties.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudLanguageAnalyzeEntitiesOperator`
:ref:`howto/operator:CloudNaturalLanguageAnalyzeEntitiesOperator`
:param document: Input document.
If a dict is provided, it must be of the same form as the protobuf message Document
Expand Down Expand Up @@ -91,14 +92,14 @@ def execute(self, context):
return MessageToDict(response)


class CloudLanguageAnalyzeEntitySentimentOperator(BaseOperator):
class CloudNaturalLanguageAnalyzeEntitySentimentOperator(BaseOperator):
"""
Finds entities, similar to AnalyzeEntities in the text and analyzes sentiment associated with each
entity and its mentions.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudLanguageAnalyzeEntitySentimentOperator`
:ref:`howto/operator:CloudNaturalLanguageAnalyzeEntitySentimentOperator`
:param document: Input document.
If a dict is provided, it must be of the same form as the protobuf message Document
Expand Down Expand Up @@ -155,13 +156,13 @@ def execute(self, context):
return MessageToDict(response)


class CloudLanguageAnalyzeSentimentOperator(BaseOperator):
class CloudNaturalLanguageAnalyzeSentimentOperator(BaseOperator):
"""
Analyzes the sentiment of the provided text.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudLanguageAnalyzeSentimentOperator`
:ref:`howto/operator:CloudNaturalLanguageAnalyzeSentimentOperator`
:param document: Input document.
If a dict is provided, it must be of the same form as the protobuf message Document
Expand Down Expand Up @@ -214,13 +215,13 @@ def execute(self, context):
return MessageToDict(response)


class CloudLanguageClassifyTextOperator(BaseOperator):
class CloudNaturalLanguageClassifyTextOperator(BaseOperator):
"""
Classifies a document into categories.
.. seealso::
For more information on how to use this operator, take a look at the guide:
:ref:`howto/operator:CloudLanguageClassifyTextOperator`
:ref:`howto/operator:CloudNaturalLanguageClassifyTextOperator`
:param document: Input document.
If a dict is provided, it must be of the same form as the protobuf message Document
Expand Down
24 changes: 12 additions & 12 deletions docs/howto/operator/gcp/natural_language.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ In addition to supplying string, a document can refer to content stored in Googl
:start-after: [START howto_operator_gcp_natural_language_document_gcs]
:end-before: [END howto_operator_gcp_natural_language_document_gcs]

.. _howto/operator:CloudLanguageAnalyzeEntitiesOperator:
.. _howto/operator:CloudNaturalLanguageAnalyzeEntitiesOperator:

Analyzing Entities
^^^^^^^^^^^^^^^^^^

Entity Analysis inspects the given text for known entities (proper nouns such as
public figures, landmarks, etc.), and returns information about those entities.
Entity analysis is performed with the
:class:`~airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeEntitiesOperator` operator.
:class:`~airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeEntitiesOperator` operator.

.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_natural_language.py
:language: python
Expand All @@ -77,7 +77,7 @@ Entity analysis is performed with the
:end-before: [END howto_operator_gcp_natural_language_analyze_entities]

You can use :ref:`Jinja templating <jinja-templating>` with
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeEntitiesOperator`
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeEntitiesOperator`
parameters which allows you to dynamically determine values. The result is saved to :ref:`XCom <concepts:xcom>`, which allows it
to be used by other operators.

Expand All @@ -87,15 +87,15 @@ to be used by other operators.
:start-after: [START howto_operator_gcp_natural_language_analyze_entities_result]
:end-before: [END howto_operator_gcp_natural_language_analyze_entities_result]

.. _howto/operator:CloudLanguageAnalyzeEntitySentimentOperator:
.. _howto/operator:CloudNaturalLanguageAnalyzeEntitySentimentOperator:

Analyzing Entity Sentiment
^^^^^^^^^^^^^^^^^^^^^^^^^^

Sentiment Analysis inspects the given text and identifies the prevailing
emotional opinion within the text, especially to determine a writer's attitude
as positive, negative, or neutral. Sentiment analysis is performed through
the :class:`~airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeEntitySentimentOperator`
the :class:`~airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeEntitySentimentOperator`
operator.

.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_natural_language.py
Expand All @@ -105,7 +105,7 @@ operator.
:end-before: [END howto_operator_gcp_natural_language_analyze_entity_sentiment]

You can use :ref:`Jinja templating <jinja-templating>` with
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeEntitiesOperator`
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeEntitiesOperator`
parameters which allows you to dynamically determine values. The result is saved to :ref:`XCom <concepts:xcom>`, which allows it
to be used by other operators.

Expand All @@ -115,7 +115,7 @@ to be used by other operators.
:start-after: [START howto_operator_gcp_natural_language_analyze_entity_sentiment_result]
:end-before: [END howto_operator_gcp_natural_language_analyze_entity_sentiment_result]

.. _howto/operator:CloudLanguageAnalyzeSentimentOperator:
.. _howto/operator:CloudNaturalLanguageAnalyzeSentimentOperator:

Analyzing Sentiment
^^^^^^^^^^^^^^^^^^^
Expand All @@ -124,7 +124,7 @@ Sentiment Analysis inspects the given text and identifies the prevailing
emotional opinion within the text, especially to determine a writer's
attitude as positive, negative, or neutral. Sentiment analysis is performed
through the
:class:`~airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeSentimentOperator`
:class:`~airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeSentimentOperator`
operator.

.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_natural_language.py
Expand All @@ -134,7 +134,7 @@ operator.
:end-before: [END howto_operator_gcp_natural_language_analyze_sentiment]

You can use :ref:`Jinja templating <jinja-templating>` with
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudLanguageAnalyzeSentimentOperator`
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageAnalyzeSentimentOperator`
parameters which allows you to dynamically determine values. The result is saved to :ref:`XCom <concepts:xcom>`, which allows it
to be used by other operators.

Expand All @@ -144,15 +144,15 @@ to be used by other operators.
:start-after: [START howto_operator_gcp_natural_language_analyze_sentiment_result]
:end-before: [END howto_operator_gcp_natural_language_analyze_sentiment_result]

.. _howto/operator:CloudLanguageClassifyTextOperator:
.. _howto/operator:CloudNaturalLanguageClassifyTextOperator:

Classifying Content
^^^^^^^^^^^^^^^^^^^

Content Classification analyzes a document and returns a list of content
categories that apply to the text found in the document. To classify the
content in a document, use the
:class:`~airflow.providers.google.cloud.operators.natural_language.CloudLanguageClassifyTextOperator`
:class:`~airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageClassifyTextOperator`
operator.

.. exampleinclude:: ../../../../airflow/providers/google/cloud/example_dags/example_natural_language.py
Expand All @@ -162,7 +162,7 @@ operator.
:end-before: [END howto_operator_gcp_natural_language_analyze_classify_text]

You can use :ref:`Jinja templating <jinja-templating>` with
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudLanguageClassifyTextOperator`
:template-fields:`airflow.providers.google.cloud.operators.natural_language.CloudNaturalLanguageClassifyTextOperator`
parameters which allows you to dynamically determine values. The result is saved to :ref:`XCom <concepts:xcom>`, which allows it
to be used by other operators.

Expand Down

0 comments on commit 95087af

Please sign in to comment.