-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Document factory constructors on language client #2164
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aeec23f
Adding basic Document class for Natural Language.
dhermes 528bfe9
Adding document_from_text() factory to language client.
dhermes 837358c
Adding document_from_html() factory to language client.
dhermes bbd2126
Adding document_from_url() factory to language client.
dhermes 094c071
Adding document_from_blob() factory to language client.
dhermes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,7 @@ | |
|
||
language-usage | ||
Client <language-client> | ||
language-document | ||
|
||
.. toctree:: | ||
:maxdepth: 0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Document | ||
~~~~~~~~ | ||
|
||
.. automodule:: gcloud.language.document | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# Copyright 2016 Google Inc. All Rights Reserved. | ||
# | ||
# Licensed 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. | ||
|
||
"""Definition for Google Cloud Natural Language API documents. | ||
|
||
A document is used to hold text to be analyzed and annotated. | ||
""" | ||
|
||
|
||
DEFAULT_LANGUAGE = 'en' | ||
"""Default document language, English.""" | ||
|
||
|
||
class Encoding(object): | ||
"""Document text encoding types.""" | ||
|
||
NONE = 'NONE' | ||
"""Unspecified encoding type.""" | ||
|
||
UTF8 = 'UTF8' | ||
"""UTF-8 encoding type.""" | ||
|
||
UTF16 = 'UTF16' | ||
"""UTF-16 encoding type.""" | ||
|
||
UTF32 = 'UTF32' | ||
"""UTF-32 encoding type.""" | ||
|
||
|
||
class Document(object): | ||
"""Document to send to Google Cloud Natural Language API. | ||
|
||
Represents either plain text or HTML, and the content is either | ||
stored on the document or referred to in a Google Cloud Storage | ||
object. | ||
|
||
:type client: :class:`~gcloud.language.client.Client` | ||
:param client: A client which holds credentials and project | ||
configuration. | ||
|
||
:type content: str | ||
:param content: (Optional) The document text content (either plain | ||
text or HTML). | ||
|
||
:type gcs_url: str | ||
:param gcs_url: (Optional) The URL of the Google Cloud Storage object | ||
holding the content. Of the form | ||
``gs://{bucket}/{blob-name}``. | ||
|
||
:type doc_type: str | ||
:param doc_type: (Optional) The type of text in the document. | ||
Defaults to plain text. Can be one of | ||
:attr:`~.Document.PLAIN_TEXT` or | ||
or :attr:`~.Document.HTML`. | ||
|
||
:type language: str | ||
:param language: (Optional) The language of the document text. | ||
Defaults to :data:`DEFAULT_LANGUAGE`. | ||
|
||
:type encoding: str | ||
:param encoding: (Optional) The encoding of the document text. | ||
Defaults to UTF-8. Can be one of | ||
:attr:`~.Encoding.UTF8`, :attr:`~.Encoding.UTF16` | ||
or :attr:`~.Encoding.UTF32`. | ||
|
||
:raises: :class:`~exceptions.ValueError` both ``content`` and ``gcs_url`` | ||
are specified or if neither are specified. | ||
""" | ||
|
||
TYPE_UNSPECIFIED = 'TYPE_UNSPECIFIED' | ||
"""Unspecified document type.""" | ||
|
||
PLAIN_TEXT = 'PLAIN_TEXT' | ||
"""Plain text document type.""" | ||
|
||
HTML = 'HTML' | ||
"""HTML document type.""" | ||
|
||
def __init__(self, client, content=None, gcs_url=None, doc_type=PLAIN_TEXT, | ||
language=DEFAULT_LANGUAGE, encoding=Encoding.UTF8): | ||
if content is not None and gcs_url is not None: | ||
raise ValueError('A Document cannot contain both local text and ' | ||
'a link to text in a Google Cloud Storage object') | ||
if content is None and gcs_url is None: | ||
raise ValueError('A Document must contain either local text or a ' | ||
'link to text in a Google Cloud Storage object') | ||
self.client = client | ||
self.content = content | ||
self.gcs_url = gcs_url | ||
self.doc_type = doc_type | ||
self.language = language | ||
self.encoding = encoding |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
Sorry, something went wrong.