UNPKG

7.02 kBMarkdownView Raw
1[//]: # "This README.md file is auto-generated, all changes to this file will be lost."
2[//]: # "To regenerate it, use `python -m synthtool`."
3<img src="https://avatars2.githubusercontent.com/u/2810941?v=3&s=96" alt="Google Cloud Platform logo" title="Google Cloud Platform" align="right" height="96" width="96"/>
4
5# [Natural Language: Node.js Client](https://github.com/googleapis/nodejs-language)
6
7[![release level](https://img.shields.io/badge/release%20level-general%20availability%20%28GA%29-brightgreen.svg?style=flat)](https://cloud.google.com/terms/launch-stages)
8[![npm version](https://img.shields.io/npm/v/@google-cloud/language.svg)](https://www.npmjs.org/package/@google-cloud/language)
9[![codecov](https://img.shields.io/codecov/c/github/googleapis/nodejs-language/main.svg?style=flat)](https://codecov.io/gh/googleapis/nodejs-language)
10
11
12
13
14[Cloud Natural Language API](https://cloud.google.com/natural-language/docs) provides natural
15language understanding technologies to developers, including sentiment analysis, entity
16analysis, and syntax analysis. This API is part of the larger Cloud Machine Learning API family.
17
18
19A comprehensive list of changes in each version may be found in
20[the CHANGELOG](https://github.com/googleapis/nodejs-language/blob/main/CHANGELOG.md).
21
22* [Natural Language Node.js Client API Reference][client-docs]
23* [Natural Language Documentation][product-docs]
24* [github.com/googleapis/nodejs-language](https://github.com/googleapis/nodejs-language)
25
26Read more about the client libraries for Cloud APIs, including the older
27Google APIs Client Libraries, in [Client Libraries Explained][explained].
28
29[explained]: https://cloud.google.com/apis/docs/client-libraries-explained
30
31**Table of contents:**
32
33
34* [Quickstart](#quickstart)
35 * [Before you begin](#before-you-begin)
36 * [Installing the client library](#installing-the-client-library)
37 * [Using the client library](#using-the-client-library)
38* [Samples](#samples)
39* [Versioning](#versioning)
40* [Contributing](#contributing)
41* [License](#license)
42
43## Quickstart
44
45### Before you begin
46
471. [Select or create a Cloud Platform project][projects].
481. [Enable billing for your project][billing].
491. [Enable the Natural Language API][enable_api].
501. [Set up authentication with a service account][auth] so you can access the
51 API from your local workstation.
52
53### Installing the client library
54
55```bash
56npm install @google-cloud/language
57```
58
59
60### Using the client library
61
62```javascript
63async function quickstart() {
64 // Imports the Google Cloud client library
65 const language = require('@google-cloud/language');
66
67 // Instantiates a client
68 const client = new language.LanguageServiceClient();
69
70 // The text to analyze
71 const text = 'Hello, world!';
72
73 const document = {
74 content: text,
75 type: 'PLAIN_TEXT',
76 };
77
78 // Detects the sentiment of the text
79 const [result] = await client.analyzeSentiment({document: document});
80 const sentiment = result.documentSentiment;
81
82 console.log(`Text: ${text}`);
83 console.log(`Sentiment score: ${sentiment.score}`);
84 console.log(`Sentiment magnitude: ${sentiment.magnitude}`);
85}
86
87```
88
89
90
91## Samples
92
93Samples are in the [`samples/`](https://github.com/googleapis/nodejs-language/tree/main/samples) directory. Each sample's `README.md` has instructions for running its sample.
94
95| Sample | Source Code | Try it |
96| --------------------------- | --------------------------------- | ------ |
97| Analyze v1 | [source code](https://github.com/googleapis/nodejs-language/blob/main/samples/analyze.v1.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-language&page=editor&open_in_editor=samples/analyze.v1.js,samples/README.md) |
98| Quickstart | [source code](https://github.com/googleapis/nodejs-language/blob/main/samples/quickstart.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-language&page=editor&open_in_editor=samples/quickstart.js,samples/README.md) |
99| Set Endpoint | [source code](https://github.com/googleapis/nodejs-language/blob/main/samples/setEndpoint.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-language&page=editor&open_in_editor=samples/setEndpoint.js,samples/README.md) |
100
101
102
103The [Natural Language Node.js Client API Reference][client-docs] documentation
104also contains samples.
105
106## Supported Node.js Versions
107
108Our client libraries follow the [Node.js release schedule](https://nodejs.org/en/about/releases/).
109Libraries are compatible with all current _active_ and _maintenance_ versions of
110Node.js.
111
112Client libraries targeting some end-of-life versions of Node.js are available, and
113can be installed via npm [dist-tags](https://docs.npmjs.com/cli/dist-tag).
114The dist-tags follow the naming convention `legacy-(version)`.
115
116_Legacy Node.js versions are supported as a best effort:_
117
118* Legacy versions will not be tested in continuous integration.
119* Some security patches may not be able to be backported.
120* Dependencies will not be kept up-to-date, and features will not be backported.
121
122#### Legacy tags available
123
124* `legacy-8`: install client libraries from this dist-tag for versions
125 compatible with Node.js 8.
126
127## Versioning
128
129This library follows [Semantic Versioning](http://semver.org/).
130
131
132This library is considered to be **General Availability (GA)**. This means it
133is stable; the code surface will not change in backwards-incompatible ways
134unless absolutely necessary (e.g. because of critical security issues) or with
135an extensive deprecation period. Issues and requests against **GA** libraries
136are addressed with the highest priority.
137
138
139
140
141
142More Information: [Google Cloud Platform Launch Stages][launch_stages]
143
144[launch_stages]: https://cloud.google.com/terms/launch-stages
145
146## Contributing
147
148Contributions welcome! See the [Contributing Guide](https://github.com/googleapis/nodejs-language/blob/main/CONTRIBUTING.md).
149
150Please note that this `README.md`, the `samples/README.md`,
151and a variety of configuration files in this repository (including `.nycrc` and `tsconfig.json`)
152are generated from a central template. To edit one of these files, make an edit
153to its templates in
154[directory](https://github.com/googleapis/synthtool).
155
156## License
157
158Apache Version 2.0
159
160See [LICENSE](https://github.com/googleapis/nodejs-language/blob/main/LICENSE)
161
162[client-docs]: https://cloud.google.com/nodejs/docs/reference/language/latest
163[product-docs]: https://cloud.google.com/natural-language/docs/
164[shell_img]: https://gstatic.com/cloudssh/images/open-btn.png
165[projects]: https://console.cloud.google.com/project
166[billing]: https://support.google.com/cloud/answer/6293499#enable-billing
167[enable_api]: https://console.cloud.google.com/flows/enableapi?apiid=language.googleapis.com
168[auth]: https://cloud.google.com/docs/authentication/getting-started