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

Introduce Natural Language API #1440

Merged
merged 11 commits into from
Aug 8, 2016

Conversation

stephenplusplus
Copy link
Contributor

@stephenplusplus stephenplusplus commented Jul 18, 2016

Upstream API docs:

Docs preview:

To Dos

  • Use modularized format from Allow individually publishable API client libraries. #1431
  • Enable API for Travis account
  • Add API to toc.json
  • Create new language folder with .gitkeep
  • Use gRPC
  • Add user agent
  • Docs
    • JSDocs
    • readme
  • System tests
    • HTML input
      • Inline annotation & detection
      • GCS file annotation & detection
    • Text input
      • Inline annotation & detection
      • GCS file annotation & detection
    • Unknown input
      • Inline annotation & detection
      • GCS file annotation & detection
  • Unit tests
    • lib/index.js
    • lib/language/document.js
    • lib/language/index.js

@googlebot googlebot added the cla: yes This human has signed the Contributor License Agreement. label Jul 18, 2016
@stephenplusplus
Copy link
Contributor Author

@callmehiphop let me know what you think of the usability. Ready to start on tests after.

@callmehiphop
Copy link
Contributor

Could you throw up a gist or something of more code examples? Or is the README example all there is to it?

@stephenplusplus
Copy link
Contributor Author

README + system tests is all for now. It's not a very big API, just 3 methods. I did fail to mention there's a verbose mode for each method call.

The two primary ways of calling are

// inline
language.detectEntities('a sentence', function(err, entities) {});

// with a document
var document = language.detectEntities('a sentence');
document.detectEntities(function(err, entities) {});

The verbose mode just makes less simplifications. These tests show what the general responses look like in simple/verbose mode for each annotation type (annotation, entities, sentiment): https://github.com/stephenplusplus/gcloud-node/blob/spp--language/system-test/language.js#L314

LMKIYHAQ

@callmehiphop
Copy link
Contributor

I see, is there a reason we only provide convenience methods for entities and sentiment? Where as your readme example shows tokens, language and sentences as well.

@stephenplusplus
Copy link
Contributor Author

There are only 3 API endpoints, see https://cloud.google.com/natural-language/reference/rest/v1beta1/documents:

  • analyzeEntities (detectEntities)
  • analyzeSentiment (detectSentiment)
  • annotateText (annotate)

@stephenplusplus
Copy link
Contributor Author

We can add things like detectSentences() and detectTokens(), it would just be plucking out only part of the annotate() response. It might end up with users thinking they have to run both functions to get both types of annotations. WDYT?

@callmehiphop
Copy link
Contributor

We can add things like detectSentences() and detectTokens(), it would just be plucking out only part of the annotate() response.

We took this exact approach with the vision api, did we not? Granted the vision annotate() response has more data in it, convenience methods sorta seem like one of the big reasons why gcloud-node exists, no?

It might end up with users thinking they have to run both functions to get both types of annotations.

Can't this be prevented with documentation? Stating that it's a convenience method for annotate()?

@stephenplusplus
Copy link
Contributor Author

We took this exact approach with the vision api, did we not?

No, the Vision API has one API method that returns a response that matches the type of request you send. So we have detectFaces, which makes a request that asks for facial detection, so the response only includes facial detections.

convenience methods sorta seem like one of the big reasons why gcloud-node exists, no?

What we're talking about here is making a request that includes a lot of info, but only returning a part of it. I can see both sides here, however this is new territory for us. I feel conflicted because we would essentially be throwing away information. Docs can help, but a user simply seeing methods called detectTokens and detectSentences will make them think these each have to be called to get those types of detections.

@callmehiphop
Copy link
Contributor

No, the Vision API has one API method that returns a response that matches the type of request you send. So we have detectFaces, which makes a request that asks for facial detection, so the response only includes facial detections.

Ah, my mistake. Fair enough then, feel free to ignore!

@@ -701,6 +702,71 @@ vision.detectFaces('./image.jpg', function(err, faces) {
```


## Google Cloud Natural Language (Alpha)

> **This is an Alpha release of Google Cloud Resource Manager.** This feature is not covered by any SLA or deprecation policy and may be subject to backward-incompatible changes.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor Author

@stephenplusplus
Copy link
Contributor Author

All tested and doc'd @callmehiphop. PTAL when you can.

@googlebot googlebot added cla: no This human has *not* signed the Contributor License Agreement. and removed cla: yes This human has signed the Contributor License Agreement. labels Aug 2, 2016
@stephenplusplus
Copy link
Contributor Author

@jmuk -- I rebased this PR against @jmdobry's modularization PR. That is still in development, but it will hopefully merge soon. You can use the new structure to get started with #1464. If the changes you make can be limited to just creating files, as opposed to amending the files in packages/language, that should make it pretty safe in regards to avoiding conflicts.

You will need to run these commands when setting up the repo:

$ ./scripts/link.sh
$ cd packages/language
$ npm install

# good to go-- helpful development commands:
$ npm run lint
$ npm run test
$ npm run system-test

@callmehiphop sorry for the huge PR now... all of the language changes for review are here: https://github.com/stephenplusplus/gcloud-node/tree/spp--language/packages/language

@stephenplusplus stephenplusplus added api: language Issues related to the Cloud Natural Language API API. and removed don't merge labels Aug 2, 2016
@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Aug 4, 2016
@stephenplusplus
Copy link
Contributor Author

@jmuk @callmehiphop -- I rebased this off of master now.

@stephenplusplus stephenplusplus force-pushed the spp--language branch 2 times, most recently from 41fd353 to 84d255c Compare August 4, 2016 20:15
// Authorizing on a per-API-basis. You don't need to do this if you auth on a
// global basis (see Authorization section above).

var languageClient = language({

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@coveralls
Copy link

coveralls commented Aug 5, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling ecfbeda on stephenplusplus:spp--language into 143f120 on GoogleCloudPlatform:master.

@stephenplusplus
Copy link
Contributor Author

@callmehiphop anything left for me to do here?

Document.formatTokens_ = util.noop;
});

it('should return the language and syntax by default', function(done) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@callmehiphop
Copy link
Contributor

@stephenplusplus I had a couple small comments, but nothing really important. I think overall it looks good, my only real complaint is that the system tests were a little tricky to work through.

@stephenplusplus
Copy link
Contributor Author

Yeah, the system tests have a unique style for sure. If it gets to be impossible to deal with when adding new features/debugging, we can look into changing that.

PTAL!

});
});

it('should return the syntax by default', function(done) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@coveralls
Copy link

coveralls commented Aug 8, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling 3be25bc on stephenplusplus:spp--language into b6433a1 on GoogleCloudPlatform:master.

@@ -287,7 +287,7 @@ describe('Document', function() {
Document.formatTokens_ = util.noop;
});

it('should return the language by default', function(done) {
it('should return language if no features are requested', function(done) {

This comment was marked as spam.

This comment was marked as spam.

@coveralls
Copy link

coveralls commented Aug 8, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling f007c7e on stephenplusplus:spp--language into b6433a1 on GoogleCloudPlatform:master.

@coveralls
Copy link

coveralls commented Aug 8, 2016

Coverage Status

Coverage remained the same at 100.0% when pulling f007c7e on stephenplusplus:spp--language into b6433a1 on GoogleCloudPlatform:master.

@callmehiphop callmehiphop merged commit 00957c3 into googleapis:master Aug 8, 2016
stephenplusplus added a commit to stephenplusplus/gcloud-node that referenced this pull request Aug 23, 2016
sofisl pushed a commit that referenced this pull request Oct 11, 2022
sofisl pushed a commit that referenced this pull request Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: language Issues related to the Cloud Natural Language API API. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants