[ 
https://issues.apache.org/jira/browse/BEAM-9248?focusedWorklogId=392824&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-392824
 ]

ASF GitHub Bot logged work on BEAM-9248:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 25/Feb/20 18:40
            Start Date: 25/Feb/20 18:40
    Worklog Time Spent: 10m 
      Work Description: aaltay commented on pull request #10881: [BEAM-9248] 
Integrate Google Cloud Natural Language functionality for Python SDK
URL: https://github.com/apache/beam/pull/10881#discussion_r384051123
 
 

 ##########
 File path: sdks/python/apache_beam/ml/gcp/naturallanguageml.py
 ##########
 @@ -0,0 +1,156 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+from __future__ import absolute_import
+
+from typing import Dict
+from typing import Mapping
+from typing import Optional
+from typing import Sequence
+from typing import Tuple
+from typing import Union
+
+import apache_beam as beam
+from apache_beam.metrics import Metrics
+
+try:
+  from google.cloud import language
+  from google.cloud.language import enums  # pylint: disable=unused-import
+  from google.cloud.language import types
+except ImportError:
+  raise ImportError(
+      'Google Cloud Natural Language API not supported for this execution '
+      'environment (could not import Natural Language API client).')
+
+__all__ = ['Document', 'Feature', 'AnnotateText']
+
+
+class Document(object):
+  """Represents the input to :class:`AnnotateText` transform.
+
+  Args:
+    content (str): The content of the input or the Google Cloud Storage URI
+      where the file is stored.
+    type (`Union[str, google.cloud.language.enums.Document.Type]`): Text type.
+      Possible values are `HTML`, `PLAIN_TEXT`. The default value is
+      `PLAIN_TEXT`.
+    language_hint (`Optional[str]`): The language of the text. If not 
specified,
+      language will be automatically detected. Values should conform to
+      ISO-639-1 standard.
+    encoding (`Optional[str]`): Text encoding. Possible values are: `NONE`,
+     `UTF8`, `UTF16`, `UTF32`. The default value is `UTF8`.
+    from_gcs (bool): Whether the content should be interpret as a Google Cloud
+      Storage URI. The default value is :data:`False`.
+  """
+
+  def __init__(
+      self,
+      content,  # type: str
+      type='PLAIN_TEXT',  # type: Union[str, enums.Document.Type]
+      language_hint=None,  # type: Optional[str]
+      encoding='UTF8',  # type: Optional[str]
+      from_gcs=False  # type: bool
+  ):
+    self.content = content
+    self.type = type
+    self.encoding = encoding
+    self.language_hint = language_hint
+    self.from_gcs = from_gcs
+
+  @staticmethod
+  def to_dict(document):
+    # type: (Document) -> Mapping[str, Optional[str]]
+    if document.from_gcs:
+      dict_repr = {'gcs_content_uri': document.content}
+    else:
+      dict_repr = {'content': document.content}
+    dict_repr.update({
+        'type': document.type, 'language': document.language_hint
+    })
+    return dict_repr
+
+
+class Feature(object):
+  EXTRACT_SYNTAX = 'extract_syntax'
+  EXTRACT_ENTITIES = 'extract_entities'
+  EXTRACT_DOCUMENT_SENTIMENT = 'extract_document_sentiment'
+  EXTRACT_ENTITY_SENTIMENT = 'extract_entity_sentiment'
+  CLASSIFY_TEXT = 'classify_text'
+
+  @staticmethod
+  def to_dict(features):
 
 Review comment:
   What happens if features are not on the above list? Do we need to keep and 
maintain an updated list?
   
   Does the client library has a list of these?
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Issue Time Tracking
-------------------

    Worklog Id:     (was: 392824)
    Time Spent: 1h 40m  (was: 1.5h)

> [Python] PTransform that integrates Cloud Natural Language functionality
> ------------------------------------------------------------------------
>
>                 Key: BEAM-9248
>                 URL: https://issues.apache.org/jira/browse/BEAM-9248
>             Project: Beam
>          Issue Type: Sub-task
>          Components: io-py-gcp
>            Reporter: Kamil Wasilewski
>            Assignee: Kamil Wasilewski
>            Priority: Major
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> The goal is to create a PTransform that integrates Google Cloud Natural 
> Language API functionality [1].
> [1] https://cloud.google.com/natural-language/docs/



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to