3
3
These samples show how to use the [ Google Cloud Natural Language API] [ language-api ]
4
4
to analyze text.
5
5
6
- This repository contains samples that use the [ Google Cloud
7
- Library for PHP] [ google-cloud-php ] to make REST calls as well as
8
- contains samples using the more-efficient (though sometimes more
9
- complex) [ GRPC] [ grpc ] API. The GRPC API also allows streaming requests.
10
-
11
6
[ language-api ] : http://cloud.google.com/natural-language
12
7
[ google-cloud-php ] : https://googlecloudplatform.github.io/google-cloud-php/
13
- [ grpc ] : http://grpc.io
14
-
15
8
16
9
## Setup
17
10
@@ -56,6 +49,10 @@ authentication:
56
49
57
50
1 . Set ` GOOGLE_APPLICATION_CREDENTIALS ` environment variable pointing to that file.
58
51
52
+ 1 . If you are using the Analyze Entity Sentiment or Classify Text features, you will need to install and enable the [ gRPC extension for PHP] [ grpc ] .
53
+
54
+ [ grpc ] : https://cloud.google.com/php/grpc
55
+
59
56
## Samples
60
57
61
58
To run the Natural Language Samples:
@@ -76,12 +73,14 @@ To run the Natural Language Samples:
76
73
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
77
74
78
75
Available commands:
79
- all Analyze syntax, sentiment and entities in text.
80
- entities Analyze entities in text.
81
- help Displays help for a command
82
- list Lists commands
83
- sentiment Analyze sentiment in text.
84
- syntax Analyze syntax in text.
76
+ all Analyze syntax, sentiment and entities in text.
77
+ entities Analyze entities in text.
78
+ help Displays help for a command
79
+ list Lists commands
80
+ sentiment Analyze sentiment in text.
81
+ syntax Analyze syntax in text.
82
+ entity-sentiment Analyze sentiment of entities in text.
83
+ classify Classify text into categories.
85
84
86
85
### Run Analyze Entities
87
86
@@ -181,11 +180,46 @@ To run the Analyze Syntax sample:
181
180
language: en
182
181
entities: { }
183
182
183
+
184
+ ### Run Analyze Entity Sentiment
185
+
186
+ To run the Analyze Entity Sentiment sample:
187
+
188
+ $ php language.php entity-sentiment 'New York is great. New York is good.'
189
+ Entity Name: New York
190
+ Entity Type: LOCATION
191
+ Entity Salience: 1
192
+ Entity Magnitude: 1.7999999523163
193
+ Entity Score: 0
194
+
195
+ Mentions:
196
+ Begin Offset: 0
197
+ Content: New York
198
+ Mention Type: PROPER
199
+ Mention Magnitude: 0.89999997615814
200
+ Mention Score: 0.89999997615814
201
+
202
+ Begin Offset: 17
203
+ Content: New York
204
+ Mention Type: PROPER
205
+ Mention Magnitude: 0.80000001192093
206
+ Mention Score: -0.80000001192093
207
+
208
+ ### Run Classify Text
209
+
210
+ To run the Classify Text sample:
211
+
212
+ $ php language.php classify 'The first two gubernatorial elections since
213
+ President Donald Trump took office went in favor of Democratic candidates
214
+ in Virginia and New Jersey.'
215
+ Category Name: /News/Politics
216
+ Confidence: 0.99000000953674
217
+
184
218
## The client library
185
219
186
220
This sample uses the [ Google Cloud Client Library for PHP] [ google-cloud-php ] .
187
221
You can read the documentation for more details on API usage and use GitHub
188
- to [ browse the source] [ google-cloud-php-source ] and [ report issues] [ google-cloud-php-issues ] .
222
+ to [ browse the source] [ google-cloud-php-source ] and [ report issues] [ google-cloud-php-issues ] .
189
223
190
224
## Troubleshooting
191
225
0 commit comments