Skip to content
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

Adding usage doc for Natural Language API. #2062

Merged
merged 1 commit into from
Aug 23, 2016

Conversation

dhermes
Copy link
Contributor

@dhermes dhermes commented Aug 8, 2016

/cc @omaray are you in the org yet (I can't assign you to this PR)

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Aug 8, 2016
and each method uses a `Document`_ for representing text. To
create a :class:`~gcloud.language.document.Document`,

.. code-block:: python

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@tseaver
Copy link
Contributor

tseaver commented Aug 8, 2016

A couple of more general questions:

  • Shouldn't this PR (and subsequent implementation PRs) target a natural-language-feature branch?
  • Should we be packaging up the JSON results for the three APIs into objects?

app. You can analyze text uploaded in your request or integrate
with your document storage on Google Cloud Storage.

This is a Beta release of Google Cloud Natural Language API. This

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor Author

dhermes commented Aug 17, 2016

@tseaver Can you weigh in here on which response values you think we should wrap?

@elibixby
Copy link

@jerjou Can you take a look to make sure we have someone who has used the API a bit to comment on usability.

@tseaver
Copy link
Contributor

tseaver commented Aug 18, 2016

Can you weigh in here on which response values you think we should wrap?

For analyze_entities, we could return instances of a (putative) Entity class:

for entity in document.analyze_entities():
    build_entity_link(entity.name, entity.type, entity.url)

For analyze_sentiment, we could return a (putative) Sentiment instance:

def by_sentiment(document):
    """Sort key:  rank from most negative to most positive."""
    sentiment = document.analyze_sentiment()
    return sentiment.polarity * sentiment.magnitude

ranked = sorted(documents, key=by_sentiment)

For annotate_text, (assuming we have flags to disable unwanted features):

only_syntax = document.annotate_text(
    include_entities=False, include_sentiment=False)

assert only_syntax.entities is None
assert only_syntax.sentiment is None

tree = ParseTree()  # imagined class w/ 'add_token' method.

for index, token in enumerate(only_syntax.tokens):
    edge = token.dependency_edge
    tree.add_token(
        index, token.lemma, token.part_of_speech, edge.head_index, edge.label)

>>> document = client.document(text_content)

By default, the document's language and type are English and
plain text:

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@tseaver
Copy link
Contributor

tseaver commented Aug 22, 2016

LGTM.

@dhermes
Copy link
Contributor Author

dhermes commented Aug 22, 2016

@jgeewax In the interest of keeping this PR from reaching 15 days of age, I'll merge with @tseaver's LGTM and we can address after the fact as the API develops (it's a small surface area so it won't be overwhelming).

@dhermes dhermes force-pushed the language-usage-doc branch from cdb4adf to d36ad4d Compare August 23, 2016 00:29
@dhermes dhermes merged commit 9a6bf7f into googleapis:master Aug 23, 2016
@dhermes dhermes deleted the language-usage-doc branch August 23, 2016 01:32
.. code-block:: python

>>> client = language.Client(language='es',
... encoding=encoding=language.Encoding.UTF16)

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@dhermes dhermes mentioned this pull request Sep 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants