33These samples show how to use the [ Google Cloud Natural Language API] [ language-api ]
44to analyze text.
55
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-
116[ language-api ] : http://cloud.google.com/natural-language
127[ google-cloud-php ] : https://googlecloudplatform.github.io/google-cloud-php/
13- [ grpc ] : http://grpc.io
14-
158
169## Setup
1710
@@ -56,6 +49,10 @@ authentication:
5649
57501 . Set ` GOOGLE_APPLICATION_CREDENTIALS ` environment variable pointing to that file.
5851
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+
5956## Samples
6057
6158To run the Natural Language Samples:
@@ -76,12 +73,14 @@ To run the Natural Language Samples:
7673 -v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
7774
7875 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.
8584
8685### Run Analyze Entities
8786
@@ -181,11 +180,46 @@ To run the Analyze Syntax sample:
181180 language: en
182181 entities: { }
183182
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+
184218## The client library
185219
186220This sample uses the [ Google Cloud Client Library for PHP] [ google-cloud-php ] .
187221You 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 ] .
189223
190224## Troubleshooting
191225
0 commit comments