diff --git a/packages/google-cloud-language/README.rst b/packages/google-cloud-language/README.rst index db07a7c41874..d4a971b65a67 100644 --- a/packages/google-cloud-language/README.rst +++ b/packages/google-cloud-language/README.rst @@ -1,15 +1,28 @@ Python Client for Google Cloud Natural Language =============================================== - Python idiomatic client for `Google Cloud Natural Language`_ - -.. _Google Cloud Natural Language: https://cloud.google.com/natural-language/ - |pypi| |versions| -- `Documentation`_ +The `Google Cloud Natural Language`_ API can be used to reveal the +structure and meaning of text via powerful machine +learning models. You can use it to extract information about +people, places, events and much more, mentioned in text documents, +news articles or blog posts. You can use it to understand +sentiment about your product on social media or parse intent from +customer conversations happening in a call center or a messaging +app. You can analyze text uploaded in your request or integrate +with your document storage on Google Cloud Storage. -.. _Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/language/usage.html +- `Client Library Documentation`_ +- `Product Documentation`_ + +.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-language.svg + :target: https://pypi.org/project/google-cloud-language/ +.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-language.svg + :target: https://pypi.org/project/google-cloud-language/ +.. _Google Cloud Natural Language: https://cloud.google.com/natural-language/ +.. _Product Documentation: https://cloud.google.com/language/docs +.. _Client Library Documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/language/index.html .. note:: @@ -19,44 +32,60 @@ Python Client for Google Cloud Natural Language Quick Start ----------- -.. code-block:: console +In order to use this library, you first need to go through the following steps: - $ pip install --upgrade google-cloud-language - $ # OR - $ pip install --upgrade google-cloud-natural-language +1. `Select or create a Cloud Platform project.`_ +2. `Enable billing for your project.`_ +3. `Enable the Google Cloud Language API.`_ +4. `Setup Authentication.`_ -For more information on setting up your Python development environment, -such as installing ``pip`` and on your system, please refer to -`Python Development Environment Setup Guide`_ for Google Cloud Platform. +.. _Select or create a Cloud Platform project.: https://console.cloud.google.com/project +.. _Enable billing for your project.: https://cloud.google.com/billing/docs/how-to/modify-project#enable_billing_for_a_project +.. _Enable the Google Cloud Language API.: https://cloud.google.com/natural-language +.. _Setup Authentication.: https://googlecloudplatform.github.io/google-cloud-python/latest/core/auth.html -.. _Python Development Environment Setup Guide: https://cloud.google.com/python/setup +Installation +~~~~~~~~~~~~ -Authentication --------------- +Install this library in a `virtualenv`_ using pip. `virtualenv`_ is a tool to +create isolated Python environments. The basic problem it addresses is one of +dependencies and versions, and indirectly permissions. -With ``google-cloud-python`` we try to make authentication as painless as -possible. Check out the `Authentication section`_ in our documentation to -learn more. You may also find the `authentication document`_ shared by all -the ``google-cloud-*`` libraries to be helpful. +With `virtualenv`_, it's possible to install this library without needing system +install permissions, and without clashing with the installed system +dependencies. -.. _Authentication section: https://google-cloud-python.readthedocs.io/en/latest/core/auth.html -.. _authentication document: https://github.com/GoogleCloudPlatform/google-cloud-common/tree/master/authentication +.. _`virtualenv`: https://virtualenv.pypa.io/en/latest/ -Using the API -------------- -The Google Cloud `Natural Language`_ API (`Natural Language API docs`_) -provides natural language understanding technologies to developers, -including sentiment analysis, entity recognition, and syntax analysis. -This API is part of the larger Cloud Machine Learning API. +Mac/Linux +^^^^^^^^^ -.. _Natural Language: https://cloud.google.com/natural-language/ -.. _Natural Language API docs: https://cloud.google.com/natural-language/reference/rest/ +.. code-block:: console -See the ``google-cloud-python`` API Natural Language `Documentation`_ to learn -how to analyze text with this API. + pip install virtualenv + virtualenv + source /bin/activate + /bin/pip install google-cloud-language -.. |pypi| image:: https://img.shields.io/pypi/v/google-cloud-language.svg - :target: https://pypi.org/project/google-cloud-language/ -.. |versions| image:: https://img.shields.io/pypi/pyversions/google-cloud-language.svg - :target: https://pypi.org/project/google-cloud-language/ + +Windows +^^^^^^^ + +.. code-block:: console + + pip install virtualenv + virtualenv + \Scripts\activate + \Scripts\pip.exe install google-cloud-language + + +Next Steps +~~~~~~~~~~ + +- Read the `Usage documentation`_ for the language client + to see available methods on the client. +- Read the `Product documentation`_ to learn + more about the product and see How-to Guides. + +.. _Usage documentation: https://googlecloudplatform.github.io/google-cloud-python/latest/language/usage.html diff --git a/packages/google-cloud-language/docs/api.rst b/packages/google-cloud-language/docs/api.rst new file mode 100644 index 000000000000..4d7146159b1a --- /dev/null +++ b/packages/google-cloud-language/docs/api.rst @@ -0,0 +1,30 @@ +Language Client API Reference +============================= + +This package includes clients for multiple versions of the Natural Language +API. By default, you will get ``v1``, the latest GA version. + +.. toctree:: + :maxdepth: 2 + + gapic/v1/api + gapic/v1/types + +If you are interested in beta features ahead of the latest GA, you may +opt-in to the v1.1 beta, which is spelled ``v1beta2``. In order to do this, +you will want to import from ``google.cloud.language_v1beta2`` in lieu of +``google.cloud.language``. + +An API and type reference is provided for the v1.1 beta also: + +.. toctree:: + :maxdepth: 2 + + gapic/v1beta2/api + gapic/v1beta2/types + +.. note:: + + The client for the beta API is provided on a provisional basis. The API + surface is subject to change, and it is possible that this client will be + deprecated or removed after its features become GA. diff --git a/packages/google-cloud-language/docs/changelog.md b/packages/google-cloud-language/docs/changelog.md new file mode 120000 index 000000000000..04c99a55caae --- /dev/null +++ b/packages/google-cloud-language/docs/changelog.md @@ -0,0 +1 @@ +../CHANGELOG.md \ No newline at end of file diff --git a/packages/google-cloud-language/docs/conf.py b/packages/google-cloud-language/docs/conf.py new file mode 100644 index 000000000000..ad6af1f51564 --- /dev/null +++ b/packages/google-cloud-language/docs/conf.py @@ -0,0 +1,317 @@ +# -*- coding: utf-8 -*- +# +# google-cloud-language documentation build configuration file +# +# This file is execfile()d with the current directory set to its +# containing dir. +# +# Note that not all possible configuration values are present in this +# autogenerated file. +# +# All configuration values have a default; values that are commented out +# serve to show the default. + +import sys +import os +import shlex + +# If extensions (or modules to document with autodoc) are in another directory, +# add these directories to sys.path here. If the directory is relative to the +# documentation root, use os.path.abspath to make it absolute, like shown here. +sys.path.insert(0, os.path.abspath('..')) + +__version__ = '0.90.4' + +# -- General configuration ------------------------------------------------ + +# If your documentation needs a minimal Sphinx version, state it here. +#needs_sphinx = '1.0' + +# Add any Sphinx extension module names here, as strings. They can be +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom +# ones. +extensions = [ + 'sphinx.ext.autodoc', + 'sphinx.ext.autosummary', + 'sphinx.ext.doctest', + 'sphinx.ext.intersphinx', + 'sphinx.ext.coverage', + 'sphinx.ext.napoleon', + 'sphinx.ext.viewcode', +] + +# autodoc/autosummary flags +autoclass_content = 'both' +autodoc_default_flags = ['members'] +autosummary_generate = True + +# Add any paths that contain templates here, relative to this directory. +templates_path = ['_templates'] + +# Allow markdown includes (so releases.md can include CHANGLEOG.md) +# http://www.sphinx-doc.org/en/master/markdown.html +source_parsers = { + '.md': 'recommonmark.parser.CommonMarkParser', +} + +# The suffix(es) of source filenames. +# You can specify multiple suffix as a list of string: +# source_suffix = ['.rst', '.md'] +source_suffix = '.rst' + +# The encoding of source files. +#source_encoding = 'utf-8-sig' + +# The master toctree document. +master_doc = 'index' + +# General information about the project. +project = u'google-cloud-language' +copyright = u'2017, Google' +author = u'Google APIs' + +# The version info for the project you're documenting, acts as replacement for +# |version| and |release|, also used in various other places throughout the +# built documents. +# +# The full version, including alpha/beta/rc tags. +release = __version__ +# The short X.Y version. +version = '.'.join(release.split('.')[0:2]) + +# The language for content autogenerated by Sphinx. Refer to documentation +# for a list of supported languages. +# +# This is also used if you do content translation via gettext catalogs. +# Usually you set "language" from the command line for these cases. +language = None + +# There are two options for replacing |today|: either, you set today to some +# non-false value, then it is used: +#today = '' +# Else, today_fmt is used as the format for a strftime call. +#today_fmt = '%B %d, %Y' + +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = ['_build'] + +# The reST default role (used for this markup: `text`) to use for all +# documents. +#default_role = None + +# If true, '()' will be appended to :func: etc. cross-reference text. +#add_function_parentheses = True + +# If true, the current module name will be prepended to all description +# unit titles (such as .. function::). +#add_module_names = True + +# If true, sectionauthor and moduleauthor directives will be shown in the +# output. They are ignored by default. +#show_authors = False + +# The name of the Pygments (syntax highlighting) style to use. +pygments_style = 'sphinx' + +# A list of ignored prefixes for module index sorting. +#modindex_common_prefix = [] + +# If true, keep warnings as "system message" paragraphs in the built documents. +#keep_warnings = False + +# If true, `todo` and `todoList` produce output, else they produce nothing. +todo_include_todos = True + +# -- Options for HTML output ---------------------------------------------- + +# The theme to use for HTML and HTML Help pages. See the documentation for +# a list of builtin themes. +html_theme = 'alabaster' + +# Theme options are theme-specific and customize the look and feel of a theme +# further. For a list of options available for each theme, see the +# documentation. +#html_theme_options = {} + +# Add any paths that contain custom themes here, relative to this directory. +#html_theme_path = [] + +# The name for this set of Sphinx documents. If None, it defaults to +# " v documentation". +#html_title = None + +# A shorter title for the navigation bar. Default is the same as html_title. +#html_short_title = None + +# The name of an image file (relative to this directory) to place at the top +# of the sidebar. +#html_logo = None + +# The name of an image file (within the static path) to use as favicon of the +# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 +# pixels large. +#html_favicon = None + +# Add any paths that contain custom static files (such as style sheets) here, +# relative to this directory. They are copied after the builtin static files, +# so a file named "default.css" will overwrite the builtin "default.css". +# html_static_path = [] + +# Add any extra paths that contain custom files (such as robots.txt or +# .htaccess) here, relative to this directory. These files are copied +# directly to the root of the documentation. +#html_extra_path = [] + +# If not '', a 'Last updated on:' timestamp is inserted at every page bottom, +# using the given strftime format. +#html_last_updated_fmt = '%b %d, %Y' + +# If true, SmartyPants will be used to convert quotes and dashes to +# typographically correct entities. +#html_use_smartypants = True + +# Custom sidebar templates, maps document names to template names. +#html_sidebars = {} + +# Additional templates that should be rendered to pages, maps page names to +# template names. +#html_additional_pages = {} + +# If false, no module index is generated. +#html_domain_indices = True + +# If false, no index is generated. +#html_use_index = True + +# If true, the index is split into individual pages for each letter. +#html_split_index = False + +# If true, links to the reST sources are added to the pages. +#html_show_sourcelink = True + +# If true, "Created using Sphinx" is shown in the HTML footer. Default is True. +#html_show_sphinx = True + +# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True. +#html_show_copyright = True + +# If true, an OpenSearch description file will be output, and all pages will +# contain a tag referring to it. The value of this option must be the +# base URL from which the finished HTML is served. +#html_use_opensearch = '' + +# This is the file name suffix for HTML files (e.g. ".xhtml"). +#html_file_suffix = None + +# Language to be used for generating the HTML full-text search index. +# Sphinx supports the following languages: +# 'da', 'de', 'en', 'es', 'fi', 'fr', 'hu', 'it', 'ja' +# 'nl', 'no', 'pt', 'ro', 'ru', 'sv', 'tr' +#html_search_language = 'en' + +# A dictionary with options for the search language support, empty by default. +# Now only 'ja' uses this config value +#html_search_options = {'type': 'default'} + +# The name of a javascript file (relative to the configuration directory) that +# implements a search results scorer. If empty, the default will be used. +#html_search_scorer = 'scorer.js' + +# Output file base name for HTML help builder. +htmlhelp_basename = 'google-cloud-language-doc' + +# -- Options for LaTeX output --------------------------------------------- + +latex_elements = { + # The paper size ('letterpaper' or 'a4paper'). + #'papersize': 'letterpaper', + + # The font size ('10pt', '11pt' or '12pt'). + #'pointsize': '10pt', + + # Additional stuff for the LaTeX preamble. + #'preamble': '', + + # Latex figure (float) alignment + #'figure_align': 'htbp', +} + +# Grouping the document tree into LaTeX files. List of tuples +# (source start file, target name, title, +# author, documentclass [howto, manual, or own class]). +latex_documents = [ + (master_doc, 'google-cloud-language.tex', + u'google-cloud-language Documentation', author, 'manual'), +] + +# The name of an image file (relative to this directory) to place at the top of +# the title page. +#latex_logo = None + +# For "manual" documents, if this is true, then toplevel headings are parts, +# not chapters. +#latex_use_parts = False + +# If true, show page references after internal links. +#latex_show_pagerefs = False + +# If true, show URL addresses after external links. +#latex_show_urls = False + +# Documents to append as an appendix to all manuals. +#latex_appendices = [] + +# If false, no module index is generated. +#latex_domain_indices = True + +# -- Options for manual page output --------------------------------------- + +# One entry per manual page. List of tuples +# (source start file, name, description, authors, manual section). +man_pages = [(master_doc, 'google-cloud-language', + u'google-cloud-language Documentation', [author], 1)] + +# If true, show URL addresses after external links. +#man_show_urls = False + +# -- Options for Texinfo output ------------------------------------------- + +# Grouping the document tree into Texinfo files. List of tuples +# (source start file, target name, title, author, +# dir menu entry, description, category) +texinfo_documents = [ + (master_doc, 'google-cloud-language', + u'google-cloud-language Documentation', author, 'google-cloud-language', + 'GAPIC library for the {metadata.shortName} v1 service', 'APIs'), +] + +# Documents to append as an appendix to all manuals. +#texinfo_appendices = [] + +# If false, no module index is generated. +#texinfo_domain_indices = True + +# How to display URL addresses: 'footnote', 'no', or 'inline'. +#texinfo_show_urls = 'footnote' + +# If true, do not generate a @detailmenu in the "Top" node's menu. +#texinfo_no_detailmenu = False + +# Example configuration for intersphinx: refer to the Python standard library. +intersphinx_mapping = { + 'python': ('http://python.readthedocs.org/en/latest/', None), + 'gax': ('https://gax-python.readthedocs.org/en/latest/', None), +} + +# Napoleon settings +napoleon_google_docstring = True +napoleon_numpy_docstring = True +napoleon_include_private_with_doc = False +napoleon_include_special_with_doc = True +napoleon_use_admonition_for_examples = False +napoleon_use_admonition_for_notes = False +napoleon_use_admonition_for_references = False +napoleon_use_ivar = False +napoleon_use_param = True +napoleon_use_rtype = True diff --git a/packages/google-cloud-language/docs/gapic/v1/api.rst b/packages/google-cloud-language/docs/gapic/v1/api.rst new file mode 100644 index 000000000000..2c5fd4fd76ea --- /dev/null +++ b/packages/google-cloud-language/docs/gapic/v1/api.rst @@ -0,0 +1,6 @@ +Natural Language Client API +=========================== + +.. automodule:: google.cloud.language_v1 + :members: + :inherited-members: diff --git a/packages/google-cloud-language/docs/gapic/v1/types.rst b/packages/google-cloud-language/docs/gapic/v1/types.rst new file mode 100644 index 000000000000..90d27a4b96fb --- /dev/null +++ b/packages/google-cloud-language/docs/gapic/v1/types.rst @@ -0,0 +1,5 @@ +Natural Language Client Types +============================= + +.. automodule:: google.cloud.language_v1.types + :members: diff --git a/packages/google-cloud-language/docs/gapic/v1beta2/api.rst b/packages/google-cloud-language/docs/gapic/v1beta2/api.rst new file mode 100644 index 000000000000..330d7e6e7a78 --- /dev/null +++ b/packages/google-cloud-language/docs/gapic/v1beta2/api.rst @@ -0,0 +1,6 @@ +Natural Language Beta Client API +================================ + +.. automodule:: google.cloud.language_v1beta2 + :members: + :inherited-members: diff --git a/packages/google-cloud-language/docs/gapic/v1beta2/types.rst b/packages/google-cloud-language/docs/gapic/v1beta2/types.rst new file mode 100644 index 000000000000..d9a7eb171f00 --- /dev/null +++ b/packages/google-cloud-language/docs/gapic/v1beta2/types.rst @@ -0,0 +1,5 @@ +Natural Language Beta Client Types +================================== + +.. automodule:: google.cloud.language_v1beta2.types + :members: diff --git a/packages/google-cloud-language/docs/index.rst b/packages/google-cloud-language/docs/index.rst new file mode 100644 index 000000000000..b1fb79481486 --- /dev/null +++ b/packages/google-cloud-language/docs/index.rst @@ -0,0 +1,9 @@ +.. include:: /../language/README.rst + + +.. toctree:: + :maxdepth: 2 + + usage + api + changelog diff --git a/packages/google-cloud-language/docs/usage.rst b/packages/google-cloud-language/docs/usage.rst new file mode 100644 index 000000000000..add76f5a8a50 --- /dev/null +++ b/packages/google-cloud-language/docs/usage.rst @@ -0,0 +1,199 @@ +Using the Language Client +========================= + +Documents +********* + +The Google Natural Language API has the following supported methods: + +- `analyzeEntities`_ +- `analyzeSentiment`_ +- `analyzeEntitySentiment`_ +- `annotateText`_ +- `classifyText`_ + +and each method uses a :class:`~.language_v1.types.Document` for representing +text. + + .. code-block:: python + + >>> document = language.types.Document( + ... content='Google, headquartered in Mountain View, unveiled the ' + ... 'new Android phone at the Consumer Electronic Show. ' + ... 'Sundar Pichai said in his keynote that users love ' + ... 'their new Android phones.', + ... language='en', + ... type='PLAIN_TEXT', + ... ) + + +The document's language defaults to ``None``, which will cause the API to +auto-detect the language. + +In addition, you can construct an HTML document: + + .. code-block:: python + + >>> html_content = """\ + ... + ... + ... El Tiempo de las Historias</time> + ... </head> + ... <body> + ... <p>La vaca saltó sobre la luna.</p> + ... </body> + ... </html> + ... """ + >>> document = language.types.Document( + ... content=html_content, + ... language='es', + ... type='HTML', + ... ) + +The ``language`` argument can be either ISO-639-1 or BCP-47 language +codes. The API reference page contains the full list of `supported languages`_. + +.. _supported languages: https://cloud.google.com/natural-language/docs/languages + + +In addition to supplying the text / HTML content, a document can refer +to content stored in `Google Cloud Storage`_. + + .. code-block:: python + + >>> document = language.types.Document( + ... gcs_content_uri='gs://my-text-bucket/sentiment-me.txt', + ... type=language.enums.HTML, + ... ) + +.. _analyzeEntities: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntities +.. _analyzeSentiment: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeSentiment +.. _analyzeEntitySentiment: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntitySentiment +.. _annotateText: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/annotateText +.. _classifyText: https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/classifyText +.. _Google Cloud Storage: https://cloud.google.com/storage/ + +Analyze Entities +**************** + +The :meth:`~.language_v1.LanguageServiceClient.analyze_entities` +method finds named entities (i.e. proper names) in the text. This method +returns a :class:`~.language_v1.types.AnalyzeEntitiesResponse`. + + .. code-block:: python + + >>> document = language.types.Document( + ... content='Michelangelo Caravaggio, Italian painter, is ' + ... 'known for "The Calling of Saint Matthew".', + ... type=language.enums.Document.Type.PLAIN_TEXT, + ... ) + >>> response = client.analyze_entities( + ... document=document, + ... encoding_type='UTF32', + ... ) + >>> for entity in response.entities: + ... print('=' * 20) + ... print(' name: {0}'.format(entity.name)) + ... print(' type: {0}'.format(entity.entity_type)) + ... print(' metadata: {0}'.format(entity.metadata)) + ... print(' salience: {0}'.format(entity.salience)) + ==================== + name: Michelangelo Caravaggio + type: PERSON + metadata: {'wikipedia_url': 'https://en.wikipedia.org/wiki/Caravaggio'} + salience: 0.7615959 + ==================== + name: Italian + type: LOCATION + metadata: {'wikipedia_url': 'https://en.wikipedia.org/wiki/Italy'} + salience: 0.19960518 + ==================== + name: The Calling of Saint Matthew + type: EVENT + metadata: {'wikipedia_url': 'https://en.wikipedia.org/wiki/The_Calling_of_St_Matthew_(Caravaggio)'} + salience: 0.038798928 + +.. note:: + + It is recommended to send an ``encoding_type`` argument to Natural + Language methods, so they provide useful offsets for the data they return. + While the correct value varies by environment, in Python you *usually* + want ``UTF32``. + + +Analyze Sentiment +***************** + +The :meth:`~.language_v1.LanguageServiceClient.analyze_sentiment` method +analyzes the sentiment of the provided text. This method returns a +:class:`~.language_v1.types.AnalyzeSentimentResponse`. + + .. code-block:: python + + >>> document = language.types.Document( + ... content='Jogging is not very fun.', + ... type='PLAIN_TEXT', + ... ) + >>> response = client.analyze_sentiment( + ... document=document, + ... encoding_type='UTF32', + ... ) + >>> sentiment = response.document_sentiment + >>> print(sentiment.score) + -1 + >>> print(sentiment.magnitude) + 0.8 + +.. note:: + + It is recommended to send an ``encoding_type`` argument to Natural + Language methods, so they provide useful offsets for the data they return. + While the correct value varies by environment, in Python you *usually* + want ``UTF32``. + + +Analyze Entity Sentiment +************************ + +The :meth:`~.language_v1.LanguageServiceClient.analyze_entity_sentiment` +method is effectively the amalgamation of +:meth:`~.language_v1.LanguageServiceClient.analyze_entities` and +:meth:`~.language_v1.LanguageServiceClient.analyze_sentiment`. +This method returns a +:class:`~.language_v1.types.AnalyzeEntitySentimentResponse`. + +.. code-block:: python + + >>> document = language.types.Document( + ... content='Mona said that jogging is very fun.', + ... type='PLAIN_TEXT', + ... ) + >>> response = client.analyze_entity_sentiment( + ... document=document, + ... encoding_type='UTF32', + ... ) + >>> entities = response.entities + >>> entities[0].name + 'Mona' + >>> entities[1].name + 'jogging' + >>> entities[1].sentiment.magnitude + 0.8 + >>> entities[1].sentiment.score + 0.8 + +.. note:: + + It is recommended to send an ``encoding_type`` argument to Natural + Language methods, so they provide useful offsets for the data they return. + While the correct value varies by environment, in Python you *usually* + want ``UTF32``. + + +Annotate Text +************* + +The :meth:`~.language_v1.LanguageServiceClient.annotate_text` method +analyzes a document and is intended for users who are familiar with +machine learning and need in-depth text features to build upon. This method +returns a :class:`~.language_v1.types.AnnotateTextResponse`.