From 5af4c4c10e49cc0f70aec46674efdb32b9747813 Mon Sep 17 00:00:00 2001 From: Luke Sneeringer Date: Fri, 13 Oct 2017 09:32:24 -0700 Subject: [PATCH] Migrate to the nodejs-language repo. (#7) --- packages/google-cloud-language/.appveyor.yml | 23 + .../.circleci/config.yml | 221 +++++ .../.circleci/key.json.enc | Bin 0 -> 2368 bytes .../.cloud-repo-tools.json | 23 + packages/google-cloud-language/.eslintignore | 3 + packages/google-cloud-language/.eslintrc.yml | 13 + packages/google-cloud-language/.gitignore | 10 + packages/google-cloud-language/.jsdoc.js | 45 + packages/google-cloud-language/.mailmap | 4 + packages/google-cloud-language/.nycrc | 26 + .../google-cloud-language/.prettierignore | 3 + packages/google-cloud-language/.prettierrc | 8 + .../google-cloud-language/CODE_OF_CONDUCT.md | 43 + packages/google-cloud-language/CONTRIBUTORS | 20 + packages/google-cloud-language/LICENSE | 202 ++++ packages/google-cloud-language/README.md | 163 +++- packages/google-cloud-language/package.json | 92 +- .../samples/.eslintrc.yml | 3 + .../google-cloud-language/samples/README.md | 60 +- .../samples/package.json | 50 +- .../samples/quickstart.js | 15 +- .../smoke-test/language_service_smoke_test.js | 40 - packages/google-cloud-language/src/index.js | 206 ++-- .../language/v1}/doc_language_service.js | 237 +++-- .../google-cloud-language/src/v1/index.js | 47 +- .../src/v1/language_service_client.js | 810 ++++++++-------- .../language/v1beta2}/doc_language_service.js | 252 ++--- .../src/v1beta2/index.js | 47 +- .../src/v1beta2/language_service_client.js | 905 +++++++++--------- .../system-test/.eslintrc.yml | 6 + .../language_service_smoke_test.js | 40 + .../google-cloud-language/test/.eslintrc.yml | 5 + .../google-cloud-language/test/gapic-v1.js | 211 ++-- .../test/gapic-v1beta2.js | 241 +++-- 34 files changed, 2455 insertions(+), 1619 deletions(-) create mode 100644 packages/google-cloud-language/.appveyor.yml create mode 100644 packages/google-cloud-language/.circleci/config.yml create mode 100644 packages/google-cloud-language/.circleci/key.json.enc create mode 100644 packages/google-cloud-language/.cloud-repo-tools.json create mode 100644 packages/google-cloud-language/.eslintignore create mode 100644 packages/google-cloud-language/.eslintrc.yml create mode 100644 packages/google-cloud-language/.gitignore create mode 100644 packages/google-cloud-language/.jsdoc.js create mode 100644 packages/google-cloud-language/.mailmap create mode 100644 packages/google-cloud-language/.nycrc create mode 100644 packages/google-cloud-language/.prettierignore create mode 100644 packages/google-cloud-language/.prettierrc create mode 100644 packages/google-cloud-language/CODE_OF_CONDUCT.md create mode 100644 packages/google-cloud-language/CONTRIBUTORS create mode 100644 packages/google-cloud-language/LICENSE create mode 100644 packages/google-cloud-language/samples/.eslintrc.yml delete mode 100644 packages/google-cloud-language/smoke-test/language_service_smoke_test.js rename packages/google-cloud-language/src/v1/doc/{ => google/cloud/language/v1}/doc_language_service.js (83%) rename packages/google-cloud-language/src/v1beta2/doc/{ => google/cloud/language/v1beta2}/doc_language_service.js (82%) create mode 100644 packages/google-cloud-language/system-test/.eslintrc.yml create mode 100644 packages/google-cloud-language/system-test/language_service_smoke_test.js create mode 100644 packages/google-cloud-language/test/.eslintrc.yml diff --git a/packages/google-cloud-language/.appveyor.yml b/packages/google-cloud-language/.appveyor.yml new file mode 100644 index 00000000000..babe1d587f4 --- /dev/null +++ b/packages/google-cloud-language/.appveyor.yml @@ -0,0 +1,23 @@ +environment: + matrix: + - nodejs_version: 4 + - nodejs_version: 6 + - nodejs_version: 7 + - nodejs_version: 8 + +install: + - ps: Install-Product node $env:nodejs_version + - npm install -g npm # Force using the latest npm to get dedupe during install + - set PATH=%APPDATA%\npm;%PATH% + - npm install --force --ignore-scripts + +test_script: + - node --version + - npm --version + - npm rebuild + - npm test + +build: off + +matrix: + fast_finish: true diff --git a/packages/google-cloud-language/.circleci/config.yml b/packages/google-cloud-language/.circleci/config.yml new file mode 100644 index 00000000000..286149e73b1 --- /dev/null +++ b/packages/google-cloud-language/.circleci/config.yml @@ -0,0 +1,221 @@ +--- +# "Include" for unit tests definition. +unit_tests: &unit_tests + steps: + - checkout + - run: + name: Install modules and dependencies. + command: npm install + - run: + name: Run unit tests. + command: npm test + - run: + name: Submit coverage data to codecov. + command: node_modules/.bin/codecov + when: always + +version: 2.0 +workflows: + version: 2 + tests: + jobs: + - node4: + filters: + tags: + only: /.*/ + - node6: + filters: + tags: + only: /.*/ + - node7: + filters: + tags: + only: /.*/ + - node8: + filters: + tags: + only: /.*/ + - lint: + requires: + - node4 + - node6 + - node7 + - node8 + filters: + tags: + only: /.*/ + - docs: + requires: + - node4 + - node6 + - node7 + - node8 + filters: + tags: + only: /.*/ + - system_tests: + requires: + - lint + - docs + filters: + branches: + only: master + tags: + only: /^v[\d.]+$/ + - sample_tests: + requires: + - lint + - docs + filters: + branches: + only: master + tags: + only: /^v[\d.]+$/ + - publish_npm: + requires: + - system_tests + - sample_tests + filters: + branches: + ignore: /.*/ + tags: + only: /^v[\d.]+$/ + +jobs: + node4: + docker: + - image: node:4 + steps: + - checkout + - run: + name: Install modules and dependencies. + command: npm install --unsafe-perm + - run: + name: Run unit tests. + command: npm test + - run: + name: Submit coverage data to codecov. + command: node_modules/.bin/codecov + when: always + node6: + docker: + - image: node:6 + <<: *unit_tests + node7: + docker: + - image: node:7 + <<: *unit_tests + node8: + docker: + - image: node:8 + <<: *unit_tests + + lint: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Install modules and dependencies. + command: npm install + - run: + name: Link the module being tested to the samples. + command: | + cd samples/ + npm install + npm link @google-cloud/language + cd .. + - run: + name: Run linting. + command: npm run lint + + docs: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Install modules and dependencies. + command: npm install + - run: + name: Build documentation. + command: npm run docs + + sample_tests: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Decrypt credentials. + command: | + openssl aes-256-cbc -d -in .circleci/key.json.enc \ + -out .circleci/key.json \ + -k "${SYSTEM_TESTS_ENCRYPTION_KEY}" + - run: + name: Install and link the module. + command: | + npm install + npm link + - run: + name: Link the module being tested to the samples. + command: | + cd samples/ + npm install + npm link @google-cloud/language + cd .. + - run: + name: Run sample tests. + command: npm run samples-test + environment: + GCLOUD_PROJECT: long-door-651 + GOOGLE_APPLICATION_CREDENTIALS: /var/language/.circleci/key.json + - run: + name: Remove unencrypted key. + command: rm .circleci/key.json + when: always + working_directory: /var/language/ + + system_tests: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Decrypt credentials. + command: | + openssl aes-256-cbc -d -in .circleci/key.json.enc \ + -out .circleci/key.json \ + -k "${SYSTEM_TESTS_ENCRYPTION_KEY}" + - run: + name: Decrypt second account credentials (storage-specific). + command: | + openssl aes-256-cbc -d -in .circleci/no-whitelist-key.json.enc \ + -out .circleci/no-whitelist-key.json \ + -k "${SYSTEM_TESTS_ENCRYPTION_KEY}" + - run: + name: Install modules and dependencies. + command: npm install + - run: + name: Run system tests. + command: npm run system-test + environment: + GCN_STORAGE_2ND_PROJECT_ID: gcloud-node-whitelist-ci-tests + GCN_STORAGE_2ND_PROJECT_KEY: .circleci/no-whitelist-key.json + GOOGLE_APPLICATION_CREDENTIALS: .circleci/key.json + - run: + name: Remove unencrypted key. + command: rm .circleci/key.json + when: always + + publish_npm: + docker: + - image: node:8 + steps: + - checkout + - run: + name: Set NPM authentication. + command: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc + - run: + name: Publish the module to npm. + command: npm publish diff --git a/packages/google-cloud-language/.circleci/key.json.enc b/packages/google-cloud-language/.circleci/key.json.enc new file mode 100644 index 0000000000000000000000000000000000000000..730ae94518c0c15819c83e8cf0f547eee2451167 GIT binary patch literal 2368 zcmV-G3BUGJVQh3|WM5y*ae(1-oWWBzr7s19Bs|M(Vg%#u^lkBw^mXu^+r(eIC;i6n zO0__xp@~tl4%V$>yQY-eL9Bx*`62ixv!C;2c*Etlm$iw}3@}3ff1pUXO#$yUKUg`o znxQGa9JBy*rUI>mxF&~^yNQ_*ngxVlBwb2L^{RKHCvdj;d#fLtQgIsVal-o-U%6=>vnP^=I7rE%Ar$syvYm z*>$uaCCx==J-FXupMa>7pIoG({bsCxyOXEm8jg8$m*}Zo*;26ppQiGbP4g=$1PJpG30}r#iGmq`$LEuZ2(+^=9t>e;_dyt2_zv}V# z!AKW*!nnbWq3bprLT_521zBlC3-))L{+Qh>Wfj=n*g{0SW4$K)n59;9c_UyW`|+Mn z2S}S0@&+WA8>EQl3+B;`e9ZPz!sGN)bYa_nkj2rfwZG(Ig9 z?uU--aeCH=@XGD4--!PU;=z;-RtrGO&qWIWEEkr|a3b}I4C%hGD|c^>^Tji4)RFi6 zhP9Rv*}0o46@Ry>NTs6tRMzRw|Jb&?8l)u#7F$F;St5*d3vNW;+DoIvxP-^kqkOp| z6n_MU5f&Zaya@IcXc*vckB#&u9JoD~b0YKfWz9h-r`HxcGAr`o5bC-t z16C7Si*(&ZqOh&FRw+jWM8$yMS%9R7pt}>yr{ooM(j{(Gq)T=IYrKb1iHwzYG0l2w zqrJ%eOY_N_Soo@$fb(J4iBcwBI$AJ-MXfWfxPm%$Eh|Fk7RE_f8><^E81h)B_Bl># zF)s}rS2}8^Z1|f+{t&>`ff}n9UT}r%Uc21;x?-1@zAf-nFXmEMgRaTx$U#_ke?2Qi zFsa5$$CjzYwpjU`g??F1qxWqAD>WL}B93TB_k%|?2;5Lvyky|Gxnrkc!#6%61?b>X zn5@OYbqsDm_>5%+-Xmsw0p*igHlzZtIff1OzX9n82uJqZ8-<@s`Xtmgi)bPj>5@%` zh&}#wUyx{-(p0t(m;f6W9j)Hm=#->CcOt7zYimbclULUbowDL=5W_!?pXg|6NND{) zM!+zAFN=-H)75Ci6F3wxcy z#A|;vgxZ|}PxLdW`B8RMo+>^i&p1s&2ac{d(V+ar<0_t9vV4fvo=~GqB@HmkXqlox zOG!OZVC`bW^-wVxPqqk2e)8KG=cGBh=B479)WW3FhU-~kg|j8v?}+M~4i7N>r+giQ z-~*|iH+7vCx4=Qk9bXBe@)V$H9rrRAg@@mxMcR0HPWifj4s1O5T7^;Vpcz~S&y@m< zOlL)Nw_lPA=gjiO|IEp%xaN9`JluhDOpwvo-%PC-{v9C+W#drk;|vunDsAd2P#Iv{ zl6LkGGc=XOGnB}X6kBt=OLdXUu}Y4Ao~c{x$BbEU8nX&lQ2k%3Y->O;91MJw@w!B% zWHTlH!r~7?OU3wgLp}q5fXtL7Or={Jy=z*iQA{;*=B(9Q9f=^|GDtP}Zm5HY)vea( z?ne%sQW4d~N$M7VHzV=g#1O&=!3r)urm5N{Fq`*!*Fi)Z9=U>bi8t{MxCi7J~A=qaW6smR4@(jlx(BhbBj3q42m&eZXZ=cf7HeuI6 zE}UR`336r{&0*2*Lm5xSh@hQ0rS9iemT0=E=51QoA*GXBHeda-Lp`Vn-1wPamIcY? z@N7i}wSv&3ZU}+Febl@~b$Ori%i;EFR;0J*q}!o}BiswB42o>yo!Jc;;rzQ-N-u-I zjSB^ac!@Ow+djzjdxLc>`b1Hk`Ehya#Z~zFhFeIT@riq-FQ-9k>Ydys3$o>_r4=?) z$GP_qL_pa5bmeL1zm*F~Lcm_MPhGW$EWJ4e4Q>Pk;+&O@&pY{xYPJ?{a{*| zhS`vAWNu0H!UhFMWlG7qB%V82_-(DbQ_v0r|L{DKjDA5Q>PG;4q<8O-SG%=$v^zUY zet+tUANOJMN(5RYVWDkelJ0yT$wT>#uakO74@x7zPFsZ zp>cpOUUaWP9s5UdjQTG$OPvX@+8B%MCI06ks#8cgIENS~PoTcGX$m_XR$$RmPZnU? z>KF)ahdnV6Grke(-dSY9=%->MBSVS*v9G8Y*-bz&ro^YfXZ%4>dx-hfvtK*n!M{D~UMOco*mS2jbqiLj1y9WdBSEDU;Ym2V=`9INe@g_*0axvgxb1FHzsU zS)9wKmCztFTF+-20aeGjX|fMlZlI|~u;=Ixm6Rec=((i%txB@U3sohhjD)i62gvVU m@8YEp(2E Jason Dobry +Luke Sneeringer Luke Sneeringer +Stephen Sawchuk Stephen Sawchuk +Stephen Sawchuk Stephen Sawchuk \ No newline at end of file diff --git a/packages/google-cloud-language/.nycrc b/packages/google-cloud-language/.nycrc new file mode 100644 index 00000000000..a1a8e6920ce --- /dev/null +++ b/packages/google-cloud-language/.nycrc @@ -0,0 +1,26 @@ +{ + "report-dir": "./.coverage", + "exclude": [ + "src/*{/*,/**/*}.js", + "src/*/v*/*.js", + "test/**/*.js" + ], + "watermarks": { + "branches": [ + 95, + 100 + ], + "functions": [ + 95, + 100 + ], + "lines": [ + 95, + 100 + ], + "statements": [ + 95, + 100 + ] + } +} diff --git a/packages/google-cloud-language/.prettierignore b/packages/google-cloud-language/.prettierignore new file mode 100644 index 00000000000..f6fac98b0a8 --- /dev/null +++ b/packages/google-cloud-language/.prettierignore @@ -0,0 +1,3 @@ +node_modules/* +samples/node_modules/* +src/**/doc/* diff --git a/packages/google-cloud-language/.prettierrc b/packages/google-cloud-language/.prettierrc new file mode 100644 index 00000000000..df6eac07446 --- /dev/null +++ b/packages/google-cloud-language/.prettierrc @@ -0,0 +1,8 @@ +--- +bracketSpacing: false +printWidth: 80 +semi: true +singleQuote: true +tabWidth: 2 +trailingComma: es5 +useTabs: false diff --git a/packages/google-cloud-language/CODE_OF_CONDUCT.md b/packages/google-cloud-language/CODE_OF_CONDUCT.md new file mode 100644 index 00000000000..46b2a08ea6d --- /dev/null +++ b/packages/google-cloud-language/CODE_OF_CONDUCT.md @@ -0,0 +1,43 @@ +# Contributor Code of Conduct + +As contributors and maintainers of this project, +and in the interest of fostering an open and welcoming community, +we pledge to respect all people who contribute through reporting issues, +posting feature requests, updating documentation, +submitting pull requests or patches, and other activities. + +We are committed to making participation in this project +a harassment-free experience for everyone, +regardless of level of experience, gender, gender identity and expression, +sexual orientation, disability, personal appearance, +body size, race, ethnicity, age, religion, or nationality. + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery +* Personal attacks +* Trolling or insulting/derogatory comments +* Public or private harassment +* Publishing other's private information, +such as physical or electronic +addresses, without explicit permission +* Other unethical or unprofessional conduct. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct. +By adopting this Code of Conduct, +project maintainers commit themselves to fairly and consistently +applying these principles to every aspect of managing this project. +Project maintainers who do not follow or enforce the Code of Conduct +may be permanently removed from the project team. + +This code of conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. + +Instances of abusive, harassing, or otherwise unacceptable behavior +may be reported by opening an issue +or contacting one or more of the project maintainers. + +This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, +available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) diff --git a/packages/google-cloud-language/CONTRIBUTORS b/packages/google-cloud-language/CONTRIBUTORS new file mode 100644 index 00000000000..a3d8ca46557 --- /dev/null +++ b/packages/google-cloud-language/CONTRIBUTORS @@ -0,0 +1,20 @@ +# The names of individuals who have contributed to this project. +# +# Names are formatted as: +# name +# +Ace Nassri +Amy +Dave Gramlich +Eric Uldall +Ernest Landrito +Gus Class +Jason Dobry +Jerjou +Jun Mukai +Luke Sneeringer +Ricky Dunlop +Sawyer Hollenshead +Song Wang +Stephen Sawchuk +Tim Swast diff --git a/packages/google-cloud-language/LICENSE b/packages/google-cloud-language/LICENSE new file mode 100644 index 00000000000..7a4a3ea2424 --- /dev/null +++ b/packages/google-cloud-language/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + 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. \ No newline at end of file diff --git a/packages/google-cloud-language/README.md b/packages/google-cloud-language/README.md index 0a252c3876f..1956bddebc1 100644 --- a/packages/google-cloud-language/README.md +++ b/packages/google-cloud-language/README.md @@ -1,49 +1,130 @@ -# Node.js Client for Google Cloud Natural Language API ([Beta](https://github.com/GoogleCloudPlatform/google-cloud-node#versioning)) +Google Cloud Platform logo -[Google Cloud Natural Language API][Product Documentation]: Google Cloud Natural Language API provides natural language understanding technologies to developers. Examples include sentiment analysis, entity recognition, and text annotations. -- [Client Library Documentation][] -- [Product Documentation][] +# Google Cloud Natural Language API: Node.js Client -## Quick Start -In order to use this library, you first need to go through the following steps: +[![release level](https://img.shields.io/badge/release%20level-beta-yellow.svg?style=flat)](https://cloud.google.com/terms/launch-stages) +[![CircleCI](https://img.shields.io/circleci/project/github/googleapis/nodejs-language.svg?style=flat)](https://circleci.com/gh/googleapis/nodejs-language) +[![AppVeyor](https://ci.appveyor.com/api/projects/status/github/googleapis/nodejs-language?branch=master&svg=true)](https://ci.appveyor.com/project/googleapis/nodejs-language) +[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-language/master.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-language) -1. [Select or create a Cloud Platform project.](https://console.cloud.google.com/project) -2. [Enable the Google Cloud Natural Language API.](https://console.cloud.google.com/apis/api/language) -3. [Setup Authentication.](https://googlecloudplatform.github.io/google-cloud-node/#/docs/google-cloud/master/guides/authentication) +> Node.js idiomatic client for [Natural Language API][product-docs]. -### Installation -``` -$ npm install --save @google-cloud/language -``` +[Cloud Natural Language API](https://cloud.google.com/natural-language/docs) provides natural language understanding technologies to developers, including sentiment analysis, entity analysis, and syntax analysis. This API is part of the larger Cloud Machine Learning API family. + +* [Natural Language API Node.js Client API Reference][client-docs] +* [Natural Language API Documentation][product-docs] + +Read more about the client libraries for Cloud APIs, including the older +Google APIs Client Libraries, in [Client Libraries Explained][explained]. + +[explained]: https://cloud.google.com/apis/docs/client-libraries-explained + +**Table of contents:** + +* [Quickstart](#quickstart) + * [Before you begin](#before-you-begin) + * [Installing the client library](#installing-the-client-library) + * [Using the client library](#using-the-client-library) +* [Samples](#samples) +* [Versioning](#versioning) +* [Contributing](#contributing) +* [License](#license) + +## Quickstart + +### Before you begin + +1. Select or create a Cloud Platform project. + + [Go to the projects page][projects] + +1. Enable billing for your project. + + [Enable billing][billing] + +1. Enable the Google Cloud Natural Language API API. + + [Enable the API][enable_api] + +1. [Set up authentication with a service account][auth] so you can access the + API from your local workstation. + +[projects]: https://console.cloud.google.com/project +[billing]: https://support.google.com/cloud/answer/6293499#enable-billing +[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=language.googleapis.com +[auth]: https://cloud.google.com/docs/authentication/getting-started + +### Installing the client library + + npm install --save @google-cloud/language -### Preview -#### LanguageServiceClient -```js - var language = require('@google-cloud/language'); - - var client = language({ - // optional auth parameters. - }); - - var content = 'Hello, world!'; - var type = language.v1.types.Document.Type.PLAIN_TEXT; - var document = { - content : content, - type : type - }; - client.analyzeSentiment({document: document}).then(function(responses) { - var response = responses[0]; - // doThingsWith(response) - }) - .catch(function(err) { - console.error(err); - }); +### Using the client library + +```javascript +// Imports the Google Cloud client library +const language = require('@google-cloud/language'); + +// Instantiates a client +const client = new language.LanguageServiceClient(); + +// The text to analyze +const text = 'Hello, world!'; + +const document = { + content: text, + type: 'PLAIN_TEXT', +}; + +// Detects the sentiment of the text +client + .analyzeSentiment({document: document}) + .then(results => { + const sentiment = results[0].documentSentiment; + + console.log(`Text: ${text}`); + console.log(`Sentiment score: ${sentiment.score}`); + console.log(`Sentiment magnitude: ${sentiment.magnitude}`); + }) + .catch(err => { + console.error('ERROR:', err); + }); ``` -### Next Steps -- Read the [Client Library Documentation][] for Google Cloud Natural Language API to see other available methods on the client. -- Read the [Google Cloud Natural Language API Product documentation][Product Documentation] to learn more about the product and see How-to Guides. -- View this [repository's main README](https://github.com/GoogleCloudPlatform/google-cloud-node/blob/master/README.md) to see the full list of Cloud APIs that we cover. +## Samples + +Samples are in the [`samples/`](https://github.com/blob/master/samples) directory. The samples' `README.md` +has instructions for running the samples. + +| Sample | Source Code | +| --------------------------- | --------------------------------- | +| Analyze v1 | [source code](https://github.com/googleapis/nodejs-language/blob/master/samples/analyze.v1.js) | +| Analyze v1beta2 | [source code](https://github.com/googleapis/nodejs-language/blob/master/samples/analyze.v1beta2.js) | + +The [Natural Language API Node.js Client API Reference][client-docs] documentation +also contains samples. + +## Versioning + +This library follows [Semantic Versioning](http://semver.org/). + +This library is considered to be in **beta**. This means it is expected to be +mostly stable while we work toward a general availability release; however, +complete stability is not guaranteed. We will address issues and requests +against beta libraries with a high priority. + +More Information: [Google Cloud Platform Launch Stages][launch_stages] + +[launch_stages]: https://cloud.google.com/terms/launch-stages + +## Contributing + +Contributions welcome! See the [Contributing Guide](.github/CONTRIBUTING.md). + +## License + +Apache Version 2.0 + +See [LICENSE](LICENSE) -[Client Library Documentation]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/language -[Product Documentation]: https://cloud.google.com/language \ No newline at end of file +[client-docs]: https://cloud.google.com/nodejs/docs/reference/natural-language/latest/ +[product-docs]: https://cloud.google.com/natural-language/docs diff --git a/packages/google-cloud-language/package.json b/packages/google-cloud-language/package.json index 5734a92bec7..fa90b79b970 100644 --- a/packages/google-cloud-language/package.json +++ b/packages/google-cloud-language/package.json @@ -1,40 +1,19 @@ { - "repository": "GoogleCloudPlatform/google-cloud-node", "name": "@google-cloud/language", + "description": "Google Cloud Natural Language API client for Node.js", "version": "0.12.1", + "license": "Apache-2.0", "author": "Google Inc", - "description": "Google Cloud Natural Language API client for Node.js", - "contributors": [ - { - "name": "Burcu Dogan", - "email": "jbd@google.com" - }, - { - "name": "Johan Euphrosine", - "email": "proppy@google.com" - }, - { - "name": "Patrick Costello", - "email": "pcostell@google.com" - }, - { - "name": "Ryan Seys", - "email": "ryan@ryanseys.com" - }, - { - "name": "Silvano Luciani", - "email": "silvano@google.com" - }, - { - "name": "Stephen Sawchuk", - "email": "sawchuk@gmail.com" - } - ], + "engines": { + "node": ">=4.0.0" + }, + "repository": "googleapis/nodejs-language", "main": "src/index.js", "files": [ "protos", "src", "AUTHORS", + "CONTRIBUTORS", "LICENSE" ], "keywords": [ @@ -50,20 +29,53 @@ "language", "Google Cloud Natural Language API" ], + "contributors": [ + "Ace Nassri ", + "Amy ", + "Dave Gramlich ", + "Eric Uldall ", + "Ernest Landrito ", + "Gus Class ", + "Jason Dobry ", + "Jerjou ", + "Jun Mukai ", + "Luke Sneeringer ", + "Ricky Dunlop ", + "Sawyer Hollenshead ", + "Song Wang ", + "Stephen Sawchuk ", + "Tim Swast " + ], + "scripts": { + "cover": "nyc --reporter=lcov mocha --require intelli-espower-loader test/*.js && nyc report", + "docs": "repo-tools exec -- jsdoc -c .jsdoc.js", + "generate-scaffolding": "repo-tools generate all && repo-tools generate lib_samples_readme -l samples/ --config ../.cloud-repo-tools.json", + "lint": "repo-tools lint --cmd eslint -- src/ samples/ system-test/ test/", + "prettier": "repo-tools exec -- prettier --write src/*.js src/*/*.js samples/*.js samples/*/*.js test/*.js test/*/*.js system-test/*.js system-test/*/*.js", + "samples-test": "cd samples/ && npm test && cd ../", + "system-test": "repo-tools test run --cmd mocha -- system-test/*.js --timeout 5000", + "test-no-cover": "repo-tools test run --cmd mocha -- test/*.js --no-timeouts", + "test": "repo-tools test run --cmd npm -- run cover" + }, "dependencies": { - "extend": "^3.0", - "google-gax": "^0.13.5" + "google-gax": "^0.14.1", + "lodash.merge": "^4.6.0" }, "devDependencies": { - "mocha": "^3.2.0" - }, - "scripts": { - "publish-module": "node ../../scripts/publish.js language", - "smoke-test": "mocha smoke-test/*.js --timeout 5000", - "test": "mocha test/*.js" - }, - "license": "Apache-2.0", - "engines": { - "node": ">=4.0.0" + "@google-cloud/nodejs-repo-tools": "^2.0.8", + "async": "^2.5.0", + "codecov": "^2.3.0", + "eslint": "^4.8.0", + "eslint-config-prettier": "^2.6.0", + "eslint-plugin-node": "^5.2.0", + "eslint-plugin-prettier": "^2.3.1", + "extend": "^3.0.1", + "ink-docstrap": "^1.3.0", + "intelli-espower-loader": "^1.0.1", + "jsdoc": "^3.5.5", + "mocha": "^3.5.3", + "nyc": "^11.2.1", + "power-assert": "^1.4.4", + "prettier": "^1.7.4" } } diff --git a/packages/google-cloud-language/samples/.eslintrc.yml b/packages/google-cloud-language/samples/.eslintrc.yml new file mode 100644 index 00000000000..282535f55f6 --- /dev/null +++ b/packages/google-cloud-language/samples/.eslintrc.yml @@ -0,0 +1,3 @@ +--- +rules: + no-console: off diff --git a/packages/google-cloud-language/samples/README.md b/packages/google-cloud-language/samples/README.md index f2d5d8db302..63aa1a1b253 100644 --- a/packages/google-cloud-language/samples/README.md +++ b/packages/google-cloud-language/samples/README.md @@ -1,41 +1,29 @@ Google Cloud Platform logo -# Google Cloud Natural Language API Node.js Samples +# Google Cloud Natural Language API: Node.js Samples -[![Build](https://storage.googleapis.com/cloud-docs-samples-badges/GoogleCloudPlatform/nodejs-docs-samples/nodejs-docs-samples-language.svg)]() +[![Build](https://storage.googleapis.com/.svg)]() [Cloud Natural Language API](https://cloud.google.com/natural-language/docs) provides natural language understanding technologies to developers, including sentiment analysis, entity analysis, and syntax analysis. This API is part of the larger Cloud Machine Learning API family. ## Table of Contents -* [Setup](#setup) +* [Before you begin](#before-you-begin) * [Samples](#samples) * [Analyze v1](#analyze-v1) * [Analyze v1beta2](#analyze-v1beta2) - * [Slack Bot](#slack-bot) -* [Running the tests](#running-the-tests) -## Setup +## Before you begin -1. Read [Prerequisites][prereq] and [How to run a sample][run] first. -1. Install dependencies: - - With **npm**: - - npm install - - With **yarn**: - - yarn install - -[prereq]: ../README.md#prerequisites -[run]: ../README.md#how-to-run-a-sample +Before running the samples, make sure you've followed the steps in the +[Before you begin section](../README.md#before-you-begin) of the client +library's README. ## Samples ### Analyze v1 -View the [documentation][analyze-v1_0_docs] or the [source code][analyze-v1_0_code]. +View the [source code][analyze-v1_0_code]. __Usage:__ `node analyze.v1.js --help` @@ -51,7 +39,8 @@ Commands: entity-sentiment-file Detects sentiment of the entities in a file in Google Cloud Storage. Options: - --help Show help [boolean] + --version Show version number [boolean] + --help Show help [boolean] Examples: node analyze.v1.js sentiment-text "President Obama is speaking at the White House." @@ -71,7 +60,7 @@ For more information, see https://cloud.google.com/natural-language/docs ### Analyze v1beta2 -View the [documentation][analyze-v1beta2_1_docs] or the [source code][analyze-v1beta2_1_code]. +View the [source code][analyze-v1beta2_1_code]. __Usage:__ `node analyze.v1beta2.js --help` @@ -87,7 +76,8 @@ Commands: classify-file Classifies text in a file in Google Cloud Storage. Options: - --help Show help [boolean] + --version Show version number [boolean] + --help Show help [boolean] Examples: node analyze.v1beta2.js sentiment-text "President Obama is speaking at the White House." @@ -96,8 +86,7 @@ Examples: node analyze.v1beta2.js entities-file my-bucket file.txt Detects entities in gs://my-bucket/file.txt node analyze.v1beta2.js syntax-text "President Obama is speaking at the White House." node analyze.v1beta2.js syntax-file my-bucket file.txt Detects syntax in gs://my-bucket/file.txt - node analyze.v1beta2.js classify-text "Currently the API requires 20 tokens in order \ - to return non-empty results. Let's use a longer piece of text for the sample in order to win." + node analyze.v1beta2.js classify-text "Android is a mobile operating system developed by Google." node analyze.v1beta2.js classify-file my-bucket Detects syntax in gs://my-bucket/android_text.txt android_text.txt @@ -106,24 +95,3 @@ For more information, see https://cloud.google.com/natural-language/docs [analyze-v1beta2_1_docs]: https://cloud.google.com/natural-language/docs/ [analyze-v1beta2_1_code]: analyze.v1beta2.js - -### Slack Bot - - -View the [README](slackbot/README.md). - - - -## Running the tests - -1. Set the **GCLOUD_PROJECT** and **GOOGLE_APPLICATION_CREDENTIALS** environment variables. - -1. Run the tests: - - With **npm**: - - npm test - - With **yarn**: - - yarn test diff --git a/packages/google-cloud-language/samples/package.json b/packages/google-cloud-language/samples/package.json index 87c1ac179fe..a31c84a5da8 100644 --- a/packages/google-cloud-language/samples/package.json +++ b/packages/google-cloud-language/samples/package.json @@ -1,61 +1,33 @@ { "name": "nodejs-docs-samples-language", "version": "0.0.1", - "private": true, "license": "Apache-2.0", "author": "Google Inc.", - "repository": { - "type": "git", - "url": "https://github.com/GoogleCloudPlatform/nodejs-docs-samples.git" - }, "engines": { "node": ">=4.3.2" }, + "repository": "googleapis/nodejs-language", + "private": true, "semistandard": { "ignore": [ "node_modules" ] }, "scripts": { - "lint": "samples lint", - "pretest": "npm run lint", - "test": "samples test run --cmd ava -- -T 20s --verbose system-test/*.test.js" + "ava": "ava -T 20s --verbose test/*.test.js ./system-test/*.test.js", + "cover": "nyc --reporter=lcov --cache ava -T 20s --verbose test/*.test.js ./system-test/*.test.js && nyc report", + "test": "repo-tools test run --cmd npm -- run cover" }, "dependencies": { "@google-cloud/language": "0.12.1", - "@google-cloud/storage": "1.2.1", - "yargs": "8.0.2" + "@google-cloud/storage": "1.4.0", + "yargs": "9.0.1" }, "devDependencies": { - "@google-cloud/nodejs-repo-tools": "1.4.17", - "ava": "0.21.0", + "@google-cloud/nodejs-repo-tools": "2.0.8", + "ava": "0.22.0", "proxyquire": "1.8.0", - "sinon": "3.2.0" - }, - "cloud-repo-tools": { - "requiresKeyFile": true, - "requiresProjectId": true, - "product": "nl", - "samples": [ - { - "id": "analyze-v1", - "name": "Analyze v1", - "file": "analyze.v1.js", - "docs_link": "https://cloud.google.com/natural-language/docs/", - "usage": "node analyze.v1.js --help" - }, - { - "id": "analyze-v1beta2", - "name": "Analyze v1beta2", - "file": "analyze.v1beta2.js", - "docs_link": "https://cloud.google.com/natural-language/docs/", - "usage": "node analyze.v1beta2.js --help" - }, - { - "id": "slackbot", - "name": "Slack Bot", - "ref": "slackbot/README.md" - } - ] + "sinon": "4.0.1", + "uuid": "3.1.0" } } diff --git a/packages/google-cloud-language/samples/quickstart.js b/packages/google-cloud-language/samples/quickstart.js index afc74fe253b..b1b5683bb9f 100644 --- a/packages/google-cloud-language/samples/quickstart.js +++ b/packages/google-cloud-language/samples/quickstart.js @@ -17,29 +17,30 @@ // [START language_quickstart] // Imports the Google Cloud client library -const Language = require('@google-cloud/language'); +const language = require('@google-cloud/language'); // Instantiates a client -const language = Language(); +const client = new language.LanguageServiceClient(); // The text to analyze const text = 'Hello, world!'; const document = { - 'content': text, - type: 'PLAIN_TEXT' + content: text, + type: 'PLAIN_TEXT', }; // Detects the sentiment of the text -language.analyzeSentiment({'document': document}) - .then((results) => { +client + .analyzeSentiment({document: document}) + .then(results => { const sentiment = results[0].documentSentiment; console.log(`Text: ${text}`); console.log(`Sentiment score: ${sentiment.score}`); console.log(`Sentiment magnitude: ${sentiment.magnitude}`); }) - .catch((err) => { + .catch(err => { console.error('ERROR:', err); }); // [END language_quickstart] diff --git a/packages/google-cloud-language/smoke-test/language_service_smoke_test.js b/packages/google-cloud-language/smoke-test/language_service_smoke_test.js deleted file mode 100644 index 1f38b3207a2..00000000000 --- a/packages/google-cloud-language/smoke-test/language_service_smoke_test.js +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2017, 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. - */ -'use strict'; - -describe('LanguageServiceSmokeTest', function() { - - it('successfully makes a call to the service', function(done) { - var language = require('../src'); - - var client = language.v1({ - // optional auth parameters. - }); - - var content = 'Hello, world!'; - var type = language.v1.types.Document.Type.PLAIN_TEXT; - var document = { - content : content, - type : type - }; - client.analyzeSentiment({document: document}).then(function(responses) { - var response = responses[0]; - console.log(response); - }) - .then(done) - .catch(done); - }); -}); \ No newline at end of file diff --git a/packages/google-cloud-language/src/index.js b/packages/google-cloud-language/src/index.js index 299b668726b..59999ca9520 100644 --- a/packages/google-cloud-language/src/index.js +++ b/packages/google-cloud-language/src/index.js @@ -1,138 +1,102 @@ -/* - * Copyright 2017, 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. +// Copyright 2017, 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. + +/** + * @namespace google + */ +/** + * @namespace google.cloud + */ +/** + * @namespace google.cloud.language + */ +/** + * @namespace google.cloud.language.v1 + */ +/** + * @namespace google.cloud.language.v1beta2 */ - /*! - * @module language - * @name Language - */ 'use strict'; -var extend = require('extend'); -var gapic = { +// Import the clients for each version supported by this package. +const gapic = Object.freeze({ v1: require('./v1'), v1beta2: require('./v1beta2'), -}; -var gaxGrpc = require('google-gax').grpc(); -var path = require('path'); - -const VERSION = require('../package.json').version; +}); /** - * Create an languageServiceClient with additional helpers for common - * tasks. + * The `@google-cloud/language` package has the following named exports: * - * Provides text analysis operations such as sentiment analysis and entity - * recognition. + * - `LanguageServiceClient` - Reference to + * {@link v1.LanguageServiceClient} + * - `v1` - This is used for selecting or pinning a + * particular backend service version. It exports: + * - `LanguageServiceClient` - Reference to + * {@link v1.LanguageServiceClient} + * - `v1beta2` - This is used for selecting or pinning a + * particular backend service version. It exports: + * - `LanguageServiceClient` - Reference to + * {@link v1beta2.LanguageServiceClient} * - * @param {object=} options - [Configuration object](#/docs). - * @param {object=} options.credentials - Credentials object. - * @param {string=} options.credentials.client_email - * @param {string=} options.credentials.private_key - * @param {string=} options.email - Account email address. Required when using a - * .pem or .p12 keyFilename. - * @param {string=} options.keyFilename - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option above is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number=} options.port - The port on which to connect to - * the remote host. - * @param {string=} options.projectId - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {function=} options.promise - Custom promise module to use instead - * of native Promises. - * @param {string=} options.servicePath - The domain name of the - * API remote host. - */ -function languageV1(options) { - // Define the header options. - options = extend({}, options, { - libName: 'gccl', - libVersion: VERSION - }); - - // Create the client with the provided options. - var client = gapic.v1(options).languageServiceClient(options); - return client; -} - -var v1Protos = {}; - -extend(v1Protos, gaxGrpc.loadProto( - path.join(__dirname, '..', 'protos', - 'google/cloud/language/v1/language_service.proto') -).google.cloud.language.v1); - - -/** - * Create an languageServiceClient with additional helpers for common - * tasks. + * @module {object} @google-cloud/language + * @alias nodejs-language + * + * @example Install the client library with + * npm: + * npm install --save @google-cloud/language + * + * @example Import the client library: + * const language = require('@google-cloud/language'); + * + * @example Create a client that uses + * Application Default Credentials + * (ADC): + * let client = new language.LanguageServiceClient(); * - * Provides text analysis operations such as sentiment analysis and entity - * recognition. + * @example Create a client with + * explicit credentials: + * let client = new language.LanguageServiceClient({ + * projectId: 'your-project-id', + * keyFilename: '/path/to/keyfile.json', + * }); * - * @param {object=} options - [Configuration object](#/docs). - * @param {object=} options.credentials - Credentials object. - * @param {string=} options.credentials.client_email - * @param {string=} options.credentials.private_key - * @param {string=} options.email - Account email address. Required when using a - * .pem or .p12 keyFilename. - * @param {string=} options.keyFilename - Full path to the a .json, .pem, or - * .p12 key downloaded from the Google Developers Console. If you provide - * a path to a JSON file, the projectId option above is not necessary. - * NOTE: .pem and .p12 require you to specify options.email as well. - * @param {number=} options.port - The port on which to connect to - * the remote host. - * @param {string=} options.projectId - The project ID from the Google - * Developer's Console, e.g. 'grape-spaceship-123'. We will also check - * the environment variable GCLOUD_PROJECT for your project ID. If your - * app is running in an environment which supports - * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, - * your project ID will be detected automatically. - * @param {function=} options.promise - Custom promise module to use instead - * of native Promises. - * @param {string=} options.servicePath - The domain name of the - * API remote host. + * @example include:samples/quickstart.js + * region_tag:language_quickstart + * Full quickstart example: */ -function languageV1beta2(options) { - // Define the header options. - options = extend({}, options, { - libName: 'gccl', - libVersion: VERSION - }); - // Create the client with the provided options. - var client = gapic.v1beta2(options).languageServiceClient(options); - return client; -} - -var v1beta2Protos = {}; +/** + * @type {object} + * @property {constructor} LanguageServiceClient + * Reference to {@link v1.LanguageServiceClient} + */ +module.exports = gapic.v1; -extend(v1beta2Protos, gaxGrpc.loadProto( - path.join(__dirname, '..', 'protos', - 'google/cloud/language/v1beta2/language_service.proto') -).google.cloud.language.v1beta2); +/** + * @type {object} + * @property {constructor} LanguageServiceClient + * Reference to {@link v1.LanguageServiceClient} + */ +module.exports.v1 = gapic.v1; +/** + * @type {object} + * @property {constructor} LanguageServiceClient + * Reference to {@link v1beta2.LanguageServiceClient} + */ +module.exports.v1beta2 = gapic.v1beta2; -module.exports = languageV1; -module.exports.types = v1Protos; -module.exports.v1 = languageV1; -module.exports.v1.types = v1Protos; -module.exports.v1beta2 = languageV1beta2; -module.exports.v1beta2.types = v1beta2Protos; +// Alias `module.exports` as `module.exports.default`, for future-proofing. +module.exports.default = Object.assign({}, module.exports); diff --git a/packages/google-cloud-language/src/v1/doc/doc_language_service.js b/packages/google-cloud-language/src/v1/doc/google/cloud/language/v1/doc_language_service.js similarity index 83% rename from packages/google-cloud-language/src/v1/doc/doc_language_service.js rename to packages/google-cloud-language/src/v1/doc/google/cloud/language/v1/doc_language_service.js index 9982df7a0e1..a28e27464b6 100644 --- a/packages/google-cloud-language/src/v1/doc/doc_language_service.js +++ b/packages/google-cloud-language/src/v1/doc/google/cloud/language/v1/doc_language_service.js @@ -1,23 +1,19 @@ -/* - * Copyright 2017, 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. - */ - -/* - * Note: this file is purely for documentation. Any contents are not expected - * to be loaded as the JS file. - */ +// Copyright 2017, 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. + +// Note: this file is purely for documentation. Any contents are not expected +// to be loaded as the JS file. /** * ################################################################ # @@ -28,7 +24,7 @@ * Required. If the type is not set or is `TYPE_UNSPECIFIED`, * returns an `INVALID_ARGUMENT` error. * - * The number should be among the values of [Type]{@link Type} + * The number should be among the values of [Type]{@link google.cloud.language.v1.Type} * * @property {string} content * The content of the input in string format. @@ -49,7 +45,8 @@ * is not supported by the called API method, an `INVALID_ARGUMENT` error * is returned. * - * @class + * @typedef Document + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.Document definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var Document = { @@ -59,6 +56,7 @@ var Document = { * The document types enum. * * @enum {number} + * @memberof google.cloud.language.v1 */ Type: { @@ -85,16 +83,17 @@ var Document = { * @property {Object} text * The sentence text. * - * This object should have the same structure as [TextSpan]{@link TextSpan} + * This object should have the same structure as [TextSpan]{@link google.cloud.language.v1.TextSpan} * * @property {Object} sentiment - * For calls to {@link AnalyzeSentiment} or if - * {@link AnnotateTextRequest.Features.extract_document_sentiment} is set to + * For calls to AnalyzeSentiment or if + * AnnotateTextRequest.Features.extract_document_sentiment is set to * true, this field will contain the sentiment for the sentence. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1.Sentiment} * - * @class + * @typedef Sentence + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.Sentence definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var Sentence = { @@ -112,7 +111,7 @@ var Sentence = { * @property {number} type * The entity type. * - * The number should be among the values of [Type]{@link Type} + * The number should be among the values of [Type]{@link google.cloud.language.v1.Type} * * @property {Object.} metadata * Metadata associated with the entity. @@ -132,17 +131,18 @@ var Sentence = { * The mentions of this entity in the input document. The API currently * supports proper noun mentions. * - * This object should have the same structure as [EntityMention]{@link EntityMention} + * This object should have the same structure as [EntityMention]{@link google.cloud.language.v1.EntityMention} * * @property {Object} sentiment - * For calls to {@link AnalyzeEntitySentiment} or if - * {@link AnnotateTextRequest.Features.extract_entity_sentiment} is set to + * For calls to AnalyzeEntitySentiment or if + * AnnotateTextRequest.Features.extract_entity_sentiment is set to * true, this field will contain the aggregate sentiment expressed for this * entity in the provided document. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1.Sentiment} * - * @class + * @typedef Entity + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.Entity definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var Entity = { @@ -152,6 +152,7 @@ var Entity = { * The type of the entity. * * @enum {number} + * @memberof google.cloud.language.v1 */ Type: { @@ -203,22 +204,23 @@ var Entity = { * @property {Object} text * The token text. * - * This object should have the same structure as [TextSpan]{@link TextSpan} + * This object should have the same structure as [TextSpan]{@link google.cloud.language.v1.TextSpan} * * @property {Object} partOfSpeech * Parts of speech tag for this token. * - * This object should have the same structure as [PartOfSpeech]{@link PartOfSpeech} + * This object should have the same structure as [PartOfSpeech]{@link google.cloud.language.v1.PartOfSpeech} * * @property {Object} dependencyEdge * Dependency tree parse for this token. * - * This object should have the same structure as [DependencyEdge]{@link DependencyEdge} + * This object should have the same structure as [DependencyEdge]{@link google.cloud.language.v1.DependencyEdge} * * @property {string} lemma * [Lemma](https://en.wikipedia.org/wiki/Lemma_%28morphology%29) of the token. * - * @class + * @typedef Token + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.Token definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var Token = { @@ -238,7 +240,8 @@ var Token = { * Sentiment score between -1.0 (negative sentiment) and 1.0 * (positive sentiment). * - * @class + * @typedef Sentiment + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.Sentiment definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var Sentiment = { @@ -253,64 +256,65 @@ var Sentiment = { * @property {number} tag * The part of speech tag. * - * The number should be among the values of [Tag]{@link Tag} + * The number should be among the values of [Tag]{@link google.cloud.language.v1.Tag} * * @property {number} aspect * The grammatical aspect. * - * The number should be among the values of [Aspect]{@link Aspect} + * The number should be among the values of [Aspect]{@link google.cloud.language.v1.Aspect} * * @property {number} case * The grammatical case. * - * The number should be among the values of [Case]{@link Case} + * The number should be among the values of [Case]{@link google.cloud.language.v1.Case} * * @property {number} form * The grammatical form. * - * The number should be among the values of [Form]{@link Form} + * The number should be among the values of [Form]{@link google.cloud.language.v1.Form} * * @property {number} gender * The grammatical gender. * - * The number should be among the values of [Gender]{@link Gender} + * The number should be among the values of [Gender]{@link google.cloud.language.v1.Gender} * * @property {number} mood * The grammatical mood. * - * The number should be among the values of [Mood]{@link Mood} + * The number should be among the values of [Mood]{@link google.cloud.language.v1.Mood} * * @property {number} number * The grammatical number. * - * The number should be among the values of [Number]{@link Number} + * The number should be among the values of [Number]{@link google.cloud.language.v1.Number} * * @property {number} person * The grammatical person. * - * The number should be among the values of [Person]{@link Person} + * The number should be among the values of [Person]{@link google.cloud.language.v1.Person} * * @property {number} proper * The grammatical properness. * - * The number should be among the values of [Proper]{@link Proper} + * The number should be among the values of [Proper]{@link google.cloud.language.v1.Proper} * * @property {number} reciprocity * The grammatical reciprocity. * - * The number should be among the values of [Reciprocity]{@link Reciprocity} + * The number should be among the values of [Reciprocity]{@link google.cloud.language.v1.Reciprocity} * * @property {number} tense * The grammatical tense. * - * The number should be among the values of [Tense]{@link Tense} + * The number should be among the values of [Tense]{@link google.cloud.language.v1.Tense} * * @property {number} voice * The grammatical voice. * - * The number should be among the values of [Voice]{@link Voice} + * The number should be among the values of [Voice]{@link google.cloud.language.v1.Voice} * - * @class + * @typedef PartOfSpeech + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.PartOfSpeech definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var PartOfSpeech = { @@ -320,6 +324,7 @@ var PartOfSpeech = { * The part of speech tags enum. * * @enum {number} + * @memberof google.cloud.language.v1 */ Tag: { @@ -398,6 +403,7 @@ var PartOfSpeech = { * The characteristic of a verb that expresses time flow during an event. * * @enum {number} + * @memberof google.cloud.language.v1 */ Aspect: { @@ -428,6 +434,7 @@ var PartOfSpeech = { * adjective and determiner, take case inflection in agreement with the noun. * * @enum {number} + * @memberof google.cloud.language.v1 */ Case: { @@ -514,6 +521,7 @@ var PartOfSpeech = { * forms of adjectives and participles * * @enum {number} + * @memberof google.cloud.language.v1 */ Form: { @@ -582,6 +590,7 @@ var PartOfSpeech = { * Gender classes of nouns reflected in the behaviour of associated words. * * @enum {number} + * @memberof google.cloud.language.v1 */ Gender: { @@ -610,6 +619,7 @@ var PartOfSpeech = { * The grammatical feature of verbs, used for showing modality and attitude. * * @enum {number} + * @memberof google.cloud.language.v1 */ Mood: { @@ -653,6 +663,7 @@ var PartOfSpeech = { * Count distinctions. * * @enum {number} + * @memberof google.cloud.language.v1 */ Number: { @@ -681,6 +692,7 @@ var PartOfSpeech = { * The distinction between the speaker, second person, third person, etc. * * @enum {number} + * @memberof google.cloud.language.v1 */ Person: { @@ -714,6 +726,7 @@ var PartOfSpeech = { * This category shows if the token is part of a proper name. * * @enum {number} + * @memberof google.cloud.language.v1 */ Proper: { @@ -737,6 +750,7 @@ var PartOfSpeech = { * Reciprocal features of a pronoun. * * @enum {number} + * @memberof google.cloud.language.v1 */ Reciprocity: { @@ -761,6 +775,7 @@ var PartOfSpeech = { * Time reference. * * @enum {number} + * @memberof google.cloud.language.v1 */ Tense: { @@ -805,6 +820,7 @@ var PartOfSpeech = { * participants identified by its arguments. * * @enum {number} + * @memberof google.cloud.language.v1 */ Voice: { @@ -845,9 +861,10 @@ var PartOfSpeech = { * @property {number} label * The parse label for the token. * - * The number should be among the values of [Label]{@link Label} + * The number should be among the values of [Label]{@link google.cloud.language.v1.Label} * - * @class + * @typedef DependencyEdge + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.DependencyEdge definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var DependencyEdge = { @@ -857,6 +874,7 @@ var DependencyEdge = { * The parse label enum for the token. * * @enum {number} + * @memberof google.cloud.language.v1 */ Label: { @@ -1284,22 +1302,23 @@ var DependencyEdge = { * @property {Object} text * The mention text. * - * This object should have the same structure as [TextSpan]{@link TextSpan} + * This object should have the same structure as [TextSpan]{@link google.cloud.language.v1.TextSpan} * * @property {number} type * The type of the entity mention. * - * The number should be among the values of [Type]{@link Type} + * The number should be among the values of [Type]{@link google.cloud.language.v1.Type} * * @property {Object} sentiment - * For calls to {@link AnalyzeEntitySentiment} or if - * {@link AnnotateTextRequest.Features.extract_entity_sentiment} is set to + * For calls to AnalyzeEntitySentiment or if + * AnnotateTextRequest.Features.extract_entity_sentiment is set to * true, this field will contain the sentiment expressed for this mention of * the entity in the provided document. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1.Sentiment} * - * @class + * @typedef EntityMention + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.EntityMention definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var EntityMention = { @@ -1309,6 +1328,7 @@ var EntityMention = { * The supported types of mentions. * * @enum {number} + * @memberof google.cloud.language.v1 */ Type: { @@ -1337,9 +1357,10 @@ var EntityMention = { * * @property {number} beginOffset * The API calculates the beginning offset of the content in the original - * document according to the {@link EncodingType} specified in the API request. + * document according to the EncodingType specified in the API request. * - * @class + * @typedef TextSpan + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.TextSpan definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var TextSpan = { @@ -1352,14 +1373,15 @@ var TextSpan = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} * * @property {number} encodingType * The encoding type used by the API to calculate sentence offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} * - * @class + * @typedef AnalyzeSentimentRequest + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeSentimentRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeSentimentRequest = { @@ -1372,19 +1394,20 @@ var AnalyzeSentimentRequest = { * @property {Object} documentSentiment * The overall sentiment of the input document. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1.Sentiment} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * * @property {Object[]} sentences * The sentiment for all the sentences in the document. * - * This object should have the same structure as [Sentence]{@link Sentence} + * This object should have the same structure as [Sentence]{@link google.cloud.language.v1.Sentence} * - * @class + * @typedef AnalyzeSentimentResponse + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeSentimentResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeSentimentResponse = { @@ -1397,14 +1420,15 @@ var AnalyzeSentimentResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} * - * @class + * @typedef AnalyzeEntitySentimentRequest + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeEntitySentimentRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeEntitySentimentRequest = { @@ -1417,14 +1441,15 @@ var AnalyzeEntitySentimentRequest = { * @property {Object[]} entities * The recognized entities in the input document with associated sentiments. * - * This object should have the same structure as [Entity]{@link Entity} + * This object should have the same structure as [Entity]{@link google.cloud.language.v1.Entity} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * - * @class + * @typedef AnalyzeEntitySentimentResponse + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeEntitySentimentResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeEntitySentimentResponse = { @@ -1437,14 +1462,15 @@ var AnalyzeEntitySentimentResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} * - * @class + * @typedef AnalyzeEntitiesRequest + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeEntitiesRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeEntitiesRequest = { @@ -1457,14 +1483,15 @@ var AnalyzeEntitiesRequest = { * @property {Object[]} entities * The recognized entities in the input document. * - * This object should have the same structure as [Entity]{@link Entity} + * This object should have the same structure as [Entity]{@link google.cloud.language.v1.Entity} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * - * @class + * @typedef AnalyzeEntitiesResponse + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeEntitiesResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeEntitiesResponse = { @@ -1477,14 +1504,15 @@ var AnalyzeEntitiesResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} * - * @class + * @typedef AnalyzeSyntaxRequest + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeSyntaxRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeSyntaxRequest = { @@ -1497,19 +1525,20 @@ var AnalyzeSyntaxRequest = { * @property {Object[]} sentences * Sentences in the input document. * - * This object should have the same structure as [Sentence]{@link Sentence} + * This object should have the same structure as [Sentence]{@link google.cloud.language.v1.Sentence} * * @property {Object[]} tokens * Tokens, along with their syntactic information, in the input document. * - * This object should have the same structure as [Token]{@link Token} + * This object should have the same structure as [Token]{@link google.cloud.language.v1.Token} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * - * @class + * @typedef AnalyzeSyntaxResponse + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnalyzeSyntaxResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnalyzeSyntaxResponse = { @@ -1523,19 +1552,20 @@ var AnalyzeSyntaxResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} * * @property {Object} features * The enabled features. * - * This object should have the same structure as [Features]{@link Features} + * This object should have the same structure as [Features]{@link google.cloud.language.v1.Features} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} * - * @class + * @typedef AnnotateTextRequest + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnnotateTextRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnnotateTextRequest = { @@ -1557,7 +1587,8 @@ var AnnotateTextRequest = { * @property {boolean} extractEntitySentiment * Extract entities and their associated sentiment. * - * @class + * @typedef Features + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnnotateTextRequest.Features definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ Features: { @@ -1570,36 +1601,37 @@ var AnnotateTextRequest = { * * @property {Object[]} sentences * Sentences in the input document. Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_syntax}. + * AnnotateTextRequest.Features.extract_syntax. * - * This object should have the same structure as [Sentence]{@link Sentence} + * This object should have the same structure as [Sentence]{@link google.cloud.language.v1.Sentence} * * @property {Object[]} tokens * Tokens, along with their syntactic information, in the input document. * Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_syntax}. + * AnnotateTextRequest.Features.extract_syntax. * - * This object should have the same structure as [Token]{@link Token} + * This object should have the same structure as [Token]{@link google.cloud.language.v1.Token} * * @property {Object[]} entities * Entities, along with their semantic information, in the input document. * Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_entities}. + * AnnotateTextRequest.Features.extract_entities. * - * This object should have the same structure as [Entity]{@link Entity} + * This object should have the same structure as [Entity]{@link google.cloud.language.v1.Entity} * * @property {Object} documentSentiment * The overall sentiment for the document. Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_document_sentiment}. + * AnnotateTextRequest.Features.extract_document_sentiment. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1.Sentiment} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * - * @class + * @typedef AnnotateTextResponse + * @memberof google.cloud.language.v1 * @see [google.cloud.language.v1.AnnotateTextResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto} */ var AnnotateTextResponse = { @@ -1614,6 +1646,7 @@ var AnnotateTextResponse = { * differently. * * @enum {number} + * @memberof google.cloud.language.v1 */ var EncodingType = { diff --git a/packages/google-cloud-language/src/v1/index.js b/packages/google-cloud-language/src/v1/index.js index c7808106836..4921903da71 100644 --- a/packages/google-cloud-language/src/v1/index.js +++ b/packages/google-cloud-language/src/v1/index.js @@ -1,34 +1,19 @@ -/* - * Copyright 2017, 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. - */ -'use strict'; - -var languageServiceClient = require('./language_service_client'); -var gax = require('google-gax'); -var extend = require('extend'); +// Copyright 2017, 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. -function v1(options) { - options = extend({ - scopes: v1.ALL_SCOPES - }, options); - var gaxGrpc = gax.grpc(options); - return languageServiceClient(gaxGrpc); -} +'use strict'; -v1.GAPIC_VERSION = '0.0.5'; -v1.SERVICE_ADDRESS = languageServiceClient.SERVICE_ADDRESS; -v1.ALL_SCOPES = languageServiceClient.ALL_SCOPES; +const LanguageServiceClient = require('./language_service_client'); -module.exports = v1; \ No newline at end of file +module.exports.LanguageServiceClient = LanguageServiceClient; diff --git a/packages/google-cloud-language/src/v1/language_service_client.js b/packages/google-cloud-language/src/v1/language_service_client.js index 4e59b4a86e2..aa5654e24c3 100644 --- a/packages/google-cloud-language/src/v1/language_service_client.js +++ b/packages/google-cloud-language/src/v1/language_service_client.js @@ -1,431 +1,459 @@ -/* - * Copyright 2017, 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. - * - * EDITING INSTRUCTIONS - * This file was generated from the file - * https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1/language_service.proto, - * and updates to that file get reflected here through a refresh process. - * For the short term, the refresh process will only be runnable by Google - * engineers. - * - * The only allowed edits are to method and file documentation. A 3-way - * merge preserves those additions if the generated source changes. - */ -/* TODO: introduce line-wrapping so that it never exceeds the limit. */ -/* jscs: disable maximumLineLength */ -'use strict'; - -var configData = require('./language_service_client_config'); -var extend = require('extend'); -var gax = require('google-gax'); -var googleProtoFiles = require('google-proto-files'); -var path = require('path'); +// Copyright 2017, 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. -var SERVICE_ADDRESS = 'language.googleapis.com'; +'use strict'; -var DEFAULT_SERVICE_PORT = 443; +const gapicConfig = require('./language_service_client_config'); +const gax = require('google-gax'); +const merge = require('lodash.merge'); +const path = require('path'); -var CODE_GEN_NAME_VERSION = 'gapic/0.0.5'; - -/** - * The scopes needed to make gRPC calls to all of the methods defined in - * this service. - */ -var ALL_SCOPES = [ - 'https://www.googleapis.com/auth/cloud-platform' -]; +const VERSION = require('../../package.json').version; /** * Provides text analysis operations such as sentiment analysis and entity * recognition. * - * * @class + * @memberof v1 */ -function LanguageServiceClient(gaxGrpc, loadedProtos, opts) { - opts = extend({ - servicePath: SERVICE_ADDRESS, - port: DEFAULT_SERVICE_PORT, - clientConfig: {} - }, opts); +class LanguageServiceClient { + /** + * Construct an instance of LanguageServiceClient. + * + * @param {object=} options - The configuration object. See the subsequent + * parameters for more details. + * @param {object=} options.credentials - Credentials object. + * @param {string=} options.credentials.client_email + * @param {string=} options.credentials.private_key + * @param {string=} options.email - Account email address. Required when + * usaing a .pem or .p12 keyFilename. + * @param {string=} options.keyFilename - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option above is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number=} options.port - The port on which to connect to + * the remote host. + * @param {string=} options.projectId - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {function=} options.promise - Custom promise module to use instead + * of native Promises. + * @param {string=} options.servicePath - The domain name of the + * API remote host. + */ + constructor(opts) { + this._descriptors = {}; - var googleApiClient = [ - 'gl-node/' + process.versions.node - ]; - if (opts.libName && opts.libVersion) { - googleApiClient.push(opts.libName + '/' + opts.libVersion); - } - googleApiClient.push( - CODE_GEN_NAME_VERSION, - 'gax/' + gax.version, - 'grpc/' + gaxGrpc.grpcVersion - ); + // Ensure that options include the service address and port. + opts = Object.assign( + { + clientConfig: {}, + port: this.constructor.port, + servicePath: this.constructor.servicePath, + }, + opts + ); - var defaults = gaxGrpc.constructSettings( - 'google.cloud.language.v1.LanguageService', - configData, - opts.clientConfig, - {'x-goog-api-client': googleApiClient.join(' ')}); + // Create a `gaxGrpc` object, with any grpc-specific options + // sent to the client. + opts.scopes = this.constructor.scopes; + var gaxGrpc = gax.grpc(opts); - var self = this; + // Save the auth object to the client, for use by other methods. + this.auth = gaxGrpc.auth; - this.auth = gaxGrpc.auth; - var languageServiceStub = gaxGrpc.createStub( - loadedProtos.google.cloud.language.v1.LanguageService, - opts); - var languageServiceStubMethods = [ - 'analyzeSentiment', - 'analyzeEntities', - 'analyzeEntitySentiment', - 'analyzeSyntax', - 'annotateText' - ]; - languageServiceStubMethods.forEach(function(methodName) { - self['_' + methodName] = gax.createApiCall( - languageServiceStub.then(function(languageServiceStub) { - return function() { - var args = Array.prototype.slice.call(arguments, 0); - return languageServiceStub[methodName].apply(languageServiceStub, args); - }; - }), - defaults[methodName], - null); - }); -} + // Determine the client header string. + var clientHeader = [ + `gl-node/${process.version.node}`, + `grpc/${gaxGrpc.grpcVersion}`, + `gax/${gax.version}`, + `gapic/${VERSION}`, + ]; + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + var protos = merge( + {}, + gaxGrpc.loadProto( + path.join(__dirname, '..', '..', 'protos'), + 'google/cloud/language/v1/language_service.proto' + ) + ); -/** - * Get the project ID used by this class. - * @param {function(Error, string)} callback - the callback to be called with - * the current project Id. - */ -LanguageServiceClient.prototype.getProjectId = function(callback) { - return this.auth.getProjectId(callback); -}; - -// Service calls + // Put together the default options sent with requests. + var defaults = gaxGrpc.constructSettings( + 'google.cloud.language.v1.LanguageService', + gapicConfig, + opts.clientConfig, + {'x-goog-api-client': clientHeader.join(' ')} + ); -/** - * Analyzes the sentiment of the provided text. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate sentence offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeSentiment({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeSentiment = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; - } - if (options === undefined) { - options = {}; - } + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this._innerApiCalls = {}; - return this._analyzeSentiment(request, options, callback); -}; + // Put together the "service stub" for + // google.cloud.language.v1.LanguageService. + var languageServiceStub = gaxGrpc.createStub( + protos.google.cloud.language.v1.LanguageService, + opts + ); -/** - * Finds named entities (currently proper names and common nouns) in the text - * along with entity types, salience, mentions for each entity, and - * other properties. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeEntities({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeEntities = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; + // Iterate over each of the methods that the service provides + // and create an API call method for each. + var languageServiceStubMethods = [ + 'analyzeSentiment', + 'analyzeEntities', + 'analyzeEntitySentiment', + 'analyzeSyntax', + 'annotateText', + ]; + for (let methodName of languageServiceStubMethods) { + this._innerApiCalls[methodName] = gax.createApiCall( + languageServiceStub.then( + stub => + function() { + var args = Array.prototype.slice.call(arguments, 0); + return stub[methodName].apply(stub, args); + } + ), + defaults[methodName], + null + ); + } } - if (options === undefined) { - options = {}; + + /** + * The DNS address for this API service. + */ + static get servicePath() { + return 'language.googleapis.com'; } - return this._analyzeEntities(request, options, callback); -}; + /** + * The port for this API service. + */ + static get port() { + return 443; + } -/** - * Finds entities, similar to {@link AnalyzeEntities} in the text and analyzes - * sentiment associated with each entity and its mentions. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeEntitySentimentResponse]{@link AnalyzeEntitySentimentResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeEntitySentimentResponse]{@link AnalyzeEntitySentimentResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeEntitySentiment({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeEntitySentiment = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + */ + static get scopes() { + return ['https://www.googleapis.com/auth/cloud-platform']; } - if (options === undefined) { - options = {}; + + /** + * Return the project ID used by this class. + * @param {function(Error, string)} callback - the callback to + * be called with the current project Id. + */ + getProjectId(callback) { + return this.auth.getProjectId(callback); } - return this._analyzeEntitySentiment(request, options, callback); -}; + // ------------------- + // -- Service calls -- + // ------------------- -/** - * Analyzes the syntax of the text and provides sentence boundaries and - * tokenization along with part of speech tags, dependency trees, and other - * properties. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeSyntaxResponse]{@link AnalyzeSyntaxResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeSyntaxResponse]{@link AnalyzeSyntaxResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeSyntax({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeSyntax = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; - } - if (options === undefined) { - options = {}; + /** + * Analyzes the sentiment of the provided text. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate sentence offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link google.cloud.language.v1.AnalyzeSentimentResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeSentimentResponse]{@link google.cloud.language.v1.AnalyzeSentimentResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeSentiment({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeSentiment(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; + + return this._innerApiCalls.analyzeSentiment(request, options, callback); } - return this._analyzeSyntax(request, options, callback); -}; + /** + * Finds named entities (currently proper names and common nouns) in the text + * along with entity types, salience, mentions for each entity, and + * other properties. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link google.cloud.language.v1.AnalyzeEntitiesResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeEntitiesResponse]{@link google.cloud.language.v1.AnalyzeEntitiesResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeEntities({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeEntities(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; -/** - * A convenience method that provides all the features that analyzeSentiment, - * analyzeEntities, and analyzeSyntax provide in one call. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {Object} request.features - * The enabled features. - * - * This object should have the same structure as [Features]{@link Features} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1({ - * // optional auth parameters. - * }); - * - * var document = {}; - * var features = {}; - * var request = { - * document: document, - * features: features - * }; - * client.annotateText(request).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.annotateText = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; - } - if (options === undefined) { - options = {}; + return this._innerApiCalls.analyzeEntities(request, options, callback); } - return this._annotateText(request, options, callback); -}; + /** + * Finds entities, similar to AnalyzeEntities in the text and analyzes + * sentiment associated with each entity and its mentions. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeEntitySentimentResponse]{@link google.cloud.language.v1.AnalyzeEntitySentimentResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeEntitySentimentResponse]{@link google.cloud.language.v1.AnalyzeEntitySentimentResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeEntitySentiment({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeEntitySentiment(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; -function LanguageServiceClientBuilder(gaxGrpc) { - if (!(this instanceof LanguageServiceClientBuilder)) { - return new LanguageServiceClientBuilder(gaxGrpc); + return this._innerApiCalls.analyzeEntitySentiment( + request, + options, + callback + ); } - var languageServiceStubProtos = gaxGrpc.loadProto( - path.join(__dirname, '..', '..', 'protos', 'google/cloud/language/v1/language_service.proto')); - extend(this, languageServiceStubProtos.google.cloud.language.v1); + /** + * Analyzes the syntax of the text and provides sentence boundaries and + * tokenization along with part of speech tags, dependency trees, and other + * properties. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeSyntaxResponse]{@link google.cloud.language.v1.AnalyzeSyntaxResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeSyntaxResponse]{@link google.cloud.language.v1.AnalyzeSyntaxResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeSyntax({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeSyntax(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; + return this._innerApiCalls.analyzeSyntax(request, options, callback); + } /** - * Build a new instance of {@link LanguageServiceClient}. - * - * @param {Object=} opts - The optional parameters. - * @param {String=} opts.servicePath - * The domain name of the API remote host. - * @param {number=} opts.port - * The port on which to connect to the remote host. - * @param {grpc.ClientCredentials=} opts.sslCreds - * A ClientCredentials for use with an SSL-enabled channel. - * @param {Object=} opts.clientConfig - * The customized config to build the call settings. See - * {@link gax.constructSettings} for the format. + * A convenience method that provides all the features that analyzeSentiment, + * analyzeEntities, and analyzeSyntax provide in one call. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1.Document} + * @param {Object} request.features + * The enabled features. + * + * This object should have the same structure as [Features]{@link google.cloud.language.v1.Features} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnnotateTextResponse]{@link google.cloud.language.v1.AnnotateTextResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnnotateTextResponse]{@link google.cloud.language.v1.AnnotateTextResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * var features = {}; + * var request = { + * document: document, + * features: features, + * }; + * client.annotateText(request) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); */ - this.languageServiceClient = function(opts) { - return new LanguageServiceClient(gaxGrpc, languageServiceStubProtos, opts); - }; - extend(this.languageServiceClient, LanguageServiceClient); + annotateText(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; + + return this._innerApiCalls.annotateText(request, options, callback); + } } -module.exports = LanguageServiceClientBuilder; -module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; -module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file + +module.exports = LanguageServiceClient; diff --git a/packages/google-cloud-language/src/v1beta2/doc/doc_language_service.js b/packages/google-cloud-language/src/v1beta2/doc/google/cloud/language/v1beta2/doc_language_service.js similarity index 82% rename from packages/google-cloud-language/src/v1beta2/doc/doc_language_service.js rename to packages/google-cloud-language/src/v1beta2/doc/google/cloud/language/v1beta2/doc_language_service.js index 472e10e8be7..944c2cbc2c1 100644 --- a/packages/google-cloud-language/src/v1beta2/doc/doc_language_service.js +++ b/packages/google-cloud-language/src/v1beta2/doc/google/cloud/language/v1beta2/doc_language_service.js @@ -1,23 +1,19 @@ -/* - * Copyright 2017, 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. - */ - -/* - * Note: this file is purely for documentation. Any contents are not expected - * to be loaded as the JS file. - */ +// Copyright 2017, 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. + +// Note: this file is purely for documentation. Any contents are not expected +// to be loaded as the JS file. /** * ################################################################ # @@ -28,7 +24,7 @@ * Required. If the type is not set or is `TYPE_UNSPECIFIED`, * returns an `INVALID_ARGUMENT` error. * - * The number should be among the values of [Type]{@link Type} + * The number should be among the values of [Type]{@link google.cloud.language.v1beta2.Type} * * @property {string} content * The content of the input in string format. @@ -49,7 +45,8 @@ * is not supported by the called API method, an `INVALID_ARGUMENT` error * is returned. * - * @class + * @typedef Document + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.Document definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var Document = { @@ -59,6 +56,7 @@ var Document = { * The document types enum. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Type: { @@ -85,16 +83,17 @@ var Document = { * @property {Object} text * The sentence text. * - * This object should have the same structure as [TextSpan]{@link TextSpan} + * This object should have the same structure as [TextSpan]{@link google.cloud.language.v1beta2.TextSpan} * * @property {Object} sentiment - * For calls to {@link AnalyzeSentiment} or if - * {@link AnnotateTextRequest.Features.extract_document_sentiment} is set to + * For calls to AnalyzeSentiment or if + * AnnotateTextRequest.Features.extract_document_sentiment is set to * true, this field will contain the sentiment for the sentence. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1beta2.Sentiment} * - * @class + * @typedef Sentence + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.Sentence definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var Sentence = { @@ -112,7 +111,7 @@ var Sentence = { * @property {number} type * The entity type. * - * The number should be among the values of [Type]{@link Type} + * The number should be among the values of [Type]{@link google.cloud.language.v1beta2.Type} * * @property {Object.} metadata * Metadata associated with the entity. @@ -132,17 +131,18 @@ var Sentence = { * The mentions of this entity in the input document. The API currently * supports proper noun mentions. * - * This object should have the same structure as [EntityMention]{@link EntityMention} + * This object should have the same structure as [EntityMention]{@link google.cloud.language.v1beta2.EntityMention} * * @property {Object} sentiment - * For calls to {@link AnalyzeEntitySentiment} or if - * {@link AnnotateTextRequest.Features.extract_entity_sentiment} is set to + * For calls to AnalyzeEntitySentiment or if + * AnnotateTextRequest.Features.extract_entity_sentiment is set to * true, this field will contain the aggregate sentiment expressed for this * entity in the provided document. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1beta2.Sentiment} * - * @class + * @typedef Entity + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.Entity definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var Entity = { @@ -152,6 +152,7 @@ var Entity = { * The type of the entity. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Type: { @@ -203,22 +204,23 @@ var Entity = { * @property {Object} text * The token text. * - * This object should have the same structure as [TextSpan]{@link TextSpan} + * This object should have the same structure as [TextSpan]{@link google.cloud.language.v1beta2.TextSpan} * * @property {Object} partOfSpeech * Parts of speech tag for this token. * - * This object should have the same structure as [PartOfSpeech]{@link PartOfSpeech} + * This object should have the same structure as [PartOfSpeech]{@link google.cloud.language.v1beta2.PartOfSpeech} * * @property {Object} dependencyEdge * Dependency tree parse for this token. * - * This object should have the same structure as [DependencyEdge]{@link DependencyEdge} + * This object should have the same structure as [DependencyEdge]{@link google.cloud.language.v1beta2.DependencyEdge} * * @property {string} lemma * [Lemma](https://en.wikipedia.org/wiki/Lemma_%28morphology%29) of the token. * - * @class + * @typedef Token + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.Token definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var Token = { @@ -238,7 +240,8 @@ var Token = { * Sentiment score between -1.0 (negative sentiment) and 1.0 * (positive sentiment). * - * @class + * @typedef Sentiment + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.Sentiment definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var Sentiment = { @@ -251,64 +254,65 @@ var Sentiment = { * @property {number} tag * The part of speech tag. * - * The number should be among the values of [Tag]{@link Tag} + * The number should be among the values of [Tag]{@link google.cloud.language.v1beta2.Tag} * * @property {number} aspect * The grammatical aspect. * - * The number should be among the values of [Aspect]{@link Aspect} + * The number should be among the values of [Aspect]{@link google.cloud.language.v1beta2.Aspect} * * @property {number} case * The grammatical case. * - * The number should be among the values of [Case]{@link Case} + * The number should be among the values of [Case]{@link google.cloud.language.v1beta2.Case} * * @property {number} form * The grammatical form. * - * The number should be among the values of [Form]{@link Form} + * The number should be among the values of [Form]{@link google.cloud.language.v1beta2.Form} * * @property {number} gender * The grammatical gender. * - * The number should be among the values of [Gender]{@link Gender} + * The number should be among the values of [Gender]{@link google.cloud.language.v1beta2.Gender} * * @property {number} mood * The grammatical mood. * - * The number should be among the values of [Mood]{@link Mood} + * The number should be among the values of [Mood]{@link google.cloud.language.v1beta2.Mood} * * @property {number} number * The grammatical number. * - * The number should be among the values of [Number]{@link Number} + * The number should be among the values of [Number]{@link google.cloud.language.v1beta2.Number} * * @property {number} person * The grammatical person. * - * The number should be among the values of [Person]{@link Person} + * The number should be among the values of [Person]{@link google.cloud.language.v1beta2.Person} * * @property {number} proper * The grammatical properness. * - * The number should be among the values of [Proper]{@link Proper} + * The number should be among the values of [Proper]{@link google.cloud.language.v1beta2.Proper} * * @property {number} reciprocity * The grammatical reciprocity. * - * The number should be among the values of [Reciprocity]{@link Reciprocity} + * The number should be among the values of [Reciprocity]{@link google.cloud.language.v1beta2.Reciprocity} * * @property {number} tense * The grammatical tense. * - * The number should be among the values of [Tense]{@link Tense} + * The number should be among the values of [Tense]{@link google.cloud.language.v1beta2.Tense} * * @property {number} voice * The grammatical voice. * - * The number should be among the values of [Voice]{@link Voice} + * The number should be among the values of [Voice]{@link google.cloud.language.v1beta2.Voice} * - * @class + * @typedef PartOfSpeech + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.PartOfSpeech definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var PartOfSpeech = { @@ -318,6 +322,7 @@ var PartOfSpeech = { * The part of speech tags enum. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Tag: { @@ -396,6 +401,7 @@ var PartOfSpeech = { * The characteristic of a verb that expresses time flow during an event. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Aspect: { @@ -426,6 +432,7 @@ var PartOfSpeech = { * adjective and determiner, take case inflection in agreement with the noun. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Case: { @@ -512,6 +519,7 @@ var PartOfSpeech = { * forms of adjectives and participles * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Form: { @@ -580,6 +588,7 @@ var PartOfSpeech = { * Gender classes of nouns reflected in the behaviour of associated words. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Gender: { @@ -608,6 +617,7 @@ var PartOfSpeech = { * The grammatical feature of verbs, used for showing modality and attitude. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Mood: { @@ -651,6 +661,7 @@ var PartOfSpeech = { * Count distinctions. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Number: { @@ -679,6 +690,7 @@ var PartOfSpeech = { * The distinction between the speaker, second person, third person, etc. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Person: { @@ -712,6 +724,7 @@ var PartOfSpeech = { * This category shows if the token is part of a proper name. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Proper: { @@ -735,6 +748,7 @@ var PartOfSpeech = { * Reciprocal features of a pronoun. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Reciprocity: { @@ -759,6 +773,7 @@ var PartOfSpeech = { * Time reference. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Tense: { @@ -803,6 +818,7 @@ var PartOfSpeech = { * participants identified by its arguments. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Voice: { @@ -841,9 +857,10 @@ var PartOfSpeech = { * @property {number} label * The parse label for the token. * - * The number should be among the values of [Label]{@link Label} + * The number should be among the values of [Label]{@link google.cloud.language.v1beta2.Label} * - * @class + * @typedef DependencyEdge + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.DependencyEdge definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var DependencyEdge = { @@ -853,6 +870,7 @@ var DependencyEdge = { * The parse label enum for the token. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Label: { @@ -1280,22 +1298,23 @@ var DependencyEdge = { * @property {Object} text * The mention text. * - * This object should have the same structure as [TextSpan]{@link TextSpan} + * This object should have the same structure as [TextSpan]{@link google.cloud.language.v1beta2.TextSpan} * * @property {number} type * The type of the entity mention. * - * The number should be among the values of [Type]{@link Type} + * The number should be among the values of [Type]{@link google.cloud.language.v1beta2.Type} * * @property {Object} sentiment - * For calls to {@link AnalyzeEntitySentiment} or if - * {@link AnnotateTextRequest.Features.extract_entity_sentiment} is set to + * For calls to AnalyzeEntitySentiment or if + * AnnotateTextRequest.Features.extract_entity_sentiment is set to * true, this field will contain the sentiment expressed for this mention of * the entity in the provided document. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1beta2.Sentiment} * - * @class + * @typedef EntityMention + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.EntityMention definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var EntityMention = { @@ -1305,6 +1324,7 @@ var EntityMention = { * The supported types of mentions. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ Type: { @@ -1333,9 +1353,10 @@ var EntityMention = { * * @property {number} beginOffset * The API calculates the beginning offset of the content in the original - * document according to the {@link EncodingType} specified in the API request. + * document according to the EncodingType specified in the API request. * - * @class + * @typedef TextSpan + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.TextSpan definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var TextSpan = { @@ -1352,7 +1373,8 @@ var TextSpan = { * The classifier's confidence of the category. Number represents how certain * the classifier is that this category represents the given text. * - * @class + * @typedef ClassificationCategory + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.ClassificationCategory definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var ClassificationCategory = { @@ -1365,15 +1387,16 @@ var ClassificationCategory = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} * * @property {number} encodingType * The encoding type used by the API to calculate sentence offsets for the * sentence sentiment. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} * - * @class + * @typedef AnalyzeSentimentRequest + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeSentimentRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeSentimentRequest = { @@ -1386,19 +1409,20 @@ var AnalyzeSentimentRequest = { * @property {Object} documentSentiment * The overall sentiment of the input document. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1beta2.Sentiment} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * * @property {Object[]} sentences * The sentiment for all the sentences in the document. * - * This object should have the same structure as [Sentence]{@link Sentence} + * This object should have the same structure as [Sentence]{@link google.cloud.language.v1beta2.Sentence} * - * @class + * @typedef AnalyzeSentimentResponse + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeSentimentResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeSentimentResponse = { @@ -1411,14 +1435,15 @@ var AnalyzeSentimentResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} * - * @class + * @typedef AnalyzeEntitySentimentRequest + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeEntitySentimentRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeEntitySentimentRequest = { @@ -1431,14 +1456,15 @@ var AnalyzeEntitySentimentRequest = { * @property {Object[]} entities * The recognized entities in the input document with associated sentiments. * - * This object should have the same structure as [Entity]{@link Entity} + * This object should have the same structure as [Entity]{@link google.cloud.language.v1beta2.Entity} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * - * @class + * @typedef AnalyzeEntitySentimentResponse + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeEntitySentimentResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeEntitySentimentResponse = { @@ -1451,14 +1477,15 @@ var AnalyzeEntitySentimentResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} * - * @class + * @typedef AnalyzeEntitiesRequest + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeEntitiesRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeEntitiesRequest = { @@ -1471,14 +1498,15 @@ var AnalyzeEntitiesRequest = { * @property {Object[]} entities * The recognized entities in the input document. * - * This object should have the same structure as [Entity]{@link Entity} + * This object should have the same structure as [Entity]{@link google.cloud.language.v1beta2.Entity} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * - * @class + * @typedef AnalyzeEntitiesResponse + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeEntitiesResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeEntitiesResponse = { @@ -1491,14 +1519,15 @@ var AnalyzeEntitiesResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} * - * @class + * @typedef AnalyzeSyntaxRequest + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeSyntaxRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeSyntaxRequest = { @@ -1511,19 +1540,20 @@ var AnalyzeSyntaxRequest = { * @property {Object[]} sentences * Sentences in the input document. * - * This object should have the same structure as [Sentence]{@link Sentence} + * This object should have the same structure as [Sentence]{@link google.cloud.language.v1beta2.Sentence} * * @property {Object[]} tokens * Tokens, along with their syntactic information, in the input document. * - * This object should have the same structure as [Token]{@link Token} + * This object should have the same structure as [Token]{@link google.cloud.language.v1beta2.Token} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * - * @class + * @typedef AnalyzeSyntaxResponse + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnalyzeSyntaxResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnalyzeSyntaxResponse = { @@ -1536,9 +1566,10 @@ var AnalyzeSyntaxResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} * - * @class + * @typedef ClassifyTextRequest + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.ClassifyTextRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var ClassifyTextRequest = { @@ -1551,9 +1582,10 @@ var ClassifyTextRequest = { * @property {Object[]} categories * Categories representing the input document. * - * This object should have the same structure as [ClassificationCategory]{@link ClassificationCategory} + * This object should have the same structure as [ClassificationCategory]{@link google.cloud.language.v1beta2.ClassificationCategory} * - * @class + * @typedef ClassifyTextResponse + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.ClassifyTextResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var ClassifyTextResponse = { @@ -1567,19 +1599,20 @@ var ClassifyTextResponse = { * @property {Object} document * Input document. * - * This object should have the same structure as [Document]{@link Document} + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} * * @property {Object} features * The enabled features. * - * This object should have the same structure as [Features]{@link Features} + * This object should have the same structure as [Features]{@link google.cloud.language.v1beta2.Features} * * @property {number} encodingType * The encoding type used by the API to calculate offsets. * - * The number should be among the values of [EncodingType]{@link EncodingType} + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} * - * @class + * @typedef AnnotateTextRequest + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnnotateTextRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnnotateTextRequest = { @@ -1604,7 +1637,8 @@ var AnnotateTextRequest = { * @property {boolean} classifyText * Classify the full document into categories. * - * @class + * @typedef Features + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnnotateTextRequest.Features definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ Features: { @@ -1617,41 +1651,42 @@ var AnnotateTextRequest = { * * @property {Object[]} sentences * Sentences in the input document. Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_syntax}. + * AnnotateTextRequest.Features.extract_syntax. * - * This object should have the same structure as [Sentence]{@link Sentence} + * This object should have the same structure as [Sentence]{@link google.cloud.language.v1beta2.Sentence} * * @property {Object[]} tokens * Tokens, along with their syntactic information, in the input document. * Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_syntax}. + * AnnotateTextRequest.Features.extract_syntax. * - * This object should have the same structure as [Token]{@link Token} + * This object should have the same structure as [Token]{@link google.cloud.language.v1beta2.Token} * * @property {Object[]} entities * Entities, along with their semantic information, in the input document. * Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_entities}. + * AnnotateTextRequest.Features.extract_entities. * - * This object should have the same structure as [Entity]{@link Entity} + * This object should have the same structure as [Entity]{@link google.cloud.language.v1beta2.Entity} * * @property {Object} documentSentiment * The overall sentiment for the document. Populated if the user enables - * {@link AnnotateTextRequest.Features.extract_document_sentiment}. + * AnnotateTextRequest.Features.extract_document_sentiment. * - * This object should have the same structure as [Sentiment]{@link Sentiment} + * This object should have the same structure as [Sentiment]{@link google.cloud.language.v1beta2.Sentiment} * * @property {string} language * The language of the text, which will be the same as the language specified * in the request or, if not specified, the automatically-detected language. - * See {@link Document.language} field for more details. + * See Document.language field for more details. * * @property {Object[]} categories * Categories identified in the input document. * - * This object should have the same structure as [ClassificationCategory]{@link ClassificationCategory} + * This object should have the same structure as [ClassificationCategory]{@link google.cloud.language.v1beta2.ClassificationCategory} * - * @class + * @typedef AnnotateTextResponse + * @memberof google.cloud.language.v1beta2 * @see [google.cloud.language.v1beta2.AnnotateTextResponse definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto} */ var AnnotateTextResponse = { @@ -1666,6 +1701,7 @@ var AnnotateTextResponse = { * differently. * * @enum {number} + * @memberof google.cloud.language.v1beta2 */ var EncodingType = { diff --git a/packages/google-cloud-language/src/v1beta2/index.js b/packages/google-cloud-language/src/v1beta2/index.js index eabebb8f311..4921903da71 100644 --- a/packages/google-cloud-language/src/v1beta2/index.js +++ b/packages/google-cloud-language/src/v1beta2/index.js @@ -1,34 +1,19 @@ -/* - * Copyright 2017, 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. - */ -'use strict'; - -var languageServiceClient = require('./language_service_client'); -var gax = require('google-gax'); -var extend = require('extend'); +// Copyright 2017, 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. -function v1beta2(options) { - options = extend({ - scopes: v1beta2.ALL_SCOPES - }, options); - var gaxGrpc = gax.grpc(options); - return languageServiceClient(gaxGrpc); -} +'use strict'; -v1beta2.GAPIC_VERSION = '0.0.5'; -v1beta2.SERVICE_ADDRESS = languageServiceClient.SERVICE_ADDRESS; -v1beta2.ALL_SCOPES = languageServiceClient.ALL_SCOPES; +const LanguageServiceClient = require('./language_service_client'); -module.exports = v1beta2; \ No newline at end of file +module.exports.LanguageServiceClient = LanguageServiceClient; diff --git a/packages/google-cloud-language/src/v1beta2/language_service_client.js b/packages/google-cloud-language/src/v1beta2/language_service_client.js index 6c9e1d52537..5aa12bd05f5 100644 --- a/packages/google-cloud-language/src/v1beta2/language_service_client.js +++ b/packages/google-cloud-language/src/v1beta2/language_service_client.js @@ -1,482 +1,509 @@ -/* - * Copyright 2017, 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. - * - * EDITING INSTRUCTIONS - * This file was generated from the file - * https://github.com/googleapis/googleapis/blob/master/google/cloud/language/v1beta2/language_service.proto, - * and updates to that file get reflected here through a refresh process. - * For the short term, the refresh process will only be runnable by Google - * engineers. - * - * The only allowed edits are to method and file documentation. A 3-way - * merge preserves those additions if the generated source changes. - */ -/* TODO: introduce line-wrapping so that it never exceeds the limit. */ -/* jscs: disable maximumLineLength */ -'use strict'; - -var configData = require('./language_service_client_config'); -var extend = require('extend'); -var gax = require('google-gax'); -var googleProtoFiles = require('google-proto-files'); -var path = require('path'); +// Copyright 2017, 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. -var SERVICE_ADDRESS = 'language.googleapis.com'; +'use strict'; -var DEFAULT_SERVICE_PORT = 443; +const gapicConfig = require('./language_service_client_config'); +const gax = require('google-gax'); +const merge = require('lodash.merge'); +const path = require('path'); -var CODE_GEN_NAME_VERSION = 'gapic/0.0.5'; - -/** - * The scopes needed to make gRPC calls to all of the methods defined in - * this service. - */ -var ALL_SCOPES = [ - 'https://www.googleapis.com/auth/cloud-platform' -]; +const VERSION = require('../../package.json').version; /** * Provides text analysis operations such as sentiment analysis and entity * recognition. * - * * @class + * @memberof v1beta2 */ -function LanguageServiceClient(gaxGrpc, loadedProtos, opts) { - opts = extend({ - servicePath: SERVICE_ADDRESS, - port: DEFAULT_SERVICE_PORT, - clientConfig: {} - }, opts); +class LanguageServiceClient { + /** + * Construct an instance of LanguageServiceClient. + * + * @param {object=} options - The configuration object. See the subsequent + * parameters for more details. + * @param {object=} options.credentials - Credentials object. + * @param {string=} options.credentials.client_email + * @param {string=} options.credentials.private_key + * @param {string=} options.email - Account email address. Required when + * usaing a .pem or .p12 keyFilename. + * @param {string=} options.keyFilename - Full path to the a .json, .pem, or + * .p12 key downloaded from the Google Developers Console. If you provide + * a path to a JSON file, the projectId option above is not necessary. + * NOTE: .pem and .p12 require you to specify options.email as well. + * @param {number=} options.port - The port on which to connect to + * the remote host. + * @param {string=} options.projectId - The project ID from the Google + * Developer's Console, e.g. 'grape-spaceship-123'. We will also check + * the environment variable GCLOUD_PROJECT for your project ID. If your + * app is running in an environment which supports + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. + * @param {function=} options.promise - Custom promise module to use instead + * of native Promises. + * @param {string=} options.servicePath - The domain name of the + * API remote host. + */ + constructor(opts) { + this._descriptors = {}; - var googleApiClient = [ - 'gl-node/' + process.versions.node - ]; - if (opts.libName && opts.libVersion) { - googleApiClient.push(opts.libName + '/' + opts.libVersion); - } - googleApiClient.push( - CODE_GEN_NAME_VERSION, - 'gax/' + gax.version, - 'grpc/' + gaxGrpc.grpcVersion - ); + // Ensure that options include the service address and port. + opts = Object.assign( + { + clientConfig: {}, + port: this.constructor.port, + servicePath: this.constructor.servicePath, + }, + opts + ); - var defaults = gaxGrpc.constructSettings( - 'google.cloud.language.v1beta2.LanguageService', - configData, - opts.clientConfig, - {'x-goog-api-client': googleApiClient.join(' ')}); + // Create a `gaxGrpc` object, with any grpc-specific options + // sent to the client. + opts.scopes = this.constructor.scopes; + var gaxGrpc = gax.grpc(opts); - var self = this; + // Save the auth object to the client, for use by other methods. + this.auth = gaxGrpc.auth; - this.auth = gaxGrpc.auth; - var languageServiceStub = gaxGrpc.createStub( - loadedProtos.google.cloud.language.v1beta2.LanguageService, - opts); - var languageServiceStubMethods = [ - 'analyzeSentiment', - 'analyzeEntities', - 'analyzeEntitySentiment', - 'analyzeSyntax', - 'classifyText', - 'annotateText' - ]; - languageServiceStubMethods.forEach(function(methodName) { - self['_' + methodName] = gax.createApiCall( - languageServiceStub.then(function(languageServiceStub) { - return function() { - var args = Array.prototype.slice.call(arguments, 0); - return languageServiceStub[methodName].apply(languageServiceStub, args); - }; - }), - defaults[methodName], - null); - }); -} + // Determine the client header string. + var clientHeader = [ + `gl-node/${process.version.node}`, + `grpc/${gaxGrpc.grpcVersion}`, + `gax/${gax.version}`, + `gapic/${VERSION}`, + ]; + if (opts.libName && opts.libVersion) { + clientHeader.push(`${opts.libName}/${opts.libVersion}`); + } + // Load the applicable protos. + var protos = merge( + {}, + gaxGrpc.loadProto( + path.join(__dirname, '..', '..', 'protos'), + 'google/cloud/language/v1beta2/language_service.proto' + ) + ); -/** - * Get the project ID used by this class. - * @param {function(Error, string)} callback - the callback to be called with - * the current project Id. - */ -LanguageServiceClient.prototype.getProjectId = function(callback) { - return this.auth.getProjectId(callback); -}; - -// Service calls + // Put together the default options sent with requests. + var defaults = gaxGrpc.constructSettings( + 'google.cloud.language.v1beta2.LanguageService', + gapicConfig, + opts.clientConfig, + {'x-goog-api-client': clientHeader.join(' ')} + ); -/** - * Analyzes the sentiment of the provided text. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate sentence offsets for the - * sentence sentiment. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeSentimentResponse]{@link AnalyzeSentimentResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1beta2({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeSentiment({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeSentiment = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; - } - if (options === undefined) { - options = {}; - } + // Set up a dictionary of "inner API calls"; the core implementation + // of calling the API is handled in `google-gax`, with this code + // merely providing the destination and request information. + this._innerApiCalls = {}; - return this._analyzeSentiment(request, options, callback); -}; + // Put together the "service stub" for + // google.cloud.language.v1beta2.LanguageService. + var languageServiceStub = gaxGrpc.createStub( + protos.google.cloud.language.v1beta2.LanguageService, + opts + ); -/** - * Finds named entities (currently proper names and common nouns) in the text - * along with entity types, salience, mentions for each entity, and - * other properties. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeEntitiesResponse]{@link AnalyzeEntitiesResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1beta2({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeEntities({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeEntities = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; + // Iterate over each of the methods that the service provides + // and create an API call method for each. + var languageServiceStubMethods = [ + 'analyzeSentiment', + 'analyzeEntities', + 'analyzeEntitySentiment', + 'analyzeSyntax', + 'classifyText', + 'annotateText', + ]; + for (let methodName of languageServiceStubMethods) { + this._innerApiCalls[methodName] = gax.createApiCall( + languageServiceStub.then( + stub => + function() { + var args = Array.prototype.slice.call(arguments, 0); + return stub[methodName].apply(stub, args); + } + ), + defaults[methodName], + null + ); + } } - if (options === undefined) { - options = {}; + + /** + * The DNS address for this API service. + */ + static get servicePath() { + return 'language.googleapis.com'; } - return this._analyzeEntities(request, options, callback); -}; + /** + * The port for this API service. + */ + static get port() { + return 443; + } -/** - * Finds entities, similar to {@link AnalyzeEntities} in the text and analyzes - * sentiment associated with each entity and its mentions. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeEntitySentimentResponse]{@link AnalyzeEntitySentimentResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeEntitySentimentResponse]{@link AnalyzeEntitySentimentResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1beta2({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeEntitySentiment({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeEntitySentiment = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; + /** + * The scopes needed to make gRPC calls for every method defined + * in this service. + */ + static get scopes() { + return ['https://www.googleapis.com/auth/cloud-platform']; } - if (options === undefined) { - options = {}; + + /** + * Return the project ID used by this class. + * @param {function(Error, string)} callback - the callback to + * be called with the current project Id. + */ + getProjectId(callback) { + return this.auth.getProjectId(callback); } - return this._analyzeEntitySentiment(request, options, callback); -}; + // ------------------- + // -- Service calls -- + // ------------------- -/** - * Analyzes the syntax of the text and provides sentence boundaries and - * tokenization along with part of speech tags, dependency trees, and other - * properties. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnalyzeSyntaxResponse]{@link AnalyzeSyntaxResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnalyzeSyntaxResponse]{@link AnalyzeSyntaxResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1beta2({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.analyzeSyntax({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.analyzeSyntax = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; - } - if (options === undefined) { - options = {}; + /** + * Analyzes the sentiment of the provided text. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate sentence offsets for the + * sentence sentiment. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeSentimentResponse]{@link google.cloud.language.v1beta2.AnalyzeSentimentResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeSentimentResponse]{@link google.cloud.language.v1beta2.AnalyzeSentimentResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1beta2.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeSentiment({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeSentiment(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; + + return this._innerApiCalls.analyzeSentiment(request, options, callback); } - return this._analyzeSyntax(request, options, callback); -}; + /** + * Finds named entities (currently proper names and common nouns) in the text + * along with entity types, salience, mentions for each entity, and + * other properties. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeEntitiesResponse]{@link google.cloud.language.v1beta2.AnalyzeEntitiesResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeEntitiesResponse]{@link google.cloud.language.v1beta2.AnalyzeEntitiesResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1beta2.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeEntities({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeEntities(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; -/** - * Classifies a document into categories. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [ClassifyTextResponse]{@link ClassifyTextResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [ClassifyTextResponse]{@link ClassifyTextResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1beta2({ - * // optional auth parameters. - * }); - * - * var document = {}; - * client.classifyText({document: document}).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.classifyText = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; - } - if (options === undefined) { - options = {}; + return this._innerApiCalls.analyzeEntities(request, options, callback); } - return this._classifyText(request, options, callback); -}; + /** + * Finds entities, similar to AnalyzeEntities in the text and analyzes + * sentiment associated with each entity and its mentions. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeEntitySentimentResponse]{@link google.cloud.language.v1beta2.AnalyzeEntitySentimentResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeEntitySentimentResponse]{@link google.cloud.language.v1beta2.AnalyzeEntitySentimentResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1beta2.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeEntitySentiment({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeEntitySentiment(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; -/** - * A convenience method that provides all syntax, sentiment, entity, and - * classification features in one call. - * - * @param {Object} request - * The request object that will be sent. - * @param {Object} request.document - * Input document. - * - * This object should have the same structure as [Document]{@link Document} - * @param {Object} request.features - * The enabled features. - * - * This object should have the same structure as [Features]{@link Features} - * @param {number=} request.encodingType - * The encoding type used by the API to calculate offsets. - * - * The number should be among the values of [EncodingType]{@link EncodingType} - * @param {Object=} options - * Optional parameters. You can override the default settings for this call, e.g, timeout, - * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. - * @param {function(?Error, ?Object)=} callback - * The function which will be called with the result of the API call. - * - * The second parameter to the callback is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse}. - * @return {Promise} - The promise which resolves to an array. - * The first element of the array is an object representing [AnnotateTextResponse]{@link AnnotateTextResponse}. - * The promise has a method named "cancel" which cancels the ongoing API call. - * - * @example - * - * var language = require('@google-cloud/language'); - * - * var client = language.v1beta2({ - * // optional auth parameters. - * }); - * - * var document = {}; - * var features = {}; - * var request = { - * document: document, - * features: features - * }; - * client.annotateText(request).then(function(responses) { - * var response = responses[0]; - * // doThingsWith(response) - * }) - * .catch(function(err) { - * console.error(err); - * }); - */ -LanguageServiceClient.prototype.annotateText = function(request, options, callback) { - if (options instanceof Function && callback === undefined) { - callback = options; - options = {}; - } - if (options === undefined) { - options = {}; + return this._innerApiCalls.analyzeEntitySentiment( + request, + options, + callback + ); } - return this._annotateText(request, options, callback); -}; + /** + * Analyzes the syntax of the text and provides sentence boundaries and + * tokenization along with part of speech tags, dependency trees, and other + * properties. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnalyzeSyntaxResponse]{@link google.cloud.language.v1beta2.AnalyzeSyntaxResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnalyzeSyntaxResponse]{@link google.cloud.language.v1beta2.AnalyzeSyntaxResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1beta2.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.analyzeSyntax({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + analyzeSyntax(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; -function LanguageServiceClientBuilder(gaxGrpc) { - if (!(this instanceof LanguageServiceClientBuilder)) { - return new LanguageServiceClientBuilder(gaxGrpc); + return this._innerApiCalls.analyzeSyntax(request, options, callback); } - var languageServiceStubProtos = gaxGrpc.loadProto( - path.join(__dirname, '..', '..', 'protos', 'google/cloud/language/v1beta2/language_service.proto')); - extend(this, languageServiceStubProtos.google.cloud.language.v1beta2); + /** + * Classifies a document into categories. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [ClassifyTextResponse]{@link google.cloud.language.v1beta2.ClassifyTextResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [ClassifyTextResponse]{@link google.cloud.language.v1beta2.ClassifyTextResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1beta2.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * client.classifyText({document: document}) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); + */ + classifyText(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; + return this._innerApiCalls.classifyText(request, options, callback); + } /** - * Build a new instance of {@link LanguageServiceClient}. - * - * @param {Object=} opts - The optional parameters. - * @param {String=} opts.servicePath - * The domain name of the API remote host. - * @param {number=} opts.port - * The port on which to connect to the remote host. - * @param {grpc.ClientCredentials=} opts.sslCreds - * A ClientCredentials for use with an SSL-enabled channel. - * @param {Object=} opts.clientConfig - * The customized config to build the call settings. See - * {@link gax.constructSettings} for the format. + * A convenience method that provides all syntax, sentiment, entity, and + * classification features in one call. + * + * @param {Object} request + * The request object that will be sent. + * @param {Object} request.document + * Input document. + * + * This object should have the same structure as [Document]{@link google.cloud.language.v1beta2.Document} + * @param {Object} request.features + * The enabled features. + * + * This object should have the same structure as [Features]{@link google.cloud.language.v1beta2.Features} + * @param {number=} request.encodingType + * The encoding type used by the API to calculate offsets. + * + * The number should be among the values of [EncodingType]{@link google.cloud.language.v1beta2.EncodingType} + * @param {Object=} options + * Optional parameters. You can override the default settings for this call, e.g, timeout, + * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. + * @param {function(?Error, ?Object)=} callback + * The function which will be called with the result of the API call. + * + * The second parameter to the callback is an object representing [AnnotateTextResponse]{@link google.cloud.language.v1beta2.AnnotateTextResponse}. + * @returns {Promise} - The promise which resolves to an array. + * The first element of the array is an object representing [AnnotateTextResponse]{@link google.cloud.language.v1beta2.AnnotateTextResponse}. + * The promise has a method named "cancel" which cancels the ongoing API call. + * + * @example + * + * const language = require('@google-cloud/language'); + * + * var client = new language.v1beta2.LanguageServiceClient({ + * // optional auth parameters. + * }); + * + * var document = {}; + * var features = {}; + * var request = { + * document: document, + * features: features, + * }; + * client.annotateText(request) + * .then(responses => { + * var response = responses[0]; + * // doThingsWith(response) + * }) + * .catch(err => { + * console.error(err); + * }); */ - this.languageServiceClient = function(opts) { - return new LanguageServiceClient(gaxGrpc, languageServiceStubProtos, opts); - }; - extend(this.languageServiceClient, LanguageServiceClient); + annotateText(request, options, callback) { + if (options instanceof Function && callback === undefined) { + callback = options; + options = {}; + } + options = options || {}; + + return this._innerApiCalls.annotateText(request, options, callback); + } } -module.exports = LanguageServiceClientBuilder; -module.exports.SERVICE_ADDRESS = SERVICE_ADDRESS; -module.exports.ALL_SCOPES = ALL_SCOPES; \ No newline at end of file + +module.exports = LanguageServiceClient; diff --git a/packages/google-cloud-language/system-test/.eslintrc.yml b/packages/google-cloud-language/system-test/.eslintrc.yml new file mode 100644 index 00000000000..2e6882e46d2 --- /dev/null +++ b/packages/google-cloud-language/system-test/.eslintrc.yml @@ -0,0 +1,6 @@ +--- +env: + mocha: true +rules: + node/no-unpublished-require: off + no-console: off diff --git a/packages/google-cloud-language/system-test/language_service_smoke_test.js b/packages/google-cloud-language/system-test/language_service_smoke_test.js new file mode 100644 index 00000000000..eb13a4a2849 --- /dev/null +++ b/packages/google-cloud-language/system-test/language_service_smoke_test.js @@ -0,0 +1,40 @@ +// Copyright 2017, 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. + +'use strict'; + +describe('LanguageServiceSmokeTest', () => { + it('successfully makes a call to the service', done => { + const language = require('../src'); + + var client = new language.v1.LanguageServiceClient({ + // optional auth parameters. + }); + + var content = 'Hello, world!'; + var type = 'PLAIN_TEXT'; + var document = { + content: content, + type: type, + }; + client + .analyzeSentiment({document: document}) + .then(responses => { + var response = responses[0]; + console.log(response); + }) + .then(done) + .catch(done); + }); +}); diff --git a/packages/google-cloud-language/test/.eslintrc.yml b/packages/google-cloud-language/test/.eslintrc.yml new file mode 100644 index 00000000000..73f7bbc946f --- /dev/null +++ b/packages/google-cloud-language/test/.eslintrc.yml @@ -0,0 +1,5 @@ +--- +env: + mocha: true +rules: + node/no-unpublished-require: off diff --git a/packages/google-cloud-language/test/gapic-v1.js b/packages/google-cloud-language/test/gapic-v1.js index 268e21d2fd5..4b9a0e33050 100644 --- a/packages/google-cloud-language/test/gapic-v1.js +++ b/packages/google-cloud-language/test/gapic-v1.js @@ -1,262 +1,301 @@ -/* - * Copyright 2017, 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. - */ +// Copyright 2017, 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. + 'use strict'; -var assert = require('assert'); -var language = require('../src'); +const assert = require('assert'); + +const languageModule = require('../src'); var FAKE_STATUS_CODE = 1; var error = new Error(); error.code = FAKE_STATUS_CODE; -describe('LanguageServiceClient', function() { - describe('analyzeSentiment', function() { - it('invokes analyzeSentiment without error', function(done) { - var client = language.v1(); +describe('LanguageServiceClient', () => { + describe('analyzeSentiment', () => { + it('invokes analyzeSentiment without error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeSentiment = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeSentiment = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeSentiment(request, function(err, response) { + client.analyzeSentiment(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeSentiment with error', function(done) { - var client = language.v1(); + it('invokes analyzeSentiment with error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeSentiment = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeSentiment = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeSentiment(request, function(err, response) { + client.analyzeSentiment(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('analyzeEntities', function() { - it('invokes analyzeEntities without error', function(done) { - var client = language.v1(); + describe('analyzeEntities', () => { + it('invokes analyzeEntities without error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeEntities = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeEntities = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeEntities(request, function(err, response) { + client.analyzeEntities(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeEntities with error', function(done) { - var client = language.v1(); + it('invokes analyzeEntities with error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeEntities = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeEntities = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeEntities(request, function(err, response) { + client.analyzeEntities(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('analyzeEntitySentiment', function() { - it('invokes analyzeEntitySentiment without error', function(done) { - var client = language.v1(); + describe('analyzeEntitySentiment', () => { + it('invokes analyzeEntitySentiment without error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeEntitySentiment = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeEntitySentiment = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeEntitySentiment(request, function(err, response) { + client.analyzeEntitySentiment(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeEntitySentiment with error', function(done) { - var client = language.v1(); + it('invokes analyzeEntitySentiment with error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeEntitySentiment = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeEntitySentiment = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeEntitySentiment(request, function(err, response) { + client.analyzeEntitySentiment(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('analyzeSyntax', function() { - it('invokes analyzeSyntax without error', function(done) { - var client = language.v1(); + describe('analyzeSyntax', () => { + it('invokes analyzeSyntax without error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeSyntax = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeSyntax = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeSyntax(request, function(err, response) { + client.analyzeSyntax(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeSyntax with error', function(done) { - var client = language.v1(); + it('invokes analyzeSyntax with error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeSyntax = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeSyntax = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeSyntax(request, function(err, response) { + client.analyzeSyntax(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('annotateText', function() { - it('invokes annotateText without error', function(done) { - var client = language.v1(); + describe('annotateText', () => { + it('invokes annotateText without error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var features = {}; var request = { - document : document, - features : features + document: document, + features: features, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._annotateText = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.annotateText = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.annotateText(request, function(err, response) { + client.annotateText(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes annotateText with error', function(done) { - var client = language.v1(); + it('invokes annotateText with error', done => { + var client = new languageModule.v1.LanguageServiceClient(); // Mock request var document = {}; var features = {}; var request = { - document : document, - features : features + document: document, + features: features, }; // Mock Grpc layer - client._annotateText = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.annotateText = mockSimpleGrpcMethod( + request, + null, + error + ); - client.annotateText(request, function(err, response) { + client.annotateText(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - }); function mockSimpleGrpcMethod(expectedRequest, response, error) { diff --git a/packages/google-cloud-language/test/gapic-v1beta2.js b/packages/google-cloud-language/test/gapic-v1beta2.js index 6614ae65865..ce078db1b27 100644 --- a/packages/google-cloud-language/test/gapic-v1beta2.js +++ b/packages/google-cloud-language/test/gapic-v1beta2.js @@ -1,305 +1,352 @@ -/* - * Copyright 2017, 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. - */ +// Copyright 2017, 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. + 'use strict'; -var assert = require('assert'); -var language = require('../src'); +const assert = require('assert'); + +const languageModule = require('../src'); var FAKE_STATUS_CODE = 1; var error = new Error(); error.code = FAKE_STATUS_CODE; -describe('LanguageServiceClient', function() { - describe('analyzeSentiment', function() { - it('invokes analyzeSentiment without error', function(done) { - var client = language.v1beta2(); +describe('LanguageServiceClient', () => { + describe('analyzeSentiment', () => { + it('invokes analyzeSentiment without error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeSentiment = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeSentiment = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeSentiment(request, function(err, response) { + client.analyzeSentiment(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeSentiment with error', function(done) { - var client = language.v1beta2(); + it('invokes analyzeSentiment with error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeSentiment = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeSentiment = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeSentiment(request, function(err, response) { + client.analyzeSentiment(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('analyzeEntities', function() { - it('invokes analyzeEntities without error', function(done) { - var client = language.v1beta2(); + describe('analyzeEntities', () => { + it('invokes analyzeEntities without error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeEntities = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeEntities = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeEntities(request, function(err, response) { + client.analyzeEntities(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeEntities with error', function(done) { - var client = language.v1beta2(); + it('invokes analyzeEntities with error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeEntities = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeEntities = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeEntities(request, function(err, response) { + client.analyzeEntities(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('analyzeEntitySentiment', function() { - it('invokes analyzeEntitySentiment without error', function(done) { - var client = language.v1beta2(); + describe('analyzeEntitySentiment', () => { + it('invokes analyzeEntitySentiment without error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeEntitySentiment = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeEntitySentiment = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeEntitySentiment(request, function(err, response) { + client.analyzeEntitySentiment(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeEntitySentiment with error', function(done) { - var client = language.v1beta2(); + it('invokes analyzeEntitySentiment with error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeEntitySentiment = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeEntitySentiment = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeEntitySentiment(request, function(err, response) { + client.analyzeEntitySentiment(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('analyzeSyntax', function() { - it('invokes analyzeSyntax without error', function(done) { - var client = language.v1beta2(); + describe('analyzeSyntax', () => { + it('invokes analyzeSyntax without error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._analyzeSyntax = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.analyzeSyntax = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.analyzeSyntax(request, function(err, response) { + client.analyzeSyntax(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes analyzeSyntax with error', function(done) { - var client = language.v1beta2(); + it('invokes analyzeSyntax with error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._analyzeSyntax = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.analyzeSyntax = mockSimpleGrpcMethod( + request, + null, + error + ); - client.analyzeSyntax(request, function(err, response) { + client.analyzeSyntax(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('classifyText', function() { - it('invokes classifyText without error', function(done) { - var client = language.v1beta2(); + describe('classifyText', () => { + it('invokes classifyText without error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock response var expectedResponse = {}; // Mock Grpc layer - client._classifyText = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.classifyText = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.classifyText(request, function(err, response) { + client.classifyText(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes classifyText with error', function(done) { - var client = language.v1beta2(); + it('invokes classifyText with error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var request = { - document : document + document: document, }; // Mock Grpc layer - client._classifyText = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.classifyText = mockSimpleGrpcMethod( + request, + null, + error + ); - client.classifyText(request, function(err, response) { + client.classifyText(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - describe('annotateText', function() { - it('invokes annotateText without error', function(done) { - var client = language.v1beta2(); + describe('annotateText', () => { + it('invokes annotateText without error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var features = {}; var request = { - document : document, - features : features + document: document, + features: features, }; // Mock response - var language_ = 'language-1613589672'; + var language = 'language-1613589672'; var expectedResponse = { - language : language_ + language: language, }; // Mock Grpc layer - client._annotateText = mockSimpleGrpcMethod(request, expectedResponse); + client._innerApiCalls.annotateText = mockSimpleGrpcMethod( + request, + expectedResponse + ); - client.annotateText(request, function(err, response) { + client.annotateText(request, (err, response) => { assert.ifError(err); assert.deepStrictEqual(response, expectedResponse); done(); }); }); - it('invokes annotateText with error', function(done) { - var client = language.v1beta2(); + it('invokes annotateText with error', done => { + var client = new languageModule.v1beta2.LanguageServiceClient(); // Mock request var document = {}; var features = {}; var request = { - document : document, - features : features + document: document, + features: features, }; // Mock Grpc layer - client._annotateText = mockSimpleGrpcMethod(request, null, error); + client._innerApiCalls.annotateText = mockSimpleGrpcMethod( + request, + null, + error + ); - client.annotateText(request, function(err, response) { + client.annotateText(request, (err, response) => { assert(err instanceof Error); assert.equal(err.code, FAKE_STATUS_CODE); + assert(typeof response === 'undefined'); done(); }); }); }); - }); function mockSimpleGrpcMethod(expectedRequest, response, error) {